mirror of
https://github.com/go-vikunja/app
synced 2024-06-01 02:06:51 +00:00
migrated to material3, added option for other themes for later
This commit is contained in:
parent
9c5ad58299
commit
33242c2bfb
|
@ -97,11 +97,15 @@ class VikunjaApp extends StatelessWidget {
|
||||||
return new ValueListenableBuilder(valueListenable: updateTheme, builder: (_,mode,__) {
|
return new ValueListenableBuilder(valueListenable: updateTheme, builder: (_,mode,__) {
|
||||||
updateTheme.value = false;
|
updateTheme.value = false;
|
||||||
Future<ThemeData> theme = manager.getThemeMode().then((value) {
|
Future<ThemeData> theme = manager.getThemeMode().then((value) {
|
||||||
if (value == ThemeMode.dark) {
|
switch(value) {
|
||||||
return buildVikunjaDarkTheme();
|
case FlutterThemeMode.dark:
|
||||||
} else {
|
return buildVikunjaDarkTheme();
|
||||||
return buildVikunjaTheme();
|
case FlutterThemeMode.materialUi:
|
||||||
|
return buildVikunjaMaterialTheme();
|
||||||
|
default:
|
||||||
|
return buildVikunjaTheme();
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
return FutureBuilder<ThemeData>(
|
return FutureBuilder<ThemeData>(
|
||||||
future: theme,
|
future: theme,
|
||||||
|
|
|
@ -38,10 +38,10 @@ class HomePageState extends State<HomePage> {
|
||||||
SettingsPage()
|
SettingsPage()
|
||||||
];
|
];
|
||||||
|
|
||||||
List<BottomNavigationBarItem> navbarItems = [
|
List<NavigationDestination> navbarItems = [
|
||||||
BottomNavigationBarItem(icon: Icon(Icons.home), label: "Home"),
|
NavigationDestination(icon: Icon(Icons.home), label: "Home"),
|
||||||
BottomNavigationBarItem(icon: Icon(Icons.list), label: "Projects"),
|
NavigationDestination(icon: Icon(Icons.list), label: "Projects"),
|
||||||
BottomNavigationBarItem(icon: Icon(Icons.settings), label: "Settings"),
|
NavigationDestination(icon: Icon(Icons.settings), label: "Settings"),
|
||||||
];
|
];
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -51,10 +51,10 @@ class HomePageState extends State<HomePage> {
|
||||||
drawerItem = _getDrawerItemWidget(_selectedDrawerIndex);
|
drawerItem = _getDrawerItemWidget(_selectedDrawerIndex);
|
||||||
|
|
||||||
return new Scaffold(
|
return new Scaffold(
|
||||||
bottomNavigationBar: BottomNavigationBar(
|
bottomNavigationBar: NavigationBar(
|
||||||
items: navbarItems,
|
destinations: navbarItems,
|
||||||
currentIndex: _selectedDrawerIndex,
|
selectedIndex: _selectedDrawerIndex,
|
||||||
onTap: (index) {
|
onDestinationSelected: (index) {
|
||||||
setState(() {
|
setState(() {
|
||||||
_selectedDrawerIndex = index;
|
_selectedDrawerIndex = index;
|
||||||
});
|
});
|
||||||
|
|
|
@ -156,7 +156,7 @@ class _ProjectEditPageState extends State<ProjectEditPage> {
|
||||||
VikunjaGlobal.of(context).projectService.update(newProject).then((_) {
|
VikunjaGlobal.of(context).projectService.update(newProject).then((_) {
|
||||||
setState(() => _loading = false);
|
setState(() => _loading = false);
|
||||||
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
|
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
|
||||||
content: Text('The task was updated successfully!'),
|
content: Text('The project was updated successfully!'),
|
||||||
));
|
));
|
||||||
}).catchError((err) {
|
}).catchError((err) {
|
||||||
setState(() => _loading = false);
|
setState(() => _loading = false);
|
||||||
|
|
|
@ -369,6 +369,7 @@ class _ListPageState extends State<ListPage> {
|
||||||
));
|
));
|
||||||
setState(() {
|
setState(() {
|
||||||
_loadingTasks.remove(newTask);
|
_loadingTasks.remove(newTask);
|
||||||
|
_loadList();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@ import 'package:vikunja_app/models/list.dart';
|
||||||
|
|
||||||
import '../main.dart';
|
import '../main.dart';
|
||||||
import '../models/project.dart';
|
import '../models/project.dart';
|
||||||
|
import '../service/services.dart';
|
||||||
|
|
||||||
|
|
||||||
class SettingsPage extends StatefulWidget {
|
class SettingsPage extends StatefulWidget {
|
||||||
|
@ -21,7 +22,7 @@ class SettingsPageState extends State<SettingsPage> {
|
||||||
String? versionTag, newestVersionTag;
|
String? versionTag, newestVersionTag;
|
||||||
late TextEditingController durationTextController;
|
late TextEditingController durationTextController;
|
||||||
bool initialized = false;
|
bool initialized = false;
|
||||||
ThemeMode? themeMode;
|
FlutterThemeMode? themeMode;
|
||||||
|
|
||||||
|
|
||||||
void init() {
|
void init() {
|
||||||
|
@ -114,23 +115,27 @@ class SettingsPageState extends State<SettingsPage> {
|
||||||
Divider(),
|
Divider(),
|
||||||
ListTile(
|
ListTile(
|
||||||
title: Text("Theme"),
|
title: Text("Theme"),
|
||||||
trailing: DropdownButton<ThemeMode>(
|
trailing: DropdownButton<FlutterThemeMode>(
|
||||||
items: [
|
items: [
|
||||||
DropdownMenuItem(
|
DropdownMenuItem(
|
||||||
child: Text("System"),
|
child: Text("System"),
|
||||||
value: ThemeMode.system,
|
value: FlutterThemeMode.system,
|
||||||
),
|
),
|
||||||
DropdownMenuItem(
|
DropdownMenuItem(
|
||||||
child: Text("Light"),
|
child: Text("Light"),
|
||||||
value: ThemeMode.light,
|
value: FlutterThemeMode.light,
|
||||||
),
|
),
|
||||||
DropdownMenuItem(
|
DropdownMenuItem(
|
||||||
child: Text("Dark"),
|
child: Text("Dark"),
|
||||||
value: ThemeMode.dark,
|
value: FlutterThemeMode.dark,
|
||||||
|
),
|
||||||
|
DropdownMenuItem(
|
||||||
|
child: Text("Material You"),
|
||||||
|
value: FlutterThemeMode.materialUi,
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
value: themeMode,
|
value: themeMode,
|
||||||
onChanged: (ThemeMode? value) {
|
onChanged: (FlutterThemeMode? value) {
|
||||||
VikunjaGlobal.of(context)
|
VikunjaGlobal.of(context)
|
||||||
.settingsManager
|
.settingsManager
|
||||||
.setThemeMode(value!);
|
.setThemeMode(value!);
|
||||||
|
|
|
@ -309,24 +309,31 @@ class SettingsManager {
|
||||||
return _storage.write(key: "recent-servers", value: jsonEncode(server));
|
return _storage.write(key: "recent-servers", value: jsonEncode(server));
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<ThemeMode> getThemeMode() async {
|
Future<FlutterThemeMode> getThemeMode() async {
|
||||||
String? theme_mode = await _storage.read(key: "theme_mode");
|
String? theme_mode = await _storage.read(key: "theme_mode");
|
||||||
if(theme_mode == null)
|
if(theme_mode == null)
|
||||||
setThemeMode(ThemeMode.system);
|
setThemeMode(FlutterThemeMode.system);
|
||||||
switch(theme_mode) {
|
switch(theme_mode) {
|
||||||
case "system":
|
case "system":
|
||||||
return ThemeMode.system;
|
return FlutterThemeMode.system;
|
||||||
case "light":
|
case "light":
|
||||||
return ThemeMode.light;
|
return FlutterThemeMode.light;
|
||||||
case "dark":
|
case "dark":
|
||||||
return ThemeMode.dark;
|
return FlutterThemeMode.dark;
|
||||||
default:
|
default:
|
||||||
return ThemeMode.system;
|
return FlutterThemeMode.system;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> setThemeMode(ThemeMode newMode) async {
|
Future<void> setThemeMode(FlutterThemeMode newMode) async {
|
||||||
await _storage.write(key: "theme_mode", value: newMode.toString().split('.').last);
|
await _storage.write(key: "theme_mode", value: newMode.toString().split('.').last);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum FlutterThemeMode {
|
||||||
|
system,
|
||||||
|
light,
|
||||||
|
dark,
|
||||||
|
materialUi
|
||||||
|
}
|
|
@ -6,8 +6,15 @@ import 'package:vikunja_app/theme/constants.dart';
|
||||||
ThemeData buildVikunjaTheme() => _buildVikunjaTheme(ThemeData.light());
|
ThemeData buildVikunjaTheme() => _buildVikunjaTheme(ThemeData.light());
|
||||||
ThemeData buildVikunjaDarkTheme() => _buildVikunjaTheme(ThemeData.dark(), isDark: true);
|
ThemeData buildVikunjaDarkTheme() => _buildVikunjaTheme(ThemeData.dark(), isDark: true);
|
||||||
|
|
||||||
|
ThemeData buildVikunjaMaterialTheme() {
|
||||||
|
return _buildVikunjaTheme(ThemeData.light()).copyWith(
|
||||||
|
useMaterial3: true,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
ThemeData _buildVikunjaTheme(ThemeData base, {bool isDark = false}) {
|
ThemeData _buildVikunjaTheme(ThemeData base, {bool isDark = false}) {
|
||||||
return base.copyWith(
|
return base.copyWith(
|
||||||
|
useMaterial3: true,
|
||||||
errorColor: vRed,
|
errorColor: vRed,
|
||||||
primaryColor: vPrimaryDark,
|
primaryColor: vPrimaryDark,
|
||||||
primaryColorLight: vPrimary,
|
primaryColorLight: vPrimary,
|
||||||
|
@ -31,7 +38,20 @@ ThemeData _buildVikunjaTheme(ThemeData base, {bool isDark = false}) {
|
||||||
vWhite, // This does not work, looks like a bug in Flutter: https://github.com/flutter/flutter/issues/19623
|
vWhite, // This does not work, looks like a bug in Flutter: https://github.com/flutter/flutter/issues/19623
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
bottomNavigationBarTheme: base.bottomNavigationBarTheme.copyWith(
|
inputDecorationTheme: InputDecorationTheme(
|
||||||
|
enabledBorder: UnderlineInputBorder(
|
||||||
|
borderSide: const BorderSide(color: Colors.grey, width: 1)
|
||||||
|
),
|
||||||
|
|
||||||
|
),
|
||||||
|
|
||||||
|
dividerTheme: DividerThemeData(
|
||||||
|
color: () {
|
||||||
|
return isDark ? Colors.white10 : Colors.black12;
|
||||||
|
}(),
|
||||||
|
),
|
||||||
|
navigationBarTheme: base.navigationBarTheme.copyWith(
|
||||||
|
indicatorColor: vPrimary,
|
||||||
// Make bottomNavigationBar backgroundColor darker to provide more separation
|
// Make bottomNavigationBar backgroundColor darker to provide more separation
|
||||||
backgroundColor: () {
|
backgroundColor: () {
|
||||||
final _hslColor = HSLColor.fromColor(
|
final _hslColor = HSLColor.fromColor(
|
||||||
|
|
Loading…
Reference in New Issue
Block a user