Compare commits

...

2 commits

Author SHA1 Message Date
Matyáš Caras
057954f6ce
feat: allow disabling Material You 2023-12-25 20:29:51 +01:00
Matyáš Caras
9fa35660df
feat(graphs): change style 2023-12-25 19:54:30 +01:00
7 changed files with 90 additions and 30 deletions

View file

@ -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"
} }

View file

@ -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"
} }

View file

@ -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,13 +22,15 @@ 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) {
appliedYou = light != null;
return MaterialApp(
debugShowCheckedModeBanner: false, debugShowCheckedModeBanner: false,
localizationsDelegates: const [ localizationsDelegates: const [
AppLocalizations.delegate, AppLocalizations.delegate,
@ -33,13 +40,19 @@ class MyApp extends StatelessWidget {
supportedLocales: AppLocalizations.supportedLocales, supportedLocales: AppLocalizations.supportedLocales,
title: 'Prašule', title: 'Prašule',
theme: ThemeData( theme: ThemeData(
colorScheme: light ?? lightColorScheme, colorScheme: (_materialYou)
? light ?? lightColorScheme
: lightColorScheme,
useMaterial3: true, useMaterial3: true,
), ),
darkTheme: ThemeData( darkTheme: ThemeData(
useMaterial3: true, colorScheme: dark ?? darkColorScheme), useMaterial3: true,
colorScheme: (_materialYou)
? dark ?? darkColorScheme
: darkColorScheme),
home: const HomeView(), home: const HomeView(),
), );
},
) )
: Theme( : Theme(
data: ThemeData( data: ThemeData(

View file

@ -5,12 +5,16 @@ import 'package:prasule/pw/platformwidget.dart';
class PlatformButton extends PlatformWidget<TextButton, CupertinoButton> { class PlatformButton extends PlatformWidget<TextButton, CupertinoButton> {
final String text; final String text;
final void Function()? onPressed; final void Function()? onPressed;
final ButtonStyle? style;
const PlatformButton( const PlatformButton(
{super.key, required this.text, required this.onPressed}); {super.key, required this.text, required this.onPressed, this.style});
@override @override
TextButton createAndroidWidget(BuildContext context) => TextButton createAndroidWidget(BuildContext context) => TextButton(
TextButton(onPressed: onPressed, child: Text(text)); onPressed: onPressed,
style: style,
child: Text(text),
);
@override @override
CupertinoButton createIosWidget(BuildContext context) => CupertinoButton createIosWidget(BuildContext context) =>

View file

@ -1,4 +1,5 @@
import 'package:currency_picker/currency_picker.dart'; import 'package:currency_picker/currency_picker.dart';
import 'package:dynamic_color/dynamic_color.dart';
import 'package:fl_chart/fl_chart.dart'; import 'package:fl_chart/fl_chart.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:intl/intl.dart'; import 'package:intl/intl.dart';
@ -102,7 +103,8 @@ class ExpensesLineChart extends StatelessWidget {
isStrokeCapRound: true, isStrokeCapRound: true,
dotData: const FlDotData(show: false), dotData: const FlDotData(show: false),
belowBarData: BarAreaData(show: false), belowBarData: BarAreaData(show: false),
color: Theme.of(context).colorScheme.primary, color: Colors.green
.harmonizeWith(Theme.of(context).colorScheme.secondary),
spots: List.generate( spots: List.generate(
(yearly) ? 12 : DateTime(date.year, date.month, 0).day, (yearly) ? 12 : DateTime(date.year, date.month, 0).day,
(index) => FlSpot(index.toDouble(), incomeData[index]), (index) => FlSpot(index.toDouble(), incomeData[index]),
@ -115,7 +117,8 @@ class ExpensesLineChart extends StatelessWidget {
isStrokeCapRound: true, isStrokeCapRound: true,
dotData: const FlDotData(show: false), dotData: const FlDotData(show: false),
belowBarData: BarAreaData(show: false), belowBarData: BarAreaData(show: false),
color: Theme.of(context).colorScheme.error, color: Colors.red
.harmonizeWith(Theme.of(context).colorScheme.secondary),
spots: List.generate( spots: List.generate(
(yearly) ? 12 : DateTime(date.year, date.month, 0).day, (yearly) ? 12 : DateTime(date.year, date.month, 0).day,
(index) => FlSpot(index.toDouble() + 1, expenseData[index]), (index) => FlSpot(index.toDouble() + 1, expenseData[index]),
@ -277,12 +280,14 @@ class ExpensesBarChart extends StatelessWidget {
if (incomeData.isNotEmpty) if (incomeData.isNotEmpty)
BarChartRodData( BarChartRodData(
toY: incomeData[index], toY: incomeData[index],
color: Theme.of(context).colorScheme.primary, color: Colors.green
.harmonizeWith(Theme.of(context).colorScheme.secondary),
), ),
if (expenseData.isNotEmpty) if (expenseData.isNotEmpty)
BarChartRodData( BarChartRodData(
toY: expenseData[index], toY: expenseData[index],
color: Theme.of(context).colorScheme.error, color: Colors.red
.harmonizeWith(Theme.of(context).colorScheme.secondary),
), ),
], ],
), ),

View file

@ -153,7 +153,7 @@ class _GraphViewState extends State<GraphView> {
strokeWidth: 5, strokeWidth: 5,
) )
: SizedBox( : SizedBox(
width: MediaQuery.of(context).size.width * 0.9, width: MediaQuery.of(context).size.width,
height: MediaQuery.of(context).size.height, height: MediaQuery.of(context).size.height,
child: Column( child: Column(
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
@ -212,6 +212,13 @@ class _GraphViewState extends State<GraphView> {
child: Column( child: Column(
children: [ children: [
PlatformButton( PlatformButton(
style: ButtonStyle(
backgroundColor: MaterialStateProperty.all(
Theme.of(context).colorScheme.primary),
foregroundColor: MaterialStateProperty.all(
Theme.of(context)
.colorScheme
.onPrimary)),
text: (yearly) text: (yearly)
? DateFormat.y(locale).format(_selectedDate) ? DateFormat.y(locale).format(_selectedDate)
: DateFormat.yMMMM(locale) : DateFormat.yMMMM(locale)

View file

@ -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,6 +63,18 @@ 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),
) )
], ],
) )