From c3a817273916d06321b734f549e0cb5ea94a52c4 Mon Sep 17 00:00:00 2001 From: Benimautner Date: Sun, 23 Jul 2023 21:56:34 +0200 Subject: [PATCH] added material you, changed button style --- lib/main.dart | 21 +++++-- lib/pages/project/project_task_list.dart | 70 ++++++++++++------------ lib/pages/settings.dart | 8 ++- lib/service/services.dart | 7 ++- lib/theme/button.dart | 3 +- lib/theme/buttonText.dart | 3 +- lib/theme/theme.dart | 9 ++- pubspec.lock | 10 +++- pubspec.yaml | 1 + 9 files changed, 86 insertions(+), 46 deletions(-) diff --git a/lib/main.dart b/lib/main.dart index 0e66d5e..1f80c0f 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,5 +1,6 @@ import 'dart:io'; +import 'package:dynamic_color/dynamic_color.dart'; import 'package:flutter/material.dart'; import 'package:flutter_secure_storage/flutter_secure_storage.dart'; import 'package:permission_handler/permission_handler.dart'; @@ -96,12 +97,16 @@ class VikunjaApp extends StatelessWidget { return new ValueListenableBuilder(valueListenable: updateTheme, builder: (_,mode,__) { updateTheme.value = false; + FlutterThemeMode themeMode = FlutterThemeMode.system; Future theme = manager.getThemeMode().then((value) { + themeMode = value; switch(value) { case FlutterThemeMode.dark: return buildVikunjaDarkTheme(); - case FlutterThemeMode.materialUi: - return buildVikunjaMaterialTheme(); + case FlutterThemeMode.materialYouLight: + return buildVikunjaMaterialLightTheme(); + case FlutterThemeMode.materialYouDark: + return buildVikunjaMaterialDarkTheme(); default: return buildVikunjaTheme(); } @@ -111,14 +116,22 @@ class VikunjaApp extends StatelessWidget { future: theme, builder: (BuildContext context, AsyncSnapshot data) { if(data.hasData) { - return new MaterialApp( + return new DynamicColorBuilder(builder: (lightTheme, darkTheme) + { + ThemeData? themeData = data.data; + if(themeMode == FlutterThemeMode.materialYouLight) + themeData = themeData?.copyWith(colorScheme: lightTheme); + else if(themeMode == FlutterThemeMode.materialYouDark) + themeData = themeData?.copyWith(colorScheme: darkTheme); + return MaterialApp( title: 'Vikunja', - theme: data.data, + theme: themeData, scaffoldMessengerKey: globalSnackbarKey, navigatorKey: navkey, // <= this home: this.home, ); + }); } else { return Center(child: CircularProgressIndicator()); } diff --git a/lib/pages/project/project_task_list.dart b/lib/pages/project/project_task_list.dart index 0972e5b..ade420e 100644 --- a/lib/pages/project/project_task_list.dart +++ b/lib/pages/project/project_task_list.dart @@ -97,7 +97,7 @@ class _ListPageState extends State { ]); break; case PageStatus.success: - body = taskState.tasks.length > 0 || taskState.buckets.length > 0 + body = taskState.tasks.length > 0 || taskState.buckets.length > 0 || _project.subprojects!.length > 0 ? ListenableProvider.value( value: taskState, child: Theme( @@ -182,6 +182,7 @@ class _ListPageState extends State { Widget buildSubProjectSelector() { return Container( height: 80, + padding: EdgeInsets.fromLTRB(10, 0, 10, 0), child: ListView( scrollDirection: Axis.horizontal, @@ -213,42 +214,43 @@ class _ListPageState extends State { } Widget _listView(BuildContext context) { - List subProjectView = []; + List children = []; if(widget.project.subprojects?.length != 0) { - subProjectView.add(Padding(child: Text("Projects", style: TextStyle(fontWeight: FontWeight.bold),), padding: EdgeInsets.fromLTRB(0, 10, 0, 0),)); - subProjectView.add(buildSubProjectSelector()); - subProjectView.add(Padding(child: Text("Tasks", style: TextStyle(fontWeight: FontWeight.bold),), padding: EdgeInsets.fromLTRB(0, 10, 0, 0),)); - subProjectView.add(Divider()); + children.add(Padding(child: Text("Projects", style: TextStyle(fontWeight: FontWeight.bold),), padding: EdgeInsets.fromLTRB(0, 10, 0, 0),)); + children.add(buildSubProjectSelector()); + + } + if(taskState.tasks.length != 0) { + children.add(Padding(child: Text("Tasks", style: TextStyle(fontWeight: FontWeight.bold),), padding: EdgeInsets.fromLTRB(0, 10, 0, 0),)); + children.add(Divider()); + children.add(Expanded(child: + ListView.builder( + padding: EdgeInsets.symmetric(vertical: 8.0), + itemCount: taskState.tasks.length * 2, + itemBuilder: (context, i) { + if (i.isOdd) return Divider(); + + if (_loadingTasks.isNotEmpty) { + final loadingTask = _loadingTasks.removeLast(); + return _buildLoadingTile(loadingTask); + } + + final index = i ~/ 2; + + if (taskState.maxPages == _currentPage && + index == taskState.tasks.length) + throw Exception("Check itemCount attribute"); + + if (index >= taskState.tasks.length && + _currentPage < taskState.maxPages) { + _currentPage++; + _loadTasksForPage(_currentPage); + } + return _buildTile(taskState.tasks[index]); + }))); } - return Column( - children: [ - ...subProjectView, - Expanded(child: - ListView.builder( - padding: EdgeInsets.symmetric(vertical: 8.0), - itemCount: taskState.tasks.length * 2, - itemBuilder: (context, i) { - if (i.isOdd) return Divider(); - - if (_loadingTasks.isNotEmpty) { - final loadingTask = _loadingTasks.removeLast(); - return _buildLoadingTile(loadingTask); - } - - final index = i ~/ 2; - - if (taskState.maxPages == _currentPage && - index == taskState.tasks.length) - throw Exception("Check itemCount attribute"); - - if (index >= taskState.tasks.length && - _currentPage < taskState.maxPages) { - _currentPage++; - _loadTasksForPage(_currentPage); - } - return _buildTile(taskState.tasks[index]); - }))]); + return Column(children: children); } Widget _buildTile(Task task) { diff --git a/lib/pages/settings.dart b/lib/pages/settings.dart index 88f88fd..e563028 100644 --- a/lib/pages/settings.dart +++ b/lib/pages/settings.dart @@ -130,8 +130,12 @@ class SettingsPageState extends State { value: FlutterThemeMode.dark, ), DropdownMenuItem( - child: Text("Material You"), - value: FlutterThemeMode.materialUi, + child: Text("Material You Light"), + value: FlutterThemeMode.materialYouLight, + ), + DropdownMenuItem( + child: Text("Material You Dark"), + value: FlutterThemeMode.materialYouDark, ), ], value: themeMode, diff --git a/lib/service/services.dart b/lib/service/services.dart index ced10fb..9a4f7b9 100644 --- a/lib/service/services.dart +++ b/lib/service/services.dart @@ -320,6 +320,10 @@ class SettingsManager { return FlutterThemeMode.light; case "dark": return FlutterThemeMode.dark; + case "materialYouLight": + return FlutterThemeMode.materialYouLight; + case "materialYouDark": + return FlutterThemeMode.materialYouDark; default: return FlutterThemeMode.system; } @@ -335,5 +339,6 @@ enum FlutterThemeMode { system, light, dark, - materialUi + materialYouLight, + materialYouDark, } \ No newline at end of file diff --git a/lib/theme/button.dart b/lib/theme/button.dart index 4647e66..44b22ba 100644 --- a/lib/theme/button.dart +++ b/lib/theme/button.dart @@ -17,6 +17,7 @@ class FancyButton extends StatelessWidget { @override Widget build(BuildContext context) { + return ElevatedButton(onPressed: onPressed, child: child); return Padding( padding: vStandardVerticalPadding, child: Container( @@ -33,7 +34,7 @@ class FancyButton extends StatelessWidget { ]), child: Material( borderRadius: BorderRadius.circular(3), - color: vButtonColor, + color: Theme.of(context).colorScheme.primary, child: InkWell( onTap: onPressed, child: Center( diff --git a/lib/theme/buttonText.dart b/lib/theme/buttonText.dart index 0603a78..4c12819 100644 --- a/lib/theme/buttonText.dart +++ b/lib/theme/buttonText.dart @@ -11,9 +11,10 @@ class VikunjaButtonText extends StatelessWidget { @override Widget build(BuildContext context) { + return Text(text); return Text( text, - style: TextStyle(color: vButtonTextColor, fontWeight: FontWeight.w600), + style: TextStyle(color: Theme.of(context).primaryTextTheme.labelMedium?.color, fontWeight: FontWeight.w600), ); } } diff --git a/lib/theme/theme.dart b/lib/theme/theme.dart index 5cdf31b..ccdf5dd 100644 --- a/lib/theme/theme.dart +++ b/lib/theme/theme.dart @@ -6,8 +6,13 @@ import 'package:vikunja_app/theme/constants.dart'; ThemeData buildVikunjaTheme() => _buildVikunjaTheme(ThemeData.light()); ThemeData buildVikunjaDarkTheme() => _buildVikunjaTheme(ThemeData.dark(), isDark: true); -ThemeData buildVikunjaMaterialTheme() { - return _buildVikunjaTheme(ThemeData.light()).copyWith( +ThemeData buildVikunjaMaterialLightTheme() { + return ThemeData.light().copyWith( + useMaterial3: true, + ); +} +ThemeData buildVikunjaMaterialDarkTheme() { + return ThemeData.dark().copyWith( useMaterial3: true, ); } diff --git a/pubspec.lock b/pubspec.lock index 7b05cc9..a7a280d 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -177,6 +177,14 @@ packages: url: "https://pub.dev" source: hosted version: "2.0.0+3" + dynamic_color: + dependency: "direct main" + description: + name: dynamic_color + sha256: de4798a7069121aee12d5895315680258415de9b00e717723a1bd73d58f0126d + url: "https://pub.dev" + source: hosted + version: "1.6.6" fake_async: dependency: transitive description: @@ -1023,4 +1031,4 @@ packages: version: "3.1.2" sdks: dart: ">=3.0.0-0 <4.0.0" - flutter: ">=3.3.0" + flutter: ">=3.4.0-17.0.pre" diff --git a/pubspec.yaml b/pubspec.yaml index b7509cb..11a08fb 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -31,6 +31,7 @@ dependencies: url_launcher: ^6.1.7 workmanager: ^0.5.1 permission_handler: ^10.2.0 + dynamic_color: ^1.6.6 dev_dependencies: flutter_test: