mirror of
https://github.com/immich-app/immich.git
synced 2024-12-28 06:31:58 +00:00
feat(mobile): exclude locales from overpass font (#14158)
* feat(mobile): create localeProvider This provider can be used to refresh providers that provide UI elements and get cached. * feat(mobile): use default font for locales not supported by Overpass * chore(mobile): fix test * refactor(mobile): use Locale instead of String
This commit is contained in:
parent
b031a8cac1
commit
bcd17c2ebe
6 changed files with 60 additions and 21 deletions
|
@ -48,3 +48,8 @@ const Map<String, Locale> locales = {
|
|||
};
|
||||
|
||||
const String translationsPath = 'assets/i18n';
|
||||
|
||||
const List<Locale> localesNotSupportedByOverpass = [
|
||||
Locale('el', 'GR'),
|
||||
Locale('sr', 'Cyrl'),
|
||||
];
|
||||
|
|
|
@ -10,6 +10,7 @@ import 'package:flutter/services.dart';
|
|||
import 'package:flutter_displaymode/flutter_displaymode.dart';
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
import 'package:immich_mobile/extensions/build_context_extensions.dart';
|
||||
import 'package:immich_mobile/providers/locale_provider.dart';
|
||||
import 'package:immich_mobile/utils/download.dart';
|
||||
import 'package:intl/date_symbol_data_local.dart';
|
||||
import 'package:timezone/data/latest.dart';
|
||||
|
@ -212,20 +213,31 @@ class ImmichAppState extends ConsumerState<ImmichApp>
|
|||
final router = ref.watch(appRouterProvider);
|
||||
final immichTheme = ref.watch(immichThemeProvider);
|
||||
|
||||
return MaterialApp(
|
||||
localizationsDelegates: context.localizationDelegates,
|
||||
supportedLocales: context.supportedLocales,
|
||||
locale: context.locale,
|
||||
debugShowCheckedModeBanner: true,
|
||||
home: MaterialApp.router(
|
||||
title: 'Immich',
|
||||
debugShowCheckedModeBanner: false,
|
||||
themeMode: ref.watch(immichThemeModeProvider),
|
||||
darkTheme: getThemeData(colorScheme: immichTheme.dark),
|
||||
theme: getThemeData(colorScheme: immichTheme.light),
|
||||
routeInformationParser: router.defaultRouteParser(),
|
||||
routerDelegate: router.delegate(
|
||||
navigatorObservers: () => [TabNavigationObserver(ref: ref)],
|
||||
return ProviderScope(
|
||||
overrides: [
|
||||
localeProvider.overrideWithValue(context.locale),
|
||||
],
|
||||
child: MaterialApp(
|
||||
localizationsDelegates: context.localizationDelegates,
|
||||
supportedLocales: context.supportedLocales,
|
||||
locale: context.locale,
|
||||
debugShowCheckedModeBanner: true,
|
||||
home: MaterialApp.router(
|
||||
title: 'Immich',
|
||||
debugShowCheckedModeBanner: false,
|
||||
themeMode: ref.watch(immichThemeModeProvider),
|
||||
darkTheme: getThemeData(
|
||||
colorScheme: immichTheme.dark,
|
||||
locale: context.locale,
|
||||
),
|
||||
theme: getThemeData(
|
||||
colorScheme: immichTheme.light,
|
||||
locale: context.locale,
|
||||
),
|
||||
routeInformationParser: router.defaultRouteParser(),
|
||||
routerDelegate: router.delegate(
|
||||
navigatorObservers: () => [TabNavigationObserver(ref: ref)],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
|
4
mobile/lib/providers/locale_provider.dart
Normal file
4
mobile/lib/providers/locale_provider.dart
Normal file
|
@ -0,0 +1,4 @@
|
|||
import 'package:flutter/widgets.dart';
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
|
||||
final localeProvider = Provider<Locale>((_) => throw UnimplementedError());
|
|
@ -2,6 +2,7 @@ import 'package:dynamic_color/dynamic_color.dart';
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
import 'package:immich_mobile/constants/immich_colors.dart';
|
||||
import 'package:immich_mobile/constants/locales.dart';
|
||||
import 'package:immich_mobile/extensions/theme_extensions.dart';
|
||||
import 'package:immich_mobile/providers/app_settings.provider.dart';
|
||||
import 'package:immich_mobile/services/app_settings.service.dart';
|
||||
|
@ -145,7 +146,18 @@ ImmichTheme _decolorizeSurfaces({
|
|||
);
|
||||
}
|
||||
|
||||
ThemeData getThemeData({required ColorScheme colorScheme}) {
|
||||
String? getFontFamilyFromLocale(Locale locale) {
|
||||
if (localesNotSupportedByOverpass.contains(locale)) {
|
||||
// Let Flutter use the default font
|
||||
return null;
|
||||
}
|
||||
return 'Overpass';
|
||||
}
|
||||
|
||||
ThemeData getThemeData({
|
||||
required ColorScheme colorScheme,
|
||||
required Locale locale,
|
||||
}) {
|
||||
var isDark = colorScheme.brightness == Brightness.dark;
|
||||
var primaryColor = colorScheme.primary;
|
||||
|
||||
|
@ -163,10 +175,10 @@ ThemeData getThemeData({required ColorScheme colorScheme}) {
|
|||
bottomSheetTheme: BottomSheetThemeData(
|
||||
backgroundColor: colorScheme.surfaceContainer,
|
||||
),
|
||||
fontFamily: 'Overpass',
|
||||
fontFamily: getFontFamilyFromLocale(locale),
|
||||
snackBarTheme: SnackBarThemeData(
|
||||
contentTextStyle: TextStyle(
|
||||
fontFamily: 'Overpass',
|
||||
fontFamily: getFontFamilyFromLocale(locale),
|
||||
color: primaryColor,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
|
@ -175,7 +187,7 @@ ThemeData getThemeData({required ColorScheme colorScheme}) {
|
|||
appBarTheme: AppBarTheme(
|
||||
titleTextStyle: TextStyle(
|
||||
color: primaryColor,
|
||||
fontFamily: 'Overpass',
|
||||
fontFamily: getFontFamilyFromLocale(locale),
|
||||
fontWeight: FontWeight.bold,
|
||||
fontSize: 18,
|
||||
),
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_hooks/flutter_hooks.dart';
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
import 'package:immich_mobile/providers/locale_provider.dart';
|
||||
import 'package:immich_mobile/providers/map/map_state.provider.dart';
|
||||
import 'package:immich_mobile/utils/immich_app_theme.dart';
|
||||
|
||||
|
@ -71,6 +72,7 @@ class _MapThemeOverideState extends ConsumerState<MapThemeOveride>
|
|||
_theme = widget.themeMode ??
|
||||
ref.watch(mapStateNotifierProvider.select((v) => v.themeMode));
|
||||
var appTheme = ref.watch(immichThemeProvider);
|
||||
final locale = ref.watch(localeProvider);
|
||||
|
||||
useValueChanged<ThemeMode, void>(_theme, (_, __) {
|
||||
if (_theme == ThemeMode.system) {
|
||||
|
@ -85,8 +87,8 @@ class _MapThemeOverideState extends ConsumerState<MapThemeOveride>
|
|||
|
||||
return Theme(
|
||||
data: _isDarkTheme
|
||||
? getThemeData(colorScheme: appTheme.dark)
|
||||
: getThemeData(colorScheme: appTheme.light),
|
||||
? getThemeData(colorScheme: appTheme.dark, locale: locale)
|
||||
: getThemeData(colorScheme: appTheme.light, locale: locale),
|
||||
child: widget.mapBuilder.call(
|
||||
ref.watch(
|
||||
mapStateNotifierProvider.select(
|
||||
|
|
|
@ -5,6 +5,7 @@ import 'package:flutter/material.dart';
|
|||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
import 'package:immich_mobile/models/map/map_state.model.dart';
|
||||
import 'package:immich_mobile/providers/locale_provider.dart';
|
||||
import 'package:immich_mobile/providers/map/map_state.provider.dart';
|
||||
import 'package:immich_mobile/widgets/map/map_theme_override.dart';
|
||||
|
||||
|
@ -24,7 +25,10 @@ void main() {
|
|||
setUp(() {
|
||||
mapState = MapState(themeMode: ThemeMode.dark);
|
||||
mapStateNotifier = MockMapStateNotifier(mapState);
|
||||
overrides = [mapStateNotifierProvider.overrideWith(() => mapStateNotifier)];
|
||||
overrides = [
|
||||
mapStateNotifierProvider.overrideWith(() => mapStateNotifier),
|
||||
localeProvider.overrideWithValue(Locale("en")),
|
||||
];
|
||||
});
|
||||
|
||||
testWidgets("Return dark theme style when theme mode is dark",
|
||||
|
|
Loading…
Reference in a new issue