68 lines
2.5 KiB
Dart
68 lines
2.5 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
import 'package:pdf_signature/l10n/app_localizations.dart';
|
|
import 'package:pdf_signature/ui/features/pdf/widgets/pdf_screen.dart';
|
|
import 'ui/features/preferences/providers.dart';
|
|
|
|
class MyApp extends StatelessWidget {
|
|
const MyApp({super.key});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return ProviderScope(
|
|
child: Consumer(
|
|
builder: (context, ref, _) {
|
|
// Ensure SharedPreferences loaded before building MaterialApp
|
|
final sp = ref.watch(sharedPreferencesProvider);
|
|
return sp.when(
|
|
loading: () => const SizedBox.shrink(),
|
|
error:
|
|
(e, st) => MaterialApp(
|
|
onGenerateTitle: (ctx) => AppLocalizations.of(ctx).appTitle,
|
|
supportedLocales: AppLocalizations.supportedLocales,
|
|
localizationsDelegates:
|
|
AppLocalizations.localizationsDelegates,
|
|
home: Builder(
|
|
builder:
|
|
(ctx) => Scaffold(
|
|
body: Center(
|
|
child: Text(
|
|
AppLocalizations.of(
|
|
ctx,
|
|
).errorWithMessage(e.toString()),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
data: (_) {
|
|
final themeMode = ref.watch(themeModeProvider);
|
|
final appLocale = ref.watch(localeProvider);
|
|
return MaterialApp(
|
|
onGenerateTitle: (ctx) => AppLocalizations.of(ctx).appTitle,
|
|
theme: ThemeData(
|
|
colorScheme: ColorScheme.fromSeed(
|
|
seedColor: Colors.indigo,
|
|
brightness: Brightness.light,
|
|
),
|
|
),
|
|
darkTheme: ThemeData(
|
|
colorScheme: ColorScheme.fromSeed(
|
|
seedColor: Colors.indigo,
|
|
brightness: Brightness.dark,
|
|
),
|
|
),
|
|
themeMode: themeMode,
|
|
locale: appLocale,
|
|
supportedLocales: AppLocalizations.supportedLocales,
|
|
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
|
home: const PdfSignatureHomePage(),
|
|
);
|
|
},
|
|
);
|
|
},
|
|
),
|
|
);
|
|
}
|
|
}
|