forked from firka/student-legacy
font changing progress
This commit is contained in:
parent
cbbf9b42b2
commit
0f4080c166
@ -43,6 +43,7 @@ const settingsDB = DatabaseStruct("settings", {
|
|||||||
"notify_s_pin": String, "extras_s_pin": String,
|
"notify_s_pin": String, "extras_s_pin": String,
|
||||||
// more
|
// more
|
||||||
"show_breaks": int,
|
"show_breaks": int,
|
||||||
|
"font_family": String,
|
||||||
});
|
});
|
||||||
// DON'T FORGET TO UPDATE DEFAULT VALUES IN `initDB` MIGRATION OR ELSE PARENTS WILL COMPLAIN ABOUT THEIR CHILDREN MISSING
|
// DON'T FORGET TO UPDATE DEFAULT VALUES IN `initDB` MIGRATION OR ELSE PARENTS WILL COMPLAIN ABOUT THEIR CHILDREN MISSING
|
||||||
// YOU'VE BEEN WARNED!!!
|
// YOU'VE BEEN WARNED!!!
|
||||||
|
@ -90,6 +90,7 @@ class SettingsProvider extends ChangeNotifier {
|
|||||||
String _pinSetExtras;
|
String _pinSetExtras;
|
||||||
// more
|
// more
|
||||||
bool _showBreaks;
|
bool _showBreaks;
|
||||||
|
String _fontFamily;
|
||||||
|
|
||||||
SettingsProvider({
|
SettingsProvider({
|
||||||
DatabaseProvider? database,
|
DatabaseProvider? database,
|
||||||
@ -146,6 +147,7 @@ class SettingsProvider extends ChangeNotifier {
|
|||||||
required String pinSetPersonalize,
|
required String pinSetPersonalize,
|
||||||
required String pinSetNotify,
|
required String pinSetNotify,
|
||||||
required String pinSetExtras,
|
required String pinSetExtras,
|
||||||
|
required String fontFamily,
|
||||||
}) : _database = database,
|
}) : _database = database,
|
||||||
_language = language,
|
_language = language,
|
||||||
_startPage = startPage,
|
_startPage = startPage,
|
||||||
@ -199,7 +201,8 @@ class SettingsProvider extends ChangeNotifier {
|
|||||||
_pinSetGeneral = pinSetGeneral,
|
_pinSetGeneral = pinSetGeneral,
|
||||||
_pinSetPersonalize = pinSetPersonalize,
|
_pinSetPersonalize = pinSetPersonalize,
|
||||||
_pinSetNotify = pinSetNotify,
|
_pinSetNotify = pinSetNotify,
|
||||||
_pinSetExtras = pinSetExtras;
|
_pinSetExtras = pinSetExtras,
|
||||||
|
_fontFamily = fontFamily;
|
||||||
|
|
||||||
factory SettingsProvider.fromMap(Map map,
|
factory SettingsProvider.fromMap(Map map,
|
||||||
{required DatabaseProvider database}) {
|
{required DatabaseProvider database}) {
|
||||||
@ -273,6 +276,7 @@ class SettingsProvider extends ChangeNotifier {
|
|||||||
pinSetPersonalize: map['personalize_s_pin'],
|
pinSetPersonalize: map['personalize_s_pin'],
|
||||||
pinSetNotify: map['notify_s_pin'],
|
pinSetNotify: map['notify_s_pin'],
|
||||||
pinSetExtras: map['extras_s_pin'],
|
pinSetExtras: map['extras_s_pin'],
|
||||||
|
fontFamily: map['font_family'],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -334,6 +338,7 @@ class SettingsProvider extends ChangeNotifier {
|
|||||||
"personalize_s_pin": _pinSetPersonalize,
|
"personalize_s_pin": _pinSetPersonalize,
|
||||||
"notify_s_pin": _pinSetNotify,
|
"notify_s_pin": _pinSetNotify,
|
||||||
"extras_s_pin": _pinSetExtras,
|
"extras_s_pin": _pinSetExtras,
|
||||||
|
"font_family": _fontFamily,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -399,6 +404,7 @@ class SettingsProvider extends ChangeNotifier {
|
|||||||
pinSetPersonalize: '',
|
pinSetPersonalize: '',
|
||||||
pinSetNotify: '',
|
pinSetNotify: '',
|
||||||
pinSetExtras: '',
|
pinSetExtras: '',
|
||||||
|
fontFamily: '',
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -455,6 +461,7 @@ class SettingsProvider extends ChangeNotifier {
|
|||||||
String get currentThemeDisplayName => _currentThemeDisplayName;
|
String get currentThemeDisplayName => _currentThemeDisplayName;
|
||||||
String get currentThemeCreator => _currentThemeCreator;
|
String get currentThemeCreator => _currentThemeCreator;
|
||||||
bool get showBreaks => _showBreaks;
|
bool get showBreaks => _showBreaks;
|
||||||
|
String get fontFamily => _fontFamily;
|
||||||
|
|
||||||
Future<void> update({
|
Future<void> update({
|
||||||
bool store = true,
|
bool store = true,
|
||||||
@ -507,6 +514,7 @@ class SettingsProvider extends ChangeNotifier {
|
|||||||
String? currentThemeDisplayName,
|
String? currentThemeDisplayName,
|
||||||
String? currentThemeCreator,
|
String? currentThemeCreator,
|
||||||
bool? showBreaks,
|
bool? showBreaks,
|
||||||
|
String? fontFamily,
|
||||||
}) async {
|
}) async {
|
||||||
if (language != null && language != _language) _language = language;
|
if (language != null && language != _language) _language = language;
|
||||||
if (startPage != null && startPage != _startPage) _startPage = startPage;
|
if (startPage != null && startPage != _startPage) _startPage = startPage;
|
||||||
@ -651,6 +659,9 @@ class SettingsProvider extends ChangeNotifier {
|
|||||||
if (showBreaks != null && showBreaks != _showBreaks) {
|
if (showBreaks != null && showBreaks != _showBreaks) {
|
||||||
_showBreaks = showBreaks;
|
_showBreaks = showBreaks;
|
||||||
}
|
}
|
||||||
|
if (fontFamily != null && fontFamily != _fontFamily) {
|
||||||
|
_fontFamily = fontFamily;
|
||||||
|
}
|
||||||
// store or not
|
// store or not
|
||||||
if (store) await _database?.store.storeSettings(this);
|
if (store) await _database?.store.storeSettings(this);
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
|
@ -5,28 +5,46 @@ import 'package:filcnaplo/theme/observer.dart';
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:material_color_utilities/material_color_utilities.dart';
|
import 'package:material_color_utilities/material_color_utilities.dart';
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
|
import 'package:google_fonts/google_fonts.dart';
|
||||||
|
|
||||||
class AppTheme {
|
class AppTheme {
|
||||||
// Dev note: All of these could be constant variables, but this is better for
|
// Dev note: All of these could be constant variables, but this is better for
|
||||||
// development (you don't have to hot-restart)
|
// development (you don't have to hot-restart)
|
||||||
|
|
||||||
static const String _fontFamily = "Montserrat";
|
static const String _defaultFontFamily = "Montserrat";
|
||||||
|
|
||||||
static Color? _paletteAccentLight(CorePalette? palette) => palette != null ? Color(palette.primary.get(70)) : null;
|
static Color? _paletteAccentLight(CorePalette? palette) =>
|
||||||
static Color? _paletteHighlightLight(CorePalette? palette) => palette != null ? Color(palette.neutral.get(100)) : null;
|
palette != null ? Color(palette.primary.get(70)) : null;
|
||||||
static Color? _paletteBackgroundLight(CorePalette? palette) => palette != null ? Color(palette.neutral.get(95)) : null;
|
static Color? _paletteHighlightLight(CorePalette? palette) =>
|
||||||
|
palette != null ? Color(palette.neutral.get(100)) : null;
|
||||||
|
static Color? _paletteBackgroundLight(CorePalette? palette) =>
|
||||||
|
palette != null ? Color(palette.neutral.get(95)) : null;
|
||||||
|
|
||||||
static Color? _paletteAccentDark(CorePalette? palette) => palette != null ? Color(palette.primary.get(80)) : null;
|
static Color? _paletteAccentDark(CorePalette? palette) =>
|
||||||
static Color? _paletteBackgroundDark(CorePalette? palette) => palette != null ? Color(palette.neutralVariant.get(10)) : null;
|
palette != null ? Color(palette.primary.get(80)) : null;
|
||||||
static Color? _paletteHighlightDark(CorePalette? palette) => palette != null ? Color(palette.neutralVariant.get(20)) : null;
|
static Color? _paletteBackgroundDark(CorePalette? palette) =>
|
||||||
|
palette != null ? Color(palette.neutralVariant.get(10)) : null;
|
||||||
|
static Color? _paletteHighlightDark(CorePalette? palette) =>
|
||||||
|
palette != null ? Color(palette.neutralVariant.get(20)) : null;
|
||||||
|
|
||||||
|
static Map<String, TextTheme?> googleFontsMap = {
|
||||||
|
"Merienda": GoogleFonts.meriendaTextTheme(),
|
||||||
|
"M PLUS Code Latin": GoogleFonts.mPlusCodeLatinTextTheme(),
|
||||||
|
"Figtree": GoogleFonts.figtreeTextTheme(),
|
||||||
|
"Fira Code": GoogleFonts.firaCodeTextTheme(),
|
||||||
|
"Vollkorn": GoogleFonts.vollkornTextTheme(),
|
||||||
|
};
|
||||||
|
|
||||||
// Light Theme
|
// Light Theme
|
||||||
static ThemeData lightTheme(BuildContext context, {CorePalette? palette}) {
|
static ThemeData lightTheme(BuildContext context, {CorePalette? palette}) {
|
||||||
var lightColors = AppColors.fromBrightness(Brightness.light);
|
var lightColors = AppColors.fromBrightness(Brightness.light);
|
||||||
final settings = Provider.of<SettingsProvider>(context, listen: false);
|
final settings = Provider.of<SettingsProvider>(context, listen: false);
|
||||||
AccentColor accentColor = settings.accentColor;
|
AccentColor accentColor = settings.accentColor;
|
||||||
final customAccentColor = accentColor == AccentColor.custom ? settings.customAccentColor : null;
|
final customAccentColor =
|
||||||
Color accent = customAccentColor ?? accentColorMap[accentColor] ?? const Color(0x00000000);
|
accentColor == AccentColor.custom ? settings.customAccentColor : null;
|
||||||
|
Color accent = customAccentColor ??
|
||||||
|
accentColorMap[accentColor] ??
|
||||||
|
const Color(0x00000000);
|
||||||
|
|
||||||
if (accentColor == AccentColor.adaptive) {
|
if (accentColor == AccentColor.adaptive) {
|
||||||
if (palette != null) accent = _paletteAccentLight(palette)!;
|
if (palette != null) accent = _paletteAccentLight(palette)!;
|
||||||
@ -34,23 +52,32 @@ class AppTheme {
|
|||||||
palette = null;
|
palette = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
Color backgroundColor =
|
Color backgroundColor = (accentColor == AccentColor.custom
|
||||||
(accentColor == AccentColor.custom ? settings.customBackgroundColor : _paletteBackgroundLight(palette)) ?? lightColors.background;
|
? settings.customBackgroundColor
|
||||||
Color highlightColor =
|
: _paletteBackgroundLight(palette)) ??
|
||||||
(accentColor == AccentColor.custom ? settings.customHighlightColor : _paletteHighlightLight(palette)) ?? lightColors.highlight;
|
lightColors.background;
|
||||||
|
Color highlightColor = (accentColor == AccentColor.custom
|
||||||
|
? settings.customHighlightColor
|
||||||
|
: _paletteHighlightLight(palette)) ??
|
||||||
|
lightColors.highlight;
|
||||||
|
|
||||||
return ThemeData(
|
return ThemeData(
|
||||||
brightness: Brightness.light,
|
brightness: Brightness.light,
|
||||||
useMaterial3: true,
|
useMaterial3: true,
|
||||||
fontFamily: _fontFamily,
|
fontFamily: _defaultFontFamily,
|
||||||
|
textTheme: googleFontsMap[settings.fontFamily],
|
||||||
scaffoldBackgroundColor: backgroundColor,
|
scaffoldBackgroundColor: backgroundColor,
|
||||||
primaryColor: lightColors.filc,
|
primaryColor: lightColors.filc,
|
||||||
dividerColor: const Color(0x00000000),
|
dividerColor: const Color(0x00000000),
|
||||||
colorScheme: ColorScheme(
|
colorScheme: ColorScheme(
|
||||||
primary: accent,
|
primary: accent,
|
||||||
onPrimary: (accent.computeLuminance() > 0.5 ? Colors.black : Colors.white).withOpacity(.9),
|
onPrimary:
|
||||||
|
(accent.computeLuminance() > 0.5 ? Colors.black : Colors.white)
|
||||||
|
.withOpacity(.9),
|
||||||
secondary: accent,
|
secondary: accent,
|
||||||
onSecondary: (accent.computeLuminance() > 0.5 ? Colors.black : Colors.white).withOpacity(.9),
|
onSecondary:
|
||||||
|
(accent.computeLuminance() > 0.5 ? Colors.black : Colors.white)
|
||||||
|
.withOpacity(.9),
|
||||||
background: highlightColor,
|
background: highlightColor,
|
||||||
onBackground: Colors.black.withOpacity(.9),
|
onBackground: Colors.black.withOpacity(.9),
|
||||||
brightness: Brightness.light,
|
brightness: Brightness.light,
|
||||||
@ -64,8 +91,10 @@ class AppTheme {
|
|||||||
indicatorColor: accent,
|
indicatorColor: accent,
|
||||||
iconTheme: IconThemeData(color: lightColors.text.withOpacity(.75)),
|
iconTheme: IconThemeData(color: lightColors.text.withOpacity(.75)),
|
||||||
navigationBarTheme: NavigationBarThemeData(
|
navigationBarTheme: NavigationBarThemeData(
|
||||||
indicatorColor: accent.withOpacity(accentColor == AccentColor.adaptive ? 0.4 : 0.8),
|
indicatorColor:
|
||||||
iconTheme: MaterialStateProperty.all(IconThemeData(color: lightColors.text)),
|
accent.withOpacity(accentColor == AccentColor.adaptive ? 0.4 : 0.8),
|
||||||
|
iconTheme:
|
||||||
|
MaterialStateProperty.all(IconThemeData(color: lightColors.text)),
|
||||||
backgroundColor: highlightColor,
|
backgroundColor: highlightColor,
|
||||||
labelTextStyle: MaterialStateProperty.all(TextStyle(
|
labelTextStyle: MaterialStateProperty.all(TextStyle(
|
||||||
fontSize: 13.0,
|
fontSize: 13.0,
|
||||||
@ -82,7 +111,10 @@ class AppTheme {
|
|||||||
expansionTileTheme: ExpansionTileThemeData(iconColor: accent),
|
expansionTileTheme: ExpansionTileThemeData(iconColor: accent),
|
||||||
cardColor: highlightColor,
|
cardColor: highlightColor,
|
||||||
bottomNavigationBarTheme: BottomNavigationBarThemeData(
|
bottomNavigationBarTheme: BottomNavigationBarThemeData(
|
||||||
backgroundColor: Provider.of<ThemeModeObserver>(context, listen: false).updateNavbarColor ? backgroundColor : null,
|
backgroundColor: Provider.of<ThemeModeObserver>(context, listen: false)
|
||||||
|
.updateNavbarColor
|
||||||
|
? backgroundColor
|
||||||
|
: null,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -92,8 +124,11 @@ class AppTheme {
|
|||||||
var darkColors = AppColors.fromBrightness(Brightness.dark);
|
var darkColors = AppColors.fromBrightness(Brightness.dark);
|
||||||
final settings = Provider.of<SettingsProvider>(context, listen: false);
|
final settings = Provider.of<SettingsProvider>(context, listen: false);
|
||||||
AccentColor accentColor = settings.accentColor;
|
AccentColor accentColor = settings.accentColor;
|
||||||
final customAccentColor = accentColor == AccentColor.custom ? settings.customAccentColor : null;
|
final customAccentColor =
|
||||||
Color accent = customAccentColor ?? accentColorMap[accentColor] ?? const Color(0x00000000);
|
accentColor == AccentColor.custom ? settings.customAccentColor : null;
|
||||||
|
Color accent = customAccentColor ??
|
||||||
|
accentColorMap[accentColor] ??
|
||||||
|
const Color(0x00000000);
|
||||||
|
|
||||||
if (accentColor == AccentColor.adaptive) {
|
if (accentColor == AccentColor.adaptive) {
|
||||||
if (palette != null) accent = _paletteAccentDark(palette)!;
|
if (palette != null) accent = _paletteAccentDark(palette)!;
|
||||||
@ -101,23 +136,32 @@ class AppTheme {
|
|||||||
palette = null;
|
palette = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
Color backgroundColor =
|
Color backgroundColor = (accentColor == AccentColor.custom
|
||||||
(accentColor == AccentColor.custom ? settings.customBackgroundColor : _paletteBackgroundDark(palette)) ?? darkColors.background;
|
? settings.customBackgroundColor
|
||||||
Color highlightColor =
|
: _paletteBackgroundDark(palette)) ??
|
||||||
(accentColor == AccentColor.custom ? settings.customHighlightColor : _paletteHighlightDark(palette)) ?? darkColors.highlight;
|
darkColors.background;
|
||||||
|
Color highlightColor = (accentColor == AccentColor.custom
|
||||||
|
? settings.customHighlightColor
|
||||||
|
: _paletteHighlightDark(palette)) ??
|
||||||
|
darkColors.highlight;
|
||||||
|
|
||||||
return ThemeData(
|
return ThemeData(
|
||||||
brightness: Brightness.dark,
|
brightness: Brightness.dark,
|
||||||
useMaterial3: true,
|
useMaterial3: true,
|
||||||
fontFamily: _fontFamily,
|
fontFamily: _defaultFontFamily,
|
||||||
|
textTheme: googleFontsMap[settings.fontFamily],
|
||||||
scaffoldBackgroundColor: backgroundColor,
|
scaffoldBackgroundColor: backgroundColor,
|
||||||
primaryColor: darkColors.filc,
|
primaryColor: darkColors.filc,
|
||||||
dividerColor: const Color(0x00000000),
|
dividerColor: const Color(0x00000000),
|
||||||
colorScheme: ColorScheme(
|
colorScheme: ColorScheme(
|
||||||
primary: accent,
|
primary: accent,
|
||||||
onPrimary: (accent.computeLuminance() > 0.5 ? Colors.black : Colors.white).withOpacity(.9),
|
onPrimary:
|
||||||
|
(accent.computeLuminance() > 0.5 ? Colors.black : Colors.white)
|
||||||
|
.withOpacity(.9),
|
||||||
secondary: accent,
|
secondary: accent,
|
||||||
onSecondary: (accent.computeLuminance() > 0.5 ? Colors.black : Colors.white).withOpacity(.9),
|
onSecondary:
|
||||||
|
(accent.computeLuminance() > 0.5 ? Colors.black : Colors.white)
|
||||||
|
.withOpacity(.9),
|
||||||
background: highlightColor,
|
background: highlightColor,
|
||||||
onBackground: Colors.white.withOpacity(.9),
|
onBackground: Colors.white.withOpacity(.9),
|
||||||
brightness: Brightness.dark,
|
brightness: Brightness.dark,
|
||||||
@ -131,8 +175,10 @@ class AppTheme {
|
|||||||
indicatorColor: accent,
|
indicatorColor: accent,
|
||||||
iconTheme: IconThemeData(color: darkColors.text.withOpacity(.75)),
|
iconTheme: IconThemeData(color: darkColors.text.withOpacity(.75)),
|
||||||
navigationBarTheme: NavigationBarThemeData(
|
navigationBarTheme: NavigationBarThemeData(
|
||||||
indicatorColor: accent.withOpacity(accentColor == AccentColor.adaptive ? 0.4 : 0.8),
|
indicatorColor:
|
||||||
iconTheme: MaterialStateProperty.all(IconThemeData(color: darkColors.text)),
|
accent.withOpacity(accentColor == AccentColor.adaptive ? 0.4 : 0.8),
|
||||||
|
iconTheme:
|
||||||
|
MaterialStateProperty.all(IconThemeData(color: darkColors.text)),
|
||||||
backgroundColor: highlightColor,
|
backgroundColor: highlightColor,
|
||||||
labelTextStyle: MaterialStateProperty.all(TextStyle(
|
labelTextStyle: MaterialStateProperty.all(TextStyle(
|
||||||
fontSize: 13.0,
|
fontSize: 13.0,
|
||||||
@ -153,7 +199,10 @@ class AppTheme {
|
|||||||
elevation: 1,
|
elevation: 1,
|
||||||
),
|
),
|
||||||
bottomNavigationBarTheme: BottomNavigationBarThemeData(
|
bottomNavigationBarTheme: BottomNavigationBarThemeData(
|
||||||
backgroundColor: Provider.of<ThemeModeObserver>(context, listen: false).updateNavbarColor ? backgroundColor : null,
|
backgroundColor: Provider.of<ThemeModeObserver>(context, listen: false)
|
||||||
|
.updateNavbarColor
|
||||||
|
? backgroundColor
|
||||||
|
: null,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -76,6 +76,7 @@ dependencies:
|
|||||||
google_sign_in: ^6.2.1
|
google_sign_in: ^6.2.1
|
||||||
extension_google_sign_in_as_googleapis_auth: ^2.0.12
|
extension_google_sign_in_as_googleapis_auth: ^2.0.12
|
||||||
maps_launcher: ^2.2.0
|
maps_launcher: ^2.2.0
|
||||||
|
google_fonts: ^4.0.4
|
||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
flutter_lints: ^3.0.1
|
flutter_lints: ^3.0.1
|
||||||
|
Loading…
x
Reference in New Issue
Block a user