prasule/lib/views/settings/settings.dart
2023-12-29 21:39:54 +01:00

109 lines
3.8 KiB
Dart

import 'dart:io';
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:prasule/main.dart';
import 'package:prasule/pw/platformroute.dart';
import 'package:prasule/views/settings/edit_categories.dart';
import 'package:prasule/views/settings/graph_type.dart';
import 'package:prasule/views/settings/tessdata_list.dart';
import 'package:settings_ui/settings_ui.dart';
import 'package:shared_preferences/shared_preferences.dart';
/// Shows settings categories
class SettingsView extends StatefulWidget {
/// Shows settings categories
const SettingsView({super.key});
@override
State<SettingsView> createState() => _SettingsViewState();
}
class _SettingsViewState extends State<SettingsView> {
var _useMaterialYou = true;
final _supportsYou = MyApp.appliedYou;
@override
void initState() {
super.initState();
SharedPreferences.getInstance().then((s) {
_useMaterialYou = s.getBool("useMaterialYou") ?? true;
setState(() {});
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text(AppLocalizations.of(context).settings)),
body: SettingsList(
applicationType: ApplicationType.both,
darkTheme: SettingsThemeData(
settingsListBackground: Theme.of(context).colorScheme.background,
titleTextColor: Theme.of(context).colorScheme.primary,
),
sections: [
SettingsSection(
tiles: [
SettingsTile.navigation(
title: Text(AppLocalizations.of(context).editCategories),
description:
Text(AppLocalizations.of(context).editCategoriesDesc),
trailing: const Icon(Icons.keyboard_arrow_right),
onPressed: (context) => Navigator.of(context).push(
platformRoute(
(c) => const EditCategoriesView(),
),
),
),
],
),
SettingsSection(
tiles: [
SettingsTile.navigation(
title: Text(AppLocalizations.of(context).downloadedOcr),
description:
Text(AppLocalizations.of(context).downloadedOcrDesc),
trailing: const Icon(Icons.keyboard_arrow_right),
onPressed: (context) => Navigator.of(context).push(
platformRoute(
(c) => const TessdataListView(),
),
),
),
],
title: Text(AppLocalizations.of(context).ocr),
),
SettingsSection(
title: Text(AppLocalizations.of(context).settingsAppearance),
tiles: [
SettingsTile.navigation(
title: Text(AppLocalizations.of(context).graphType),
description: Text(AppLocalizations.of(context).graphTypeDesc),
trailing: const Icon(Icons.keyboard_arrow_right),
onPressed: (c) => Navigator.of(c).push(
platformRoute(
(p0) => const GraphTypeSettingsView(),
),
),
),
if (Platform.isAndroid && _supportsYou)
SettingsTile.switchTile(
initialValue: _useMaterialYou,
onToggle: (v) async {
final s = await SharedPreferences.getInstance();
await s.setBool("useMaterialYou", v);
_useMaterialYou = v;
setState(() {});
},
title: Text(AppLocalizations.of(context).enableYou),
description: Text(
AppLocalizations.of(context).enableYouDesc,
),
),
],
),
],
),
);
}
}