mirror of
https://github.com/zarzet/SpotiFLAC-Mobile.git
synced 2026-04-01 01:20:21 +02:00
- Add locale field to AppSettings model with 'system' default - Add Language section in Appearance settings page - Support System Default, English, and Indonesian options - App language changes take effect immediately - Add localization strings for language selector
69 lines
2.3 KiB
Dart
69 lines
2.3 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
import 'package:flutter_localizations/flutter_localizations.dart';
|
|
import 'package:go_router/go_router.dart';
|
|
import 'package:spotiflac_android/screens/main_shell.dart';
|
|
import 'package:spotiflac_android/screens/setup_screen.dart';
|
|
import 'package:spotiflac_android/providers/settings_provider.dart';
|
|
import 'package:spotiflac_android/theme/dynamic_color_wrapper.dart';
|
|
import 'package:spotiflac_android/l10n/app_localizations.dart';
|
|
|
|
final _routerProvider = Provider<GoRouter>((ref) {
|
|
// Only watch isFirstLaunch to prevent router rebuild on other settings changes
|
|
final isFirstLaunch = ref.watch(settingsProvider.select((s) => s.isFirstLaunch));
|
|
|
|
return GoRouter(
|
|
initialLocation: isFirstLaunch ? '/setup' : '/',
|
|
routes: [
|
|
GoRoute(
|
|
path: '/',
|
|
builder: (context, state) => const MainShell(),
|
|
),
|
|
GoRoute(
|
|
path: '/setup',
|
|
builder: (context, state) => const SetupScreen(),
|
|
),
|
|
],
|
|
);
|
|
});
|
|
|
|
class SpotiFLACApp extends ConsumerWidget {
|
|
const SpotiFLACApp({super.key});
|
|
|
|
@override
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
|
final router = ref.watch(_routerProvider);
|
|
final localeString = ref.watch(settingsProvider.select((s) => s.locale));
|
|
|
|
// Convert locale string to Locale object
|
|
Locale? locale;
|
|
if (localeString != 'system') {
|
|
locale = Locale(localeString);
|
|
}
|
|
|
|
return DynamicColorWrapper(
|
|
builder: (lightTheme, darkTheme, themeMode) {
|
|
return MaterialApp.router(
|
|
title: 'SpotiFLAC',
|
|
debugShowCheckedModeBanner: false,
|
|
theme: lightTheme,
|
|
darkTheme: darkTheme,
|
|
themeMode: themeMode,
|
|
themeAnimationDuration: const Duration(milliseconds: 300),
|
|
themeAnimationCurve: Curves.easeInOut,
|
|
routerConfig: router,
|
|
// Localization
|
|
locale: locale, // null = follow system
|
|
localizationsDelegates: const [
|
|
AppLocalizations.delegate,
|
|
GlobalMaterialLocalizations.delegate,
|
|
GlobalWidgetsLocalizations.delegate,
|
|
GlobalCupertinoLocalizations.delegate,
|
|
],
|
|
supportedLocales: AppLocalizations.supportedLocales,
|
|
);
|
|
},
|
|
);
|
|
}
|
|
}
|