Jisho-Study-Tool/lib/screens/settings.dart

150 lines
4.7 KiB
Dart
Raw Normal View History

2021-08-03 22:04:29 +02:00
import 'package:confirm_dialog/confirm_dialog.dart';
import 'package:flutter/material.dart';
2022-01-14 09:01:52 +01:00
import 'package:flutter_settings_ui/flutter_settings_ui.dart';
2021-08-08 23:16:54 +02:00
2022-01-19 02:10:05 +01:00
import '../bloc/theme/theme_bloc.dart';
import '../models/history/search.dart';
import '../settings.dart';
2021-12-01 23:09:53 +01:00
2021-08-08 23:16:54 +02:00
class SettingsView extends StatefulWidget {
2021-12-01 23:09:53 +01:00
const SettingsView({Key? key}) : super(key: key);
2021-08-08 23:16:54 +02:00
@override
_SettingsViewState createState() => _SettingsViewState();
}
class _SettingsViewState extends State<SettingsView> {
final Database db = GetIt.instance.get<Database>();
2021-08-03 22:04:29 +02:00
2021-12-04 05:13:13 +01:00
Future<void> clearHistory(context) async {
final bool userIsSure = await confirm(context);
if (userIsSure) {
await Search.store.delete(db);
}
}
// ignore: avoid_positional_boolean_parameters
void toggleAutoTheme(bool b) {
final bool newThemeIsDark = b
? WidgetsBinding.instance!.window.platformBrightness == Brightness.dark
: darkThemeEnabled;
BlocProvider.of<ThemeBloc>(context)
.add(SetTheme(themeIsDark: newThemeIsDark));
setState(() => autoThemeEnabled = b);
}
2021-12-01 23:09:53 +01:00
@override
2021-08-03 22:04:29 +02:00
Widget build(BuildContext context) {
2021-08-08 23:16:54 +02:00
final TextStyle _titleTextStyle = TextStyle(
2021-12-01 23:09:53 +01:00
color: BlocProvider.of<ThemeBloc>(context).state is DarkThemeState
? AppTheme.jishoGreen.background
: null,
);
2021-08-08 23:16:54 +02:00
2021-08-03 22:04:29 +02:00
return SettingsList(
2021-08-08 23:16:54 +02:00
backgroundColor: Colors.transparent,
2021-12-01 23:09:53 +01:00
contentPadding: const EdgeInsets.symmetric(vertical: 10),
sections: <SettingsSection>[
2021-08-08 23:16:54 +02:00
SettingsSection(
2022-01-19 02:10:05 +01:00
title: 'Dictionary',
titleTextStyle: _titleTextStyle,
tiles: <SettingsTile>[
SettingsTile.switchTile(
title: 'Use romaji',
onToggle: (b) {
setState(() => romajiEnabled = b);
},
2022-01-19 02:10:05 +01:00
switchValue: romajiEnabled,
switchActiveColor: AppTheme.jishoGreen.background,
),
],
),
SettingsSection(
2021-08-08 23:16:54 +02:00
title: 'Theme',
titleTextStyle: _titleTextStyle,
2021-12-01 23:09:53 +01:00
tiles: <SettingsTile>[
2021-08-08 23:16:54 +02:00
SettingsTile.switchTile(
title: 'Automatically determine theme',
onToggle: toggleAutoTheme,
2021-08-08 23:16:54 +02:00
switchValue: autoThemeEnabled,
switchActiveColor: AppTheme.jishoGreen.background,
),
SettingsTile.switchTile(
title: 'Dark Theme',
onToggle: (b) {
2021-12-01 23:09:53 +01:00
BlocProvider.of<ThemeBloc>(context)
.add(SetTheme(themeIsDark: b));
setState(() => darkThemeEnabled = b);
2021-08-08 23:16:54 +02:00
},
switchValue: darkThemeEnabled,
enabled: !autoThemeEnabled,
switchActiveColor: AppTheme.jishoGreen.background,
),
],
),
2021-08-03 22:04:29 +02:00
SettingsSection(
title: 'Cache',
2021-08-08 23:16:54 +02:00
titleTextStyle: _titleTextStyle,
2021-12-01 23:09:53 +01:00
tiles: <SettingsTile>[
2021-08-03 22:04:29 +02:00
SettingsTile.switchTile(
2021-08-08 23:16:54 +02:00
title: 'Cache grade 1-7 kanji',
2021-08-03 22:04:29 +02:00
switchValue: false,
onToggle: (v) {},
2021-08-08 23:16:54 +02:00
enabled: false,
switchActiveColor: AppTheme.jishoGreen.background,
2021-08-03 22:04:29 +02:00
),
SettingsTile.switchTile(
2021-08-08 23:16:54 +02:00
title: 'Cache grade standard kanji',
2021-08-03 22:04:29 +02:00
switchValue: false,
onToggle: (v) {},
2021-08-08 23:16:54 +02:00
enabled: false,
switchActiveColor: AppTheme.jishoGreen.background,
2021-08-03 22:04:29 +02:00
),
SettingsTile.switchTile(
2021-08-08 23:16:54 +02:00
title: 'Cache all favourites',
2021-08-03 22:04:29 +02:00
switchValue: false,
onToggle: (v) {},
2021-08-08 23:16:54 +02:00
enabled: false,
switchActiveColor: AppTheme.jishoGreen.background,
2021-08-03 22:04:29 +02:00
),
SettingsTile.switchTile(
2021-08-08 23:16:54 +02:00
title: 'Cache all searches',
2021-08-03 22:04:29 +02:00
switchValue: false,
onToggle: (v) {},
2021-08-08 23:16:54 +02:00
enabled: false,
switchActiveColor: AppTheme.jishoGreen.background,
2021-08-03 22:04:29 +02:00
),
],
),
SettingsSection(
title: 'Data',
2021-08-08 23:16:54 +02:00
titleTextStyle: _titleTextStyle,
2021-12-01 23:09:53 +01:00
tiles: <SettingsTile>[
2022-01-14 09:01:52 +01:00
SettingsTile(
leading: const Icon(Icons.file_download),
2021-08-08 23:16:54 +02:00
title: 'Export Data',
enabled: false,
2021-08-03 22:04:29 +02:00
),
2021-12-04 05:13:13 +01:00
SettingsTile(
leading: const Icon(Icons.delete),
2021-08-08 23:16:54 +02:00
title: 'Clear History',
2021-12-04 05:13:13 +01:00
onPressed: clearHistory,
titleTextStyle: const TextStyle(color: Colors.red),
2021-08-03 22:04:29 +02:00
),
SettingsTile(
2021-12-01 23:09:53 +01:00
leading: const Icon(Icons.delete),
2021-08-08 23:16:54 +02:00
title: 'Clear Favourites',
2021-08-03 22:04:29 +02:00
onPressed: (c) {},
2021-12-01 23:09:53 +01:00
titleTextStyle: const TextStyle(color: Colors.red),
2021-08-08 23:16:54 +02:00
enabled: false,
2021-08-03 22:04:29 +02:00
)
],
2021-08-08 23:16:54 +02:00
),
2021-08-03 22:04:29 +02:00
],
);
}
}