Basic Dark theme and option for theme in settings

This commit is contained in:
2023-05-24 21:53:18 +02:00
parent 9a1247de5f
commit 9aea09d582
4 changed files with 159 additions and 56 deletions

View File

@ -3,6 +3,7 @@ import 'dart:io';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:jiffy/jiffy.dart';
import 'package:marianum_mobile/data/appTheme.dart';
import 'package:marianum_mobile/data/timetable/timetableProps.dart';
import 'package:marianum_mobile/screen/login/login.dart';
import 'package:marianum_mobile/widget/errorView.dart';
@ -30,6 +31,7 @@ Future<void> main() async {
MultiProvider(
providers: [
ChangeNotifierProvider(create: (context) => AccountModel()),
ChangeNotifierProvider(create: (context) => AppTheme()),
ChangeNotifierProvider(create: (context) => TimetableProps()),
ChangeNotifierProvider(create: (context) => ChatListProps()),
ChangeNotifierProvider(create: (context) => ChatProps()),
@ -70,63 +72,101 @@ class _MainState extends State<Main> {
Widget build(BuildContext context) {
SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);
return MaterialApp(
debugShowCheckedModeBanner: false,
localizationsDelegates: const [
...GlobalMaterialLocalizations.delegates,
GlobalWidgetsLocalizations.delegate,
],
supportedLocales: const [
Locale('de'),
Locale('en'),
],
locale: const Locale('de'),
return Directionality(
textDirection: TextDirection.ltr,
child: Consumer<AppTheme>(
builder: (context, value, child) {
return MaterialApp(
debugShowCheckedModeBanner: false,
localizationsDelegates: const [
...GlobalMaterialLocalizations.delegates,
GlobalWidgetsLocalizations.delegate,
],
supportedLocales: const [
Locale('de'),
Locale('en'),
],
locale: const Locale('de'),
title: 'Marianum Fulda',
theme: ThemeData(
brightness: Brightness.light,
primaryColor: marianumRed,
colorScheme: const ColorScheme(
brightness: Brightness.light,
surface: Colors.white,
onSurface: Colors.black,
onSecondary: Colors.white,
onPrimary: Colors.white,
onError: marianumRed,
onBackground: Colors.black,
error: marianumRed,
background: Colors.white,
secondary: marianumRed,
primary: marianumRed,
),
hintColor: marianumRed,
inputDecorationTheme: const InputDecorationTheme(
border: UnderlineInputBorder(borderSide: BorderSide(color: marianumRed)),
),
appBarTheme: const AppBarTheme(
backgroundColor: marianumRed,
),
progressIndicatorTheme: const ProgressIndicatorThemeData(
color: marianumRed,
),
),
title: 'Marianum Fulda',
home: FutureBuilder<SharedPreferences>(
future: _storage,
builder: (BuildContext context, AsyncSnapshot<SharedPreferences> snapshot) {
themeMode: value.getMode,
theme: ThemeData(
brightness: Brightness.light,
primaryColor: marianumRed,
colorScheme: const ColorScheme(
brightness: Brightness.light,
surface: Colors.white,
onSurface: Colors.black,
onSecondary: Colors.white,
onPrimary: Colors.white,
onError: marianumRed,
onBackground: Colors.black,
error: marianumRed,
background: Colors.white,
secondary: Colors.grey,
primary: marianumRed,
),
hintColor: marianumRed,
inputDecorationTheme: const InputDecorationTheme(
border: UnderlineInputBorder(borderSide: BorderSide(color: marianumRed)),
),
appBarTheme: const AppBarTheme(
backgroundColor: marianumRed,
),
progressIndicatorTheme: const ProgressIndicatorThemeData(
color: marianumRed,
),
),
if(snapshot.hasData) {
return Consumer<AccountModel>(
builder: (context, accountModel, child) {
return accountModel.isLoggedIn ? const App() : const Login();
},
);
} else {
return const Center(child: CircularProgressIndicator());
}
darkTheme: ThemeData(
brightness: Brightness.dark,
primaryColor: marianumRed,
colorScheme: const ColorScheme(
brightness: Brightness.dark,
surface: Colors.white,
onSurface: Colors.white,
onSecondary: Colors.black,
onPrimary: Colors.black,
onError: marianumRed,
onBackground: Colors.black,
error: marianumRed,
background: Colors.black,
secondary: Colors.grey,
primary: marianumRed,
),
hintColor: marianumRed,
inputDecorationTheme: const InputDecorationTheme(
border: UnderlineInputBorder(borderSide: BorderSide(color: marianumRed)),
),
appBarTheme: const AppBarTheme(
backgroundColor: marianumRed,
),
progressIndicatorTheme: const ProgressIndicatorThemeData(
color: marianumRed,
),
),
home: FutureBuilder<SharedPreferences>(
future: _storage,
builder: (BuildContext context, AsyncSnapshot<SharedPreferences> snapshot) {
if(snapshot.hasData) {
return Consumer<AccountModel>(
builder: (context, accountModel, child) {
return accountModel.isLoggedIn ? const App() : const Login();
},
);
} else {
return const Center(child: CircularProgressIndicator());
}
},
)
);
},
)
),
);
}
}