feat: add graphs #16

Merged
hernik merged 9 commits from dev into main 2023-12-25 21:43:25 +01:00
4 changed files with 66 additions and 22 deletions
Showing only changes of commit 057954f6ce - Show all commits

View file

@ -72,6 +72,8 @@
"graphTypeDesc":"Zvolte, zda-li použít sloupcový, nebo spojnicový graf, a kde",
"lineChart":"Spojnicový",
"barChart":"Sloupcový",
"selectType":"Zvolte typ"
"selectType":"Zvolte typ",
"enableYou":"Povolit Material You (Může vyžadovat restart aplikace)",
"enableYouDesc":"Aplikace použije barevné schéma z vaší tapety"
}

View file

@ -152,5 +152,7 @@
"graphTypeDesc":"Choose whether to show line or bar chart and where",
"lineChart":"Line chart",
"barChart":"Bar chart",
"selectType":"Select type"
"selectType":"Select type",
"enableYou":"Enable Material You (May require an app restart)",
"enableYouDesc":"The app will use a color scheme from your wallpaper"
}

View file

@ -8,8 +8,13 @@ import 'package:logger/logger.dart';
import 'package:prasule/util/color_schemes.g.dart';
import 'package:prasule/views/home.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:shared_preferences/shared_preferences.dart';
void main() {
var _materialYou = false;
void main() async {
WidgetsFlutterBinding.ensureInitialized();
var s = await SharedPreferences.getInstance();
_materialYou = s.getBool("useMaterialYou") ?? true;
runApp(const MyApp());
}
@ -17,13 +22,15 @@ final logger = Logger();
class MyApp extends StatelessWidget {
const MyApp({super.key});
static bool appliedYou = false;
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return (Platform.isAndroid)
? DynamicColorBuilder(
builder: (light, dark) => MaterialApp(
builder: (light, dark) {
appliedYou = light != null;
return MaterialApp(
debugShowCheckedModeBanner: false,
localizationsDelegates: const [
AppLocalizations.delegate,
@ -33,13 +40,19 @@ class MyApp extends StatelessWidget {
supportedLocales: AppLocalizations.supportedLocales,
title: 'Prašule',
theme: ThemeData(
colorScheme: light ?? lightColorScheme,
colorScheme: (_materialYou)
? light ?? lightColorScheme
: lightColorScheme,
useMaterial3: true,
),
darkTheme: ThemeData(
useMaterial3: true, colorScheme: dark ?? darkColorScheme),
useMaterial3: true,
colorScheme: (_materialYou)
? dark ?? darkColorScheme
: darkColorScheme),
home: const HomeView(),
),
);
},
)
: Theme(
data: ThemeData(

View file

@ -1,9 +1,13 @@
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:prasule/main.dart';
import 'package:prasule/pw/platformroute.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:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:shared_preferences/shared_preferences.dart';
class SettingsView extends StatefulWidget {
const SettingsView({super.key});
@ -13,6 +17,17 @@ class SettingsView extends StatefulWidget {
}
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(
@ -48,6 +63,18 @@ class _SettingsViewState extends State<SettingsView> {
(p0) => const GraphTypeSettingsView(),
),
),
),
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),
)
],
)