2024-08-13 21:42:23 +08:00
|
|
|
import 'dart:ui';
|
|
|
|
|
|
2024-11-09 20:17:57 +08:00
|
|
|
import 'package:fl_clash/common/common.dart';
|
2024-05-20 15:15:09 +08:00
|
|
|
import 'package:fl_clash/enum/enum.dart';
|
2024-04-30 23:38:49 +08:00
|
|
|
import 'package:fl_clash/fragments/profiles/edit_profile.dart';
|
2025-03-12 17:15:31 +08:00
|
|
|
import 'package:fl_clash/fragments/profiles/override_profile.dart';
|
2024-04-30 23:38:49 +08:00
|
|
|
import 'package:fl_clash/models/models.dart';
|
2025-02-09 18:39:38 +08:00
|
|
|
import 'package:fl_clash/providers/providers.dart';
|
2024-05-11 17:02:34 +08:00
|
|
|
import 'package:fl_clash/state.dart';
|
2024-04-30 23:38:49 +08:00
|
|
|
import 'package:fl_clash/widgets/widgets.dart';
|
|
|
|
|
import 'package:flutter/material.dart';
|
2025-02-09 18:39:38 +08:00
|
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
2024-04-30 23:38:49 +08:00
|
|
|
|
|
|
|
|
import 'add_profile.dart';
|
|
|
|
|
|
2024-06-08 22:51:58 +08:00
|
|
|
class ProfilesFragment extends StatefulWidget {
|
2024-04-30 23:38:49 +08:00
|
|
|
const ProfilesFragment({super.key});
|
|
|
|
|
|
2024-06-08 22:51:58 +08:00
|
|
|
@override
|
|
|
|
|
State<ProfilesFragment> createState() => _ProfilesFragmentState();
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-09 18:39:38 +08:00
|
|
|
class _ProfilesFragmentState extends State<ProfilesFragment> with PageMixin {
|
2024-06-29 21:42:00 +08:00
|
|
|
Function? applyConfigDebounce;
|
2024-06-08 22:51:58 +08:00
|
|
|
|
2024-05-20 15:15:09 +08:00
|
|
|
_handleShowAddExtendPage() {
|
2025-03-12 17:15:31 +08:00
|
|
|
showExtend(
|
2024-05-20 15:15:09 +08:00
|
|
|
globalState.navigatorKey.currentState!.context,
|
2025-03-12 17:15:31 +08:00
|
|
|
builder: (_, type) {
|
|
|
|
|
return AdaptiveSheetScaffold(
|
|
|
|
|
type: type,
|
|
|
|
|
body: AddProfile(
|
|
|
|
|
context: globalState.navigatorKey.currentState!.context,
|
|
|
|
|
),
|
|
|
|
|
title: "${appLocalizations.add}${appLocalizations.profile}",
|
|
|
|
|
);
|
|
|
|
|
},
|
2024-05-20 15:15:09 +08:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-19 13:13:31 +08:00
|
|
|
_updateProfiles() async {
|
2025-02-09 18:39:38 +08:00
|
|
|
final profiles = globalState.config.profiles;
|
2024-08-13 21:42:23 +08:00
|
|
|
final messages = [];
|
2024-08-04 08:21:14 +08:00
|
|
|
final updateProfiles = profiles.map<Future>(
|
|
|
|
|
(profile) async {
|
2024-08-25 23:30:18 +08:00
|
|
|
if (profile.type == ProfileType.file) return;
|
2025-02-09 18:39:38 +08:00
|
|
|
globalState.appController.setProfile(
|
2024-08-04 08:21:14 +08:00
|
|
|
profile.copyWith(isUpdating: true),
|
|
|
|
|
);
|
|
|
|
|
try {
|
2025-02-09 18:39:38 +08:00
|
|
|
await globalState.appController.updateProfile(profile);
|
2024-08-13 21:42:23 +08:00
|
|
|
} catch (e) {
|
|
|
|
|
messages.add("${profile.label ?? profile.id}: $e \n");
|
2025-02-09 18:39:38 +08:00
|
|
|
globalState.appController.setProfile(
|
2024-08-04 08:21:14 +08:00
|
|
|
profile.copyWith(
|
|
|
|
|
isUpdating: false,
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
);
|
2024-08-13 21:42:23 +08:00
|
|
|
final titleMedium = context.textTheme.titleMedium;
|
2024-06-27 01:14:45 +08:00
|
|
|
await Future.wait(updateProfiles);
|
2024-08-13 21:42:23 +08:00
|
|
|
if (messages.isNotEmpty) {
|
|
|
|
|
globalState.showMessage(
|
|
|
|
|
title: appLocalizations.tip,
|
|
|
|
|
message: TextSpan(
|
|
|
|
|
children: [
|
|
|
|
|
for (final message in messages)
|
|
|
|
|
TextSpan(text: message, style: titleMedium)
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
2024-06-19 13:13:31 +08:00
|
|
|
}
|
|
|
|
|
|
2025-02-09 18:39:38 +08:00
|
|
|
@override
|
|
|
|
|
List<Widget> get actions => [
|
|
|
|
|
IconButton(
|
|
|
|
|
onPressed: () {
|
|
|
|
|
_updateProfiles();
|
|
|
|
|
},
|
|
|
|
|
icon: const Icon(Icons.sync),
|
|
|
|
|
),
|
|
|
|
|
IconButton(
|
|
|
|
|
onPressed: () {
|
|
|
|
|
final profiles = globalState.config.profiles;
|
|
|
|
|
showSheet(
|
|
|
|
|
context: context,
|
2025-03-12 17:15:31 +08:00
|
|
|
builder: (_, type) {
|
|
|
|
|
return ReorderableProfilesSheet(
|
|
|
|
|
type: type,
|
|
|
|
|
profiles: profiles,
|
|
|
|
|
);
|
|
|
|
|
},
|
2025-02-09 18:39:38 +08:00
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
icon: const Icon(Icons.sort),
|
|
|
|
|
iconSize: 26,
|
|
|
|
|
),
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget? get floatingActionButton => FloatingActionButton(
|
|
|
|
|
heroTag: null,
|
|
|
|
|
onPressed: _handleShowAddExtendPage,
|
|
|
|
|
child: const Icon(
|
|
|
|
|
Icons.add,
|
|
|
|
|
),
|
|
|
|
|
);
|
2024-06-07 17:22:55 +08:00
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
2025-02-09 18:39:38 +08:00
|
|
|
return Consumer(
|
|
|
|
|
builder: (_, ref, __) {
|
|
|
|
|
ref.listenManual(
|
|
|
|
|
isCurrentPageProvider(PageLabel.profiles),
|
|
|
|
|
(prev, next) {
|
|
|
|
|
if (prev != next && next == true) {
|
|
|
|
|
initPageState();
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
fireImmediately: true,
|
|
|
|
|
);
|
|
|
|
|
final profilesSelectorState = ref.watch(profilesSelectorStateProvider);
|
|
|
|
|
if (profilesSelectorState.profiles.isEmpty) {
|
|
|
|
|
return NullStatus(
|
|
|
|
|
label: appLocalizations.nullProfileDesc,
|
|
|
|
|
);
|
2024-10-27 16:59:23 +08:00
|
|
|
}
|
2025-02-09 18:39:38 +08:00
|
|
|
return Align(
|
|
|
|
|
alignment: Alignment.topCenter,
|
|
|
|
|
child: SingleChildScrollView(
|
|
|
|
|
padding: const EdgeInsets.only(
|
|
|
|
|
left: 16,
|
|
|
|
|
right: 16,
|
|
|
|
|
top: 16,
|
|
|
|
|
bottom: 88,
|
|
|
|
|
),
|
|
|
|
|
child: Grid(
|
|
|
|
|
mainAxisSpacing: 16,
|
|
|
|
|
crossAxisSpacing: 16,
|
|
|
|
|
crossAxisCount: profilesSelectorState.columns,
|
|
|
|
|
children: [
|
|
|
|
|
for (int i = 0; i < profilesSelectorState.profiles.length; i++)
|
|
|
|
|
GridItem(
|
|
|
|
|
child: ProfileItem(
|
|
|
|
|
key: Key(profilesSelectorState.profiles[i].id),
|
|
|
|
|
profile: profilesSelectorState.profiles[i],
|
|
|
|
|
groupValue: profilesSelectorState.currentProfileId,
|
|
|
|
|
onChanged: (profileId) {
|
|
|
|
|
ref.read(currentProfileIdProvider.notifier).value =
|
|
|
|
|
profileId;
|
|
|
|
|
},
|
2024-10-27 16:59:23 +08:00
|
|
|
),
|
2025-02-09 18:39:38 +08:00
|
|
|
),
|
|
|
|
|
],
|
2024-10-27 16:59:23 +08:00
|
|
|
),
|
2025-02-09 18:39:38 +08:00
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
},
|
2024-05-20 15:15:09 +08:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-04 08:21:14 +08:00
|
|
|
class ProfileItem extends StatelessWidget {
|
2024-05-20 15:15:09 +08:00
|
|
|
final Profile profile;
|
|
|
|
|
final String? groupValue;
|
|
|
|
|
final void Function(String? value) onChanged;
|
|
|
|
|
|
|
|
|
|
const ProfileItem({
|
|
|
|
|
super.key,
|
|
|
|
|
required this.profile,
|
|
|
|
|
required this.groupValue,
|
|
|
|
|
required this.onChanged,
|
|
|
|
|
});
|
|
|
|
|
|
2024-08-04 08:21:14 +08:00
|
|
|
_handleDeleteProfile(BuildContext context) async {
|
2025-01-13 19:08:17 +08:00
|
|
|
final res = await globalState.showMessage(
|
2024-07-26 08:05:22 +08:00
|
|
|
title: appLocalizations.tip,
|
|
|
|
|
message: TextSpan(
|
|
|
|
|
text: appLocalizations.deleteProfileTip,
|
|
|
|
|
),
|
|
|
|
|
);
|
2025-01-13 19:08:17 +08:00
|
|
|
if (res != true) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
await globalState.appController.deleteProfile(profile.id);
|
2024-06-07 17:22:55 +08:00
|
|
|
}
|
|
|
|
|
|
2024-08-04 08:21:14 +08:00
|
|
|
Future updateProfile() async {
|
|
|
|
|
final appController = globalState.appController;
|
|
|
|
|
if (profile.type == ProfileType.file) return;
|
2025-01-09 18:38:52 +08:00
|
|
|
await globalState.safeRun(silence: false, () async {
|
2024-08-04 08:21:14 +08:00
|
|
|
try {
|
2025-02-09 18:39:38 +08:00
|
|
|
appController.setProfile(
|
2024-08-04 08:21:14 +08:00
|
|
|
profile.copyWith(
|
|
|
|
|
isUpdating: true,
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
await appController.updateProfile(profile);
|
|
|
|
|
} catch (e) {
|
2025-02-09 18:39:38 +08:00
|
|
|
appController.setProfile(
|
2024-08-04 08:21:14 +08:00
|
|
|
profile.copyWith(
|
|
|
|
|
isUpdating: false,
|
|
|
|
|
),
|
|
|
|
|
);
|
2024-07-07 10:02:10 +08:00
|
|
|
rethrow;
|
2024-06-19 13:13:31 +08:00
|
|
|
}
|
2024-08-04 08:21:14 +08:00
|
|
|
});
|
2024-06-07 17:22:55 +08:00
|
|
|
}
|
|
|
|
|
|
2024-08-04 08:21:14 +08:00
|
|
|
_handleShowEditExtendPage(BuildContext context) {
|
2025-03-12 17:15:31 +08:00
|
|
|
showExtend(
|
2024-06-07 17:22:55 +08:00
|
|
|
context,
|
2025-03-12 17:15:31 +08:00
|
|
|
builder: (_, type) {
|
|
|
|
|
return AdaptiveSheetScaffold(
|
|
|
|
|
type: type,
|
|
|
|
|
body: EditProfile(
|
|
|
|
|
profile: profile,
|
|
|
|
|
context: context,
|
|
|
|
|
),
|
|
|
|
|
title: "${appLocalizations.edit}${appLocalizations.profile}",
|
|
|
|
|
);
|
|
|
|
|
},
|
2024-06-07 17:22:55 +08:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-04 08:21:14 +08:00
|
|
|
List<Widget> _buildUrlProfileInfo(BuildContext context) {
|
2024-11-09 20:17:57 +08:00
|
|
|
final subscriptionInfo = profile.subscriptionInfo;
|
2024-08-01 23:51:00 +08:00
|
|
|
return [
|
|
|
|
|
const SizedBox(
|
|
|
|
|
height: 8,
|
|
|
|
|
),
|
2024-11-09 20:17:57 +08:00
|
|
|
if (subscriptionInfo != null)
|
|
|
|
|
SubscriptionInfoView(
|
|
|
|
|
subscriptionInfo: subscriptionInfo,
|
|
|
|
|
),
|
2024-08-01 23:51:00 +08:00
|
|
|
Text(
|
|
|
|
|
profile.lastUpdateDate?.lastUpdateTimeDesc ?? "",
|
|
|
|
|
style: context.textTheme.labelMedium?.toLight,
|
|
|
|
|
),
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-04 08:21:14 +08:00
|
|
|
List<Widget> _buildFileProfileInfo(BuildContext context) {
|
2024-08-01 23:51:00 +08:00
|
|
|
return [
|
|
|
|
|
const SizedBox(
|
|
|
|
|
height: 8,
|
|
|
|
|
),
|
|
|
|
|
Text(
|
|
|
|
|
profile.lastUpdateDate?.lastUpdateTimeDesc ?? "",
|
|
|
|
|
style: context.textTheme.labelMedium?.toLight,
|
|
|
|
|
),
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-09 18:39:38 +08:00
|
|
|
// _handleCopyLink(BuildContext context) async {
|
|
|
|
|
// await Clipboard.setData(
|
|
|
|
|
// ClipboardData(
|
|
|
|
|
// text: profile.url,
|
|
|
|
|
// ),
|
|
|
|
|
// );
|
|
|
|
|
// if (context.mounted) {
|
|
|
|
|
// context.showNotifier(appLocalizations.copySuccess);
|
|
|
|
|
// }
|
|
|
|
|
// }
|
2025-01-13 19:08:17 +08:00
|
|
|
|
|
|
|
|
_handleExportFile(BuildContext context) async {
|
|
|
|
|
final commonScaffoldState = context.commonScaffoldState;
|
|
|
|
|
final res = await commonScaffoldState?.loadingRun<bool>(
|
|
|
|
|
() async {
|
|
|
|
|
final file = await profile.getFile();
|
|
|
|
|
final value = await picker.saveFile(
|
|
|
|
|
profile.label ?? profile.id,
|
|
|
|
|
file.readAsBytesSync(),
|
|
|
|
|
);
|
|
|
|
|
if (value == null) return false;
|
|
|
|
|
return true;
|
|
|
|
|
},
|
|
|
|
|
title: appLocalizations.tip,
|
|
|
|
|
);
|
|
|
|
|
if (res == true && context.mounted) {
|
|
|
|
|
context.showNotifier(appLocalizations.exportSuccess);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-09 01:58:46 +08:00
|
|
|
_handlePushGenProfilePage(BuildContext context, String id) {
|
|
|
|
|
BaseNavigator.push(
|
|
|
|
|
context,
|
2025-03-12 17:15:31 +08:00
|
|
|
OverrideProfile(
|
2025-03-09 01:58:46 +08:00
|
|
|
profileId: id,
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
2025-02-09 18:39:38 +08:00
|
|
|
|
2024-06-07 17:22:55 +08:00
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
2024-07-07 10:02:10 +08:00
|
|
|
return CommonCard(
|
2024-07-26 08:05:22 +08:00
|
|
|
isSelected: profile.id == groupValue,
|
|
|
|
|
onPressed: () {
|
|
|
|
|
onChanged(profile.id);
|
|
|
|
|
},
|
|
|
|
|
child: ListItem(
|
2024-06-07 17:22:55 +08:00
|
|
|
key: Key(profile.id),
|
|
|
|
|
horizontalTitleGap: 16,
|
|
|
|
|
padding: const EdgeInsets.symmetric(horizontal: 16),
|
2024-06-19 13:13:31 +08:00
|
|
|
trailing: SizedBox(
|
2024-07-26 08:05:22 +08:00
|
|
|
height: 40,
|
|
|
|
|
width: 40,
|
2025-03-12 17:15:31 +08:00
|
|
|
child: FadeThroughBox(
|
2024-08-04 08:21:14 +08:00
|
|
|
child: profile.isUpdating
|
|
|
|
|
? const Padding(
|
|
|
|
|
padding: EdgeInsets.all(8),
|
|
|
|
|
child: CircularProgressIndicator(),
|
|
|
|
|
)
|
2025-01-13 19:08:17 +08:00
|
|
|
: CommonPopupBox(
|
|
|
|
|
popup: CommonPopupMenu(
|
|
|
|
|
items: [
|
2025-03-12 17:15:31 +08:00
|
|
|
PopupMenuItemData(
|
2025-01-13 19:08:17 +08:00
|
|
|
icon: Icons.edit_outlined,
|
|
|
|
|
label: appLocalizations.edit,
|
|
|
|
|
onPressed: () {
|
|
|
|
|
_handleShowEditExtendPage(context);
|
|
|
|
|
},
|
2024-08-04 08:21:14 +08:00
|
|
|
),
|
2025-01-13 19:08:17 +08:00
|
|
|
if (profile.type == ProfileType.url) ...[
|
2025-03-12 17:15:31 +08:00
|
|
|
PopupMenuItemData(
|
2025-01-13 19:08:17 +08:00
|
|
|
icon: Icons.sync_alt_sharp,
|
|
|
|
|
label: appLocalizations.sync,
|
|
|
|
|
onPressed: () {
|
2025-03-05 16:08:50 +08:00
|
|
|
updateProfile();
|
2025-01-13 19:08:17 +08:00
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
],
|
2025-03-12 17:15:31 +08:00
|
|
|
PopupMenuItemData(
|
|
|
|
|
icon: Icons.extension_outlined,
|
|
|
|
|
label: appLocalizations.override,
|
|
|
|
|
onPressed: () {
|
|
|
|
|
_handlePushGenProfilePage(context, profile.id);
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
PopupMenuItemData(
|
2025-01-13 19:08:17 +08:00
|
|
|
icon: Icons.file_copy_outlined,
|
|
|
|
|
label: appLocalizations.exportFile,
|
|
|
|
|
onPressed: () {
|
|
|
|
|
_handleExportFile(context);
|
|
|
|
|
},
|
|
|
|
|
),
|
2025-03-12 17:15:31 +08:00
|
|
|
PopupMenuItemData(
|
2025-01-13 19:08:17 +08:00
|
|
|
icon: Icons.delete_outlined,
|
|
|
|
|
iconSize: 20,
|
|
|
|
|
label: appLocalizations.delete,
|
|
|
|
|
onPressed: () {
|
|
|
|
|
_handleDeleteProfile(context);
|
|
|
|
|
},
|
2025-03-12 17:15:31 +08:00
|
|
|
type: PopupMenuItemType.danger,
|
2025-01-13 19:08:17 +08:00
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
2025-03-12 17:15:31 +08:00
|
|
|
targetBuilder: (open) {
|
|
|
|
|
return IconButton(
|
|
|
|
|
onPressed: () {
|
|
|
|
|
open();
|
|
|
|
|
},
|
|
|
|
|
icon: Icon(Icons.more_vert),
|
|
|
|
|
);
|
|
|
|
|
},
|
2024-08-04 08:21:14 +08:00
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
title: Container(
|
2025-04-18 17:50:46 +08:00
|
|
|
padding: const EdgeInsets.symmetric(vertical: 4),
|
2024-08-04 08:21:14 +08:00
|
|
|
child: Column(
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
|
children: [
|
|
|
|
|
Text(
|
|
|
|
|
profile.label ?? profile.id,
|
|
|
|
|
style: context.textTheme.titleMedium,
|
|
|
|
|
maxLines: 1,
|
|
|
|
|
overflow: TextOverflow.ellipsis,
|
|
|
|
|
),
|
|
|
|
|
Column(
|
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
|
children: [
|
|
|
|
|
...switch (profile.type) {
|
|
|
|
|
ProfileType.file => _buildFileProfileInfo(context),
|
|
|
|
|
ProfileType.url => _buildUrlProfileInfo(context),
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
],
|
2024-06-19 13:13:31 +08:00
|
|
|
),
|
2024-06-07 17:22:55 +08:00
|
|
|
),
|
|
|
|
|
tileTitleAlignment: ListTileTitleAlignment.titleHeight,
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
2024-04-30 23:38:49 +08:00
|
|
|
}
|
2024-08-13 21:42:23 +08:00
|
|
|
|
2025-03-12 17:15:31 +08:00
|
|
|
class ReorderableProfilesSheet extends StatefulWidget {
|
2024-08-13 21:42:23 +08:00
|
|
|
final List<Profile> profiles;
|
2025-03-12 17:15:31 +08:00
|
|
|
final SheetType type;
|
2024-08-13 21:42:23 +08:00
|
|
|
|
2025-03-12 17:15:31 +08:00
|
|
|
const ReorderableProfilesSheet({
|
2024-08-13 21:42:23 +08:00
|
|
|
super.key,
|
|
|
|
|
required this.profiles,
|
2025-03-12 17:15:31 +08:00
|
|
|
required this.type,
|
2024-08-13 21:42:23 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
@override
|
2025-03-12 17:15:31 +08:00
|
|
|
State<ReorderableProfilesSheet> createState() =>
|
|
|
|
|
_ReorderableProfilesSheetState();
|
2024-08-13 21:42:23 +08:00
|
|
|
}
|
|
|
|
|
|
2025-03-12 17:15:31 +08:00
|
|
|
class _ReorderableProfilesSheetState extends State<ReorderableProfilesSheet> {
|
2024-08-13 21:42:23 +08:00
|
|
|
late List<Profile> profiles;
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
void initState() {
|
|
|
|
|
super.initState();
|
|
|
|
|
profiles = List.from(widget.profiles);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Widget proxyDecorator(
|
|
|
|
|
Widget child,
|
|
|
|
|
int index,
|
|
|
|
|
Animation<double> animation,
|
|
|
|
|
) {
|
|
|
|
|
final profile = profiles[index];
|
|
|
|
|
return AnimatedBuilder(
|
|
|
|
|
animation: animation,
|
|
|
|
|
builder: (_, Widget? child) {
|
|
|
|
|
final double animValue = Curves.easeInOut.transform(animation.value);
|
|
|
|
|
final double scale = lerpDouble(1, 1.02, animValue)!;
|
|
|
|
|
return Transform.scale(
|
|
|
|
|
scale: scale,
|
|
|
|
|
child: child,
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
child: Container(
|
|
|
|
|
key: Key(profile.id),
|
|
|
|
|
padding: const EdgeInsets.symmetric(vertical: 4),
|
|
|
|
|
child: CommonCard(
|
|
|
|
|
type: CommonCardType.filled,
|
|
|
|
|
child: ListTile(
|
|
|
|
|
contentPadding: const EdgeInsets.only(
|
|
|
|
|
right: 44,
|
|
|
|
|
left: 16,
|
|
|
|
|
),
|
|
|
|
|
title: Text(profile.label ?? profile.id),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
2025-03-12 17:15:31 +08:00
|
|
|
return AdaptiveSheetScaffold(
|
|
|
|
|
type: widget.type,
|
|
|
|
|
actions: [
|
|
|
|
|
IconButton(
|
|
|
|
|
onPressed: () {
|
|
|
|
|
Navigator.of(context).pop();
|
|
|
|
|
globalState.appController.setProfiles(profiles);
|
|
|
|
|
},
|
|
|
|
|
icon: Icon(
|
|
|
|
|
Icons.save,
|
2024-08-13 21:42:23 +08:00
|
|
|
),
|
2025-03-12 17:15:31 +08:00
|
|
|
)
|
|
|
|
|
],
|
|
|
|
|
body: Padding(
|
|
|
|
|
padding: EdgeInsets.only(bottom: 32),
|
|
|
|
|
child: ReorderableListView.builder(
|
|
|
|
|
buildDefaultDragHandles: false,
|
2024-08-13 21:42:23 +08:00
|
|
|
padding: const EdgeInsets.symmetric(
|
2025-03-12 17:15:31 +08:00
|
|
|
horizontal: 12,
|
2024-08-13 21:42:23 +08:00
|
|
|
),
|
2025-03-12 17:15:31 +08:00
|
|
|
proxyDecorator: proxyDecorator,
|
|
|
|
|
onReorder: (oldIndex, newIndex) {
|
|
|
|
|
setState(() {
|
|
|
|
|
if (oldIndex < newIndex) {
|
|
|
|
|
newIndex -= 1;
|
|
|
|
|
}
|
|
|
|
|
final profile = profiles.removeAt(oldIndex);
|
|
|
|
|
profiles.insert(newIndex, profile);
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
itemBuilder: (_, index) {
|
|
|
|
|
final profile = profiles[index];
|
|
|
|
|
return Container(
|
|
|
|
|
key: Key(profile.id),
|
|
|
|
|
padding: const EdgeInsets.symmetric(vertical: 4),
|
|
|
|
|
child: CommonCard(
|
|
|
|
|
type: CommonCardType.filled,
|
|
|
|
|
child: ListTile(
|
|
|
|
|
contentPadding: const EdgeInsets.only(
|
|
|
|
|
right: 16,
|
|
|
|
|
left: 16,
|
|
|
|
|
),
|
|
|
|
|
title: Text(profile.label ?? profile.id),
|
|
|
|
|
trailing: ReorderableDragStartListener(
|
|
|
|
|
index: index,
|
|
|
|
|
child: const Icon(Icons.drag_handle),
|
|
|
|
|
),
|
2024-09-05 08:59:45 +08:00
|
|
|
),
|
2025-03-12 17:15:31 +08:00
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
itemCount: profiles.length,
|
2024-08-13 21:42:23 +08:00
|
|
|
),
|
2025-03-12 17:15:31 +08:00
|
|
|
),
|
|
|
|
|
title: appLocalizations.profilesSort,
|
2024-08-13 21:42:23 +08:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|