prasule/lib/views/settings/settings.dart

86 lines
3 KiB
Dart
Raw Normal View History

2023-12-25 20:29:51 +01:00
import 'dart:io';
2023-09-08 11:50:21 +02:00
import 'package:flutter/material.dart';
2023-12-25 20:29:51 +01:00
import 'package:prasule/main.dart';
import 'package:prasule/pw/platformroute.dart';
import 'package:prasule/views/settings/graph_type.dart';
2023-09-08 11:50:21 +02:00
import 'package:prasule/views/settings/tessdata_list.dart';
import 'package:settings_ui/settings_ui.dart';
2023-10-11 18:37:18 +02:00
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
2023-12-25 20:29:51 +01:00
import 'package:shared_preferences/shared_preferences.dart';
2023-09-08 11:50:21 +02:00
class SettingsView extends StatefulWidget {
const SettingsView({super.key});
@override
State<SettingsView> createState() => _SettingsViewState();
}
class _SettingsViewState extends State<SettingsView> {
2023-12-25 20:29:51 +01:00
var _useMaterialYou = true;
final _supportsYou = MyApp.appliedYou;
@override
void initState() {
super.initState();
SharedPreferences.getInstance().then((s) {
_useMaterialYou = s.getBool("useMaterialYou") ?? true;
setState(() {});
});
}
2023-09-08 11:50:21 +02:00
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text(AppLocalizations.of(context).settings)),
2023-09-08 11:50:21 +02:00
body: SettingsList(
applicationType: ApplicationType.both,
darkTheme: SettingsThemeData(
settingsListBackground: Theme.of(context).colorScheme.background,
titleTextColor: Theme.of(context).colorScheme.primary),
2023-09-08 11:50:21 +02:00
sections: [
SettingsSection(
tiles: [
SettingsTile.navigation(
title: Text(AppLocalizations.of(context).downloadedOcr),
2023-10-11 18:37:18 +02:00
description:
Text(AppLocalizations.of(context).downloadedOcrDesc),
trailing: const Icon(Icons.keyboard_arrow_right),
onPressed: (context) => Navigator.of(context)
.push(platformRoute((c) => const TessdataListView())),
2023-09-08 11:50:21 +02:00
)
],
title: Text(AppLocalizations.of(context).ocr),
2023-09-08 11:50:21 +02:00
),
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(),
),
),
2023-12-25 20:29:51 +01:00
),
if (Platform.isAndroid && _supportsYou)
SettingsTile.switchTile(
initialValue: _useMaterialYou,
onToggle: (v) async {
var s = await SharedPreferences.getInstance();
s.setBool("useMaterialYou", v);
_useMaterialYou = v;
setState(() {});
},
title: Text(AppLocalizations.of(context).enableYou),
description: Text(AppLocalizations.of(context).enableYouDesc),
)
],
)
2023-09-08 11:50:21 +02:00
],
),
);
}
}