mirror of
https://github.com/go-vikunja/app
synced 2024-06-05 03:59:48 +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,__) {
|
||||
updateTheme.value = false;
|
||||
Future<ThemeData> theme = manager.getThemeMode().then((value) {
|
||||
if (value == ThemeMode.dark) {
|
||||
return buildVikunjaDarkTheme();
|
||||
} else {
|
||||
return buildVikunjaTheme();
|
||||
switch(value) {
|
||||
case FlutterThemeMode.dark:
|
||||
return buildVikunjaDarkTheme();
|
||||
case FlutterThemeMode.materialUi:
|
||||
return buildVikunjaMaterialTheme();
|
||||
default:
|
||||
return buildVikunjaTheme();
|
||||
}
|
||||
|
||||
});
|
||||
return FutureBuilder<ThemeData>(
|
||||
future: theme,
|
||||
|
|
|
@ -38,10 +38,10 @@ class HomePageState extends State<HomePage> {
|
|||
SettingsPage()
|
||||
];
|
||||
|
||||
List<BottomNavigationBarItem> navbarItems = [
|
||||
BottomNavigationBarItem(icon: Icon(Icons.home), label: "Home"),
|
||||
BottomNavigationBarItem(icon: Icon(Icons.list), label: "Projects"),
|
||||
BottomNavigationBarItem(icon: Icon(Icons.settings), label: "Settings"),
|
||||
List<NavigationDestination> navbarItems = [
|
||||
NavigationDestination(icon: Icon(Icons.home), label: "Home"),
|
||||
NavigationDestination(icon: Icon(Icons.list), label: "Projects"),
|
||||
NavigationDestination(icon: Icon(Icons.settings), label: "Settings"),
|
||||
];
|
||||
|
||||
@override
|
||||
|
@ -51,10 +51,10 @@ class HomePageState extends State<HomePage> {
|
|||
drawerItem = _getDrawerItemWidget(_selectedDrawerIndex);
|
||||
|
||||
return new Scaffold(
|
||||
bottomNavigationBar: BottomNavigationBar(
|
||||
items: navbarItems,
|
||||
currentIndex: _selectedDrawerIndex,
|
||||
onTap: (index) {
|
||||
bottomNavigationBar: NavigationBar(
|
||||
destinations: navbarItems,
|
||||
selectedIndex: _selectedDrawerIndex,
|
||||
onDestinationSelected: (index) {
|
||||
setState(() {
|
||||
_selectedDrawerIndex = index;
|
||||
});
|
||||
|
|
|
@ -156,7 +156,7 @@ class _ProjectEditPageState extends State<ProjectEditPage> {
|
|||
VikunjaGlobal.of(context).projectService.update(newProject).then((_) {
|
||||
setState(() => _loading = false);
|
||||
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
|
||||
content: Text('The task was updated successfully!'),
|
||||
content: Text('The project was updated successfully!'),
|
||||
));
|
||||
}).catchError((err) {
|
||||
setState(() => _loading = false);
|
||||
|
|
|
@ -369,6 +369,7 @@ class _ListPageState extends State<ListPage> {
|
|||
));
|
||||
setState(() {
|
||||
_loadingTasks.remove(newTask);
|
||||
_loadList();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ import 'package:vikunja_app/models/list.dart';
|
|||
|
||||
import '../main.dart';
|
||||
import '../models/project.dart';
|
||||
import '../service/services.dart';
|
||||
|
||||
|
||||
class SettingsPage extends StatefulWidget {
|
||||
|
@ -21,7 +22,7 @@ class SettingsPageState extends State<SettingsPage> {
|
|||
String? versionTag, newestVersionTag;
|
||||
late TextEditingController durationTextController;
|
||||
bool initialized = false;
|
||||
ThemeMode? themeMode;
|
||||
FlutterThemeMode? themeMode;
|
||||
|
||||
|
||||
void init() {
|
||||
|
@ -114,23 +115,27 @@ class SettingsPageState extends State<SettingsPage> {
|
|||
Divider(),
|
||||
ListTile(
|
||||
title: Text("Theme"),
|
||||
trailing: DropdownButton<ThemeMode>(
|
||||
trailing: DropdownButton<FlutterThemeMode>(
|
||||
items: [
|
||||
DropdownMenuItem(
|
||||
child: Text("System"),
|
||||
value: ThemeMode.system,
|
||||
value: FlutterThemeMode.system,
|
||||
),
|
||||
DropdownMenuItem(
|
||||
child: Text("Light"),
|
||||
value: ThemeMode.light,
|
||||
value: FlutterThemeMode.light,
|
||||
),
|
||||
DropdownMenuItem(
|
||||
child: Text("Dark"),
|
||||
value: ThemeMode.dark,
|
||||
value: FlutterThemeMode.dark,
|
||||
),
|
||||
DropdownMenuItem(
|
||||
child: Text("Material You"),
|
||||
value: FlutterThemeMode.materialUi,
|
||||
),
|
||||
],
|
||||
value: themeMode,
|
||||
onChanged: (ThemeMode? value) {
|
||||
onChanged: (FlutterThemeMode? value) {
|
||||
VikunjaGlobal.of(context)
|
||||
.settingsManager
|
||||
.setThemeMode(value!);
|
||||
|
|
|
@ -309,24 +309,31 @@ class SettingsManager {
|
|||
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");
|
||||
if(theme_mode == null)
|
||||
setThemeMode(ThemeMode.system);
|
||||
setThemeMode(FlutterThemeMode.system);
|
||||
switch(theme_mode) {
|
||||
case "system":
|
||||
return ThemeMode.system;
|
||||
return FlutterThemeMode.system;
|
||||
case "light":
|
||||
return ThemeMode.light;
|
||||
return FlutterThemeMode.light;
|
||||
case "dark":
|
||||
return ThemeMode.dark;
|
||||
return FlutterThemeMode.dark;
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
enum FlutterThemeMode {
|
||||
system,
|
||||
light,
|
||||
dark,
|
||||
materialUi
|
||||
}
|
|
@ -6,8 +6,15 @@ 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(
|
||||
useMaterial3: true,
|
||||
);
|
||||
}
|
||||
|
||||
ThemeData _buildVikunjaTheme(ThemeData base, {bool isDark = false}) {
|
||||
return base.copyWith(
|
||||
useMaterial3: true,
|
||||
errorColor: vRed,
|
||||
primaryColor: vPrimaryDark,
|
||||
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
|
||||
),
|
||||
),
|
||||
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
|
||||
backgroundColor: () {
|
||||
final _hslColor = HSLColor.fromColor(
|
||||
|
|
Loading…
Reference in New Issue
Block a user