2024-04-30 23:38:49 +08:00
|
|
|
import 'package:fl_clash/common/common.dart';
|
2025-02-09 18:39:38 +08:00
|
|
|
import 'package:fl_clash/providers/config.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 'package:intl/intl.dart';
|
|
|
|
|
|
2025-02-09 18:39:38 +08:00
|
|
|
class CloseConnectionsItem extends ConsumerWidget {
|
|
|
|
|
const CloseConnectionsItem({super.key});
|
2024-09-26 14:29:04 +08:00
|
|
|
|
|
|
|
|
@override
|
2025-02-09 18:39:38 +08:00
|
|
|
Widget build(BuildContext context, ref) {
|
|
|
|
|
final closeConnections = ref.watch(
|
|
|
|
|
appSettingProvider.select((state) => state.closeConnections),
|
|
|
|
|
);
|
|
|
|
|
return ListItem.switchItem(
|
|
|
|
|
title: Text(appLocalizations.autoCloseConnections),
|
|
|
|
|
subtitle: Text(appLocalizations.autoCloseConnectionsDesc),
|
|
|
|
|
delegate: SwitchDelegate(
|
|
|
|
|
value: closeConnections,
|
|
|
|
|
onChanged: (value) async {
|
2025-07-31 17:09:18 +08:00
|
|
|
ref
|
|
|
|
|
.read(appSettingProvider.notifier)
|
|
|
|
|
.updateState((state) => state.copyWith(closeConnections: value));
|
2025-02-09 18:39:38 +08:00
|
|
|
},
|
|
|
|
|
),
|
2024-09-26 14:29:04 +08:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-09 18:39:38 +08:00
|
|
|
class UsageItem extends ConsumerWidget {
|
|
|
|
|
const UsageItem({super.key});
|
2024-09-26 14:29:04 +08:00
|
|
|
|
|
|
|
|
@override
|
2025-02-09 18:39:38 +08:00
|
|
|
Widget build(BuildContext context, ref) {
|
|
|
|
|
final onlyStatisticsProxy = ref.watch(
|
|
|
|
|
appSettingProvider.select((state) => state.onlyStatisticsProxy),
|
|
|
|
|
);
|
|
|
|
|
return ListItem.switchItem(
|
|
|
|
|
title: Text(appLocalizations.onlyStatisticsProxy),
|
|
|
|
|
subtitle: Text(appLocalizations.onlyStatisticsProxyDesc),
|
|
|
|
|
delegate: SwitchDelegate(
|
|
|
|
|
value: onlyStatisticsProxy,
|
|
|
|
|
onChanged: (bool value) async {
|
2025-07-31 17:09:18 +08:00
|
|
|
ref
|
|
|
|
|
.read(appSettingProvider.notifier)
|
|
|
|
|
.updateState(
|
|
|
|
|
(state) => state.copyWith(onlyStatisticsProxy: value),
|
2024-09-26 14:29:04 +08:00
|
|
|
);
|
2025-02-09 18:39:38 +08:00
|
|
|
},
|
|
|
|
|
),
|
2024-09-26 14:29:04 +08:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-09 18:39:38 +08:00
|
|
|
class MinimizeItem extends ConsumerWidget {
|
|
|
|
|
const MinimizeItem({super.key});
|
2024-04-30 23:38:49 +08:00
|
|
|
|
2025-02-09 18:39:38 +08:00
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
|
|
|
|
final minimizeOnExit = ref.watch(
|
|
|
|
|
appSettingProvider.select((state) => state.minimizeOnExit),
|
|
|
|
|
);
|
|
|
|
|
return ListItem.switchItem(
|
|
|
|
|
title: Text(appLocalizations.minimizeOnExit),
|
|
|
|
|
subtitle: Text(appLocalizations.minimizeOnExitDesc),
|
|
|
|
|
delegate: SwitchDelegate(
|
|
|
|
|
value: minimizeOnExit,
|
|
|
|
|
onChanged: (bool value) {
|
2025-07-31 17:09:18 +08:00
|
|
|
ref
|
|
|
|
|
.read(appSettingProvider.notifier)
|
|
|
|
|
.updateState((state) => state.copyWith(minimizeOnExit: value));
|
2025-02-09 18:39:38 +08:00
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class AutoLaunchItem extends ConsumerWidget {
|
|
|
|
|
const AutoLaunchItem({super.key});
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
|
|
|
|
final autoLaunch = ref.watch(
|
|
|
|
|
appSettingProvider.select((state) => state.autoLaunch),
|
|
|
|
|
);
|
|
|
|
|
return ListItem.switchItem(
|
|
|
|
|
title: Text(appLocalizations.autoLaunch),
|
|
|
|
|
subtitle: Text(appLocalizations.autoLaunchDesc),
|
|
|
|
|
delegate: SwitchDelegate(
|
|
|
|
|
value: autoLaunch,
|
|
|
|
|
onChanged: (bool value) {
|
2025-07-31 17:09:18 +08:00
|
|
|
ref
|
|
|
|
|
.read(appSettingProvider.notifier)
|
|
|
|
|
.updateState((state) => state.copyWith(autoLaunch: value));
|
2025-02-09 18:39:38 +08:00
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
);
|
2024-04-30 23:38:49 +08:00
|
|
|
}
|
2025-02-09 18:39:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class SilentLaunchItem extends ConsumerWidget {
|
|
|
|
|
const SilentLaunchItem({super.key});
|
2024-04-30 23:38:49 +08:00
|
|
|
|
|
|
|
|
@override
|
2025-02-09 18:39:38 +08:00
|
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
|
|
|
|
final silentLaunch = ref.watch(
|
|
|
|
|
appSettingProvider.select((state) => state.silentLaunch),
|
|
|
|
|
);
|
|
|
|
|
return ListItem.switchItem(
|
|
|
|
|
title: Text(appLocalizations.silentLaunch),
|
|
|
|
|
subtitle: Text(appLocalizations.silentLaunchDesc),
|
|
|
|
|
delegate: SwitchDelegate(
|
|
|
|
|
value: silentLaunch,
|
|
|
|
|
onChanged: (bool value) {
|
2025-07-31 17:09:18 +08:00
|
|
|
ref
|
|
|
|
|
.read(appSettingProvider.notifier)
|
|
|
|
|
.updateState((state) => state.copyWith(silentLaunch: value));
|
2024-04-30 23:38:49 +08:00
|
|
|
},
|
|
|
|
|
),
|
2025-02-09 18:39:38 +08:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class AutoRunItem extends ConsumerWidget {
|
|
|
|
|
const AutoRunItem({super.key});
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
|
|
|
|
final autoRun = ref.watch(
|
|
|
|
|
appSettingProvider.select((state) => state.autoRun),
|
|
|
|
|
);
|
|
|
|
|
return ListItem.switchItem(
|
|
|
|
|
title: Text(appLocalizations.autoRun),
|
|
|
|
|
subtitle: Text(appLocalizations.autoRunDesc),
|
|
|
|
|
delegate: SwitchDelegate(
|
|
|
|
|
value: autoRun,
|
|
|
|
|
onChanged: (bool value) {
|
2025-07-31 17:09:18 +08:00
|
|
|
ref
|
|
|
|
|
.read(appSettingProvider.notifier)
|
|
|
|
|
.updateState((state) => state.copyWith(autoRun: value));
|
2025-02-09 18:39:38 +08:00
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class HiddenItem extends ConsumerWidget {
|
|
|
|
|
const HiddenItem({super.key});
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
|
|
|
|
final hidden = ref.watch(
|
|
|
|
|
appSettingProvider.select((state) => state.hidden),
|
|
|
|
|
);
|
|
|
|
|
return ListItem.switchItem(
|
|
|
|
|
title: Text(appLocalizations.exclude),
|
|
|
|
|
subtitle: Text(appLocalizations.excludeDesc),
|
|
|
|
|
delegate: SwitchDelegate(
|
|
|
|
|
value: hidden,
|
|
|
|
|
onChanged: (value) {
|
2025-07-31 17:09:18 +08:00
|
|
|
ref
|
|
|
|
|
.read(appSettingProvider.notifier)
|
|
|
|
|
.updateState((state) => state.copyWith(hidden: value));
|
2024-04-30 23:38:49 +08:00
|
|
|
},
|
|
|
|
|
),
|
2025-02-09 18:39:38 +08:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class AnimateTabItem extends ConsumerWidget {
|
|
|
|
|
const AnimateTabItem({super.key});
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
|
|
|
|
final isAnimateToPage = ref.watch(
|
|
|
|
|
appSettingProvider.select((state) => state.isAnimateToPage),
|
|
|
|
|
);
|
|
|
|
|
return ListItem.switchItem(
|
|
|
|
|
title: Text(appLocalizations.tabAnimation),
|
|
|
|
|
subtitle: Text(appLocalizations.tabAnimationDesc),
|
|
|
|
|
delegate: SwitchDelegate(
|
|
|
|
|
value: isAnimateToPage,
|
|
|
|
|
onChanged: (value) {
|
2025-07-31 17:09:18 +08:00
|
|
|
ref
|
|
|
|
|
.read(appSettingProvider.notifier)
|
|
|
|
|
.updateState((state) => state.copyWith(isAnimateToPage: value));
|
2025-02-09 18:39:38 +08:00
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class OpenLogsItem extends ConsumerWidget {
|
|
|
|
|
const OpenLogsItem({super.key});
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
|
|
|
|
final openLogs = ref.watch(
|
|
|
|
|
appSettingProvider.select((state) => state.openLogs),
|
|
|
|
|
);
|
|
|
|
|
return ListItem.switchItem(
|
|
|
|
|
title: Text(appLocalizations.logcat),
|
|
|
|
|
subtitle: Text(appLocalizations.logcatDesc),
|
|
|
|
|
delegate: SwitchDelegate(
|
|
|
|
|
value: openLogs,
|
|
|
|
|
onChanged: (bool value) {
|
2025-07-31 17:09:18 +08:00
|
|
|
ref
|
|
|
|
|
.read(appSettingProvider.notifier)
|
|
|
|
|
.updateState((state) => state.copyWith(openLogs: value));
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class CrashlyticsItem extends ConsumerWidget {
|
|
|
|
|
const CrashlyticsItem({super.key});
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
|
|
|
|
final crashlytics = ref.watch(
|
|
|
|
|
appSettingProvider.select((state) => state.crashlytics),
|
|
|
|
|
);
|
|
|
|
|
return ListItem.switchItem(
|
|
|
|
|
title: Text(appLocalizations.crashlytics),
|
|
|
|
|
subtitle: Text(appLocalizations.crashlyticsTip),
|
|
|
|
|
delegate: SwitchDelegate(
|
|
|
|
|
value: crashlytics,
|
|
|
|
|
onChanged: (bool value) {
|
|
|
|
|
ref
|
|
|
|
|
.read(appSettingProvider.notifier)
|
|
|
|
|
.updateState((state) => state.copyWith(crashlytics: value));
|
2024-05-20 15:15:09 +08:00
|
|
|
},
|
|
|
|
|
),
|
2025-02-09 18:39:38 +08:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class AutoCheckUpdateItem extends ConsumerWidget {
|
|
|
|
|
const AutoCheckUpdateItem({super.key});
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
|
|
|
|
final autoCheckUpdate = ref.watch(
|
|
|
|
|
appSettingProvider.select((state) => state.autoCheckUpdate),
|
|
|
|
|
);
|
|
|
|
|
return ListItem.switchItem(
|
|
|
|
|
title: Text(appLocalizations.autoCheckUpdate),
|
|
|
|
|
subtitle: Text(appLocalizations.autoCheckUpdateDesc),
|
|
|
|
|
delegate: SwitchDelegate(
|
|
|
|
|
value: autoCheckUpdate,
|
|
|
|
|
onChanged: (bool value) {
|
2025-07-31 17:09:18 +08:00
|
|
|
ref
|
|
|
|
|
.read(appSettingProvider.notifier)
|
|
|
|
|
.updateState((state) => state.copyWith(autoCheckUpdate: value));
|
2024-05-20 15:15:09 +08:00
|
|
|
},
|
|
|
|
|
),
|
2025-02-09 18:39:38 +08:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-02 02:24:12 +08:00
|
|
|
class ApplicationSettingView extends StatelessWidget {
|
|
|
|
|
const ApplicationSettingView({super.key});
|
2025-02-09 18:39:38 +08:00
|
|
|
|
|
|
|
|
String getLocaleString(Locale? locale) {
|
|
|
|
|
if (locale == null) return appLocalizations.defaultText;
|
|
|
|
|
return Intl.message(locale.toString());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
List<Widget> items = [
|
|
|
|
|
MinimizeItem(),
|
2025-07-31 17:09:18 +08:00
|
|
|
if (system.isDesktop) ...[AutoLaunchItem(), SilentLaunchItem()],
|
2025-02-09 18:39:38 +08:00
|
|
|
AutoRunItem(),
|
2025-07-31 17:09:18 +08:00
|
|
|
if (system.isAndroid) ...[HiddenItem()],
|
2025-03-12 17:15:31 +08:00
|
|
|
AnimateTabItem(),
|
2025-02-09 18:39:38 +08:00
|
|
|
OpenLogsItem(),
|
|
|
|
|
CloseConnectionsItem(),
|
|
|
|
|
UsageItem(),
|
2025-07-31 17:09:18 +08:00
|
|
|
if (system.isAndroid) CrashlyticsItem(),
|
2025-02-09 18:39:38 +08:00
|
|
|
AutoCheckUpdateItem(),
|
2024-04-30 23:38:49 +08:00
|
|
|
];
|
2025-10-14 15:13:52 +08:00
|
|
|
return BaseScaffold(
|
|
|
|
|
title: appLocalizations.application,
|
|
|
|
|
body: ListView.separated(
|
|
|
|
|
itemBuilder: (_, index) {
|
|
|
|
|
final item = items[index];
|
|
|
|
|
return item;
|
|
|
|
|
},
|
|
|
|
|
separatorBuilder: (_, _) {
|
|
|
|
|
return const Divider(height: 0);
|
|
|
|
|
},
|
|
|
|
|
itemCount: items.length,
|
|
|
|
|
),
|
2024-04-30 23:38:49 +08:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|