feat: allow disabling Material You
This commit is contained in:
parent
9fa35660df
commit
057954f6ce
4 changed files with 66 additions and 22 deletions
|
@ -72,6 +72,8 @@
|
||||||
"graphTypeDesc":"Zvolte, zda-li použít sloupcový, nebo spojnicový graf, a kde",
|
"graphTypeDesc":"Zvolte, zda-li použít sloupcový, nebo spojnicový graf, a kde",
|
||||||
"lineChart":"Spojnicový",
|
"lineChart":"Spojnicový",
|
||||||
"barChart":"Sloupcový",
|
"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"
|
||||||
|
|
||||||
}
|
}
|
|
@ -152,5 +152,7 @@
|
||||||
"graphTypeDesc":"Choose whether to show line or bar chart and where",
|
"graphTypeDesc":"Choose whether to show line or bar chart and where",
|
||||||
"lineChart":"Line chart",
|
"lineChart":"Line chart",
|
||||||
"barChart":"Bar 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"
|
||||||
}
|
}
|
|
@ -8,8 +8,13 @@ import 'package:logger/logger.dart';
|
||||||
import 'package:prasule/util/color_schemes.g.dart';
|
import 'package:prasule/util/color_schemes.g.dart';
|
||||||
import 'package:prasule/views/home.dart';
|
import 'package:prasule/views/home.dart';
|
||||||
import 'package:flutter_gen/gen_l10n/app_localizations.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());
|
runApp(const MyApp());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,29 +22,37 @@ final logger = Logger();
|
||||||
|
|
||||||
class MyApp extends StatelessWidget {
|
class MyApp extends StatelessWidget {
|
||||||
const MyApp({super.key});
|
const MyApp({super.key});
|
||||||
|
static bool appliedYou = false;
|
||||||
// This widget is the root of your application.
|
// This widget is the root of your application.
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return (Platform.isAndroid)
|
return (Platform.isAndroid)
|
||||||
? DynamicColorBuilder(
|
? DynamicColorBuilder(
|
||||||
builder: (light, dark) => MaterialApp(
|
builder: (light, dark) {
|
||||||
debugShowCheckedModeBanner: false,
|
appliedYou = light != null;
|
||||||
localizationsDelegates: const [
|
return MaterialApp(
|
||||||
AppLocalizations.delegate,
|
debugShowCheckedModeBanner: false,
|
||||||
...GlobalMaterialLocalizations.delegates,
|
localizationsDelegates: const [
|
||||||
...GlobalCupertinoLocalizations.delegates
|
AppLocalizations.delegate,
|
||||||
],
|
...GlobalMaterialLocalizations.delegates,
|
||||||
supportedLocales: AppLocalizations.supportedLocales,
|
...GlobalCupertinoLocalizations.delegates
|
||||||
title: 'Prašule',
|
],
|
||||||
theme: ThemeData(
|
supportedLocales: AppLocalizations.supportedLocales,
|
||||||
colorScheme: light ?? lightColorScheme,
|
title: 'Prašule',
|
||||||
useMaterial3: true,
|
theme: ThemeData(
|
||||||
),
|
colorScheme: (_materialYou)
|
||||||
darkTheme: ThemeData(
|
? light ?? lightColorScheme
|
||||||
useMaterial3: true, colorScheme: dark ?? darkColorScheme),
|
: lightColorScheme,
|
||||||
home: const HomeView(),
|
useMaterial3: true,
|
||||||
),
|
),
|
||||||
|
darkTheme: ThemeData(
|
||||||
|
useMaterial3: true,
|
||||||
|
colorScheme: (_materialYou)
|
||||||
|
? dark ?? darkColorScheme
|
||||||
|
: darkColorScheme),
|
||||||
|
home: const HomeView(),
|
||||||
|
);
|
||||||
|
},
|
||||||
)
|
)
|
||||||
: Theme(
|
: Theme(
|
||||||
data: ThemeData(
|
data: ThemeData(
|
||||||
|
|
|
@ -1,9 +1,13 @@
|
||||||
|
import 'dart:io';
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:prasule/main.dart';
|
||||||
import 'package:prasule/pw/platformroute.dart';
|
import 'package:prasule/pw/platformroute.dart';
|
||||||
import 'package:prasule/views/settings/graph_type.dart';
|
import 'package:prasule/views/settings/graph_type.dart';
|
||||||
import 'package:prasule/views/settings/tessdata_list.dart';
|
import 'package:prasule/views/settings/tessdata_list.dart';
|
||||||
import 'package:settings_ui/settings_ui.dart';
|
import 'package:settings_ui/settings_ui.dart';
|
||||||
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
||||||
|
import 'package:shared_preferences/shared_preferences.dart';
|
||||||
|
|
||||||
class SettingsView extends StatefulWidget {
|
class SettingsView extends StatefulWidget {
|
||||||
const SettingsView({super.key});
|
const SettingsView({super.key});
|
||||||
|
@ -13,6 +17,17 @@ class SettingsView extends StatefulWidget {
|
||||||
}
|
}
|
||||||
|
|
||||||
class _SettingsViewState extends State<SettingsView> {
|
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
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
|
@ -48,7 +63,19 @@ class _SettingsViewState extends State<SettingsView> {
|
||||||
(p0) => const GraphTypeSettingsView(),
|
(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),
|
||||||
|
)
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
],
|
],
|
||||||
|
|
Loading…
Reference in a new issue