From ff6f6ef8682d2662944605d432ffcc581866dc4b Mon Sep 17 00:00:00 2001 From: h7x4 Date: Tue, 3 Aug 2021 22:04:29 +0200 Subject: [PATCH] Add temporary settings screen --- lib/main.dart | 4 +- lib/view/screens/settings.dart | 72 ++++++++++++++++++++++++++++++++++ pubspec.yaml | 2 + 3 files changed, 76 insertions(+), 2 deletions(-) diff --git a/lib/main.dart b/lib/main.dart index 161865e..8ca5b4e 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -15,7 +15,7 @@ import 'package:jisho_study_tool/bloc/navigation/navigation_bloc.dart'; import 'package:jisho_study_tool/view/screens/kanji/view.dart'; import 'package:jisho_study_tool/view/screens/history.dart'; import 'package:jisho_study_tool/view/screens/search/view.dart'; - +import 'package:jisho_study_tool/view/screens/settings.dart'; void main() => runApp(MyApp()); @@ -154,7 +154,7 @@ final List<_Page> pages = [ ), ), _Page( - content: Container(), + content: SettingsView(), titleBar: Text("Settings"), item: BottomNavigationBarItem( label: 'Settings', diff --git a/lib/view/screens/settings.dart b/lib/view/screens/settings.dart index e69de29..ed1c35e 100644 --- a/lib/view/screens/settings.dart +++ b/lib/view/screens/settings.dart @@ -0,0 +1,72 @@ +import 'package:confirm_dialog/confirm_dialog.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:jisho_study_tool/bloc/database/database_bloc.dart'; +import 'package:jisho_study_tool/models/history/search.dart'; +import 'package:jisho_study_tool/objectbox.g.dart'; +import 'package:settings_ui/settings_ui.dart'; + +class SettingsView extends StatelessWidget { + Widget build(BuildContext context) { + return SettingsList( + sections: [ + SettingsSection( + title: 'Cache', + tiles: [ + SettingsTile.switchTile( + title: 'Cache grade 1-7 kanji (N/A)', + switchValue: false, + onToggle: (v) {}, + ), + SettingsTile.switchTile( + title: 'Cache grade standard kanji (N/A)', + switchValue: false, + onToggle: (v) {}, + ), + SettingsTile.switchTile( + title: 'Cache all favourites (N/A)', + switchValue: false, + onToggle: (v) {}, + ), + SettingsTile.switchTile( + title: 'Cache all searches (N/A)', + switchValue: false, + onToggle: (v) {}, + ), + ], + ), + SettingsSection( + title: 'Data', + tiles: [ + SettingsTile( + leading: Icon(Icons.file_download), + title: 'Export Data (N/A)', + ), + SettingsTile( + leading: Icon(Icons.delete), + title: 'Clear History (N/A)', + onPressed: _clearHistory, + titleTextStyle: TextStyle(color: Colors.red), + ), + SettingsTile( + leading: Icon(Icons.delete), + title: 'Clear Favourites (N/A)', + onPressed: (c) {}, + titleTextStyle: TextStyle(color: Colors.red), + ) + ], + ) + ], + ); + } +} + +void _clearHistory(context) async { + if (await confirm(context)) { + Store db = + (BlocProvider.of(context).state as DatabaseConnected) + .database; + // db.box().query().build().find() + db.box().removeAll(); + } +} diff --git a/pubspec.yaml b/pubspec.yaml index 19e834e..d196ef4 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -7,6 +7,7 @@ environment: dependencies: animated_size_and_fade: ^2.0.0 + confirm_dialog: ^1.0.0 division: ^0.9.0 flutter: sdk: flutter @@ -19,6 +20,7 @@ dependencies: shared_preferences: ^2.0.6 unofficial_jisho_api: ^2.0.2 url_launcher: ^6.0.9 + settings_ui: ^1.0.0 dev_dependencies: