53 lines
1.6 KiB
Dart
53 lines
1.6 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
|
|
|
import 'screens/home_screen.dart';
|
|
import 'services/last_location.dart';
|
|
import 'services/tracker_storage.dart';
|
|
import 'widgets/theme.dart';
|
|
|
|
Future<void> main() async {
|
|
WidgetsFlutterBinding.ensureInitialized();
|
|
final SharedPreferences prefs = await SharedPreferences.getInstance();
|
|
// Load the last location synchronously before the root navigator can fire
|
|
// its initial didPush and clear the saved value.
|
|
final LastLocation? pending = LastLocationService(prefs).load();
|
|
runApp(
|
|
ProviderScope(
|
|
overrides: <Override>[
|
|
sharedPreferencesProvider.overrideWithValue(prefs),
|
|
pendingRestoreProvider.overrideWithValue(pending),
|
|
],
|
|
child: const BibleTrackerApp(),
|
|
),
|
|
);
|
|
}
|
|
|
|
class BibleTrackerApp extends ConsumerStatefulWidget {
|
|
const BibleTrackerApp({super.key});
|
|
|
|
@override
|
|
ConsumerState<BibleTrackerApp> createState() => _BibleTrackerAppState();
|
|
}
|
|
|
|
class _BibleTrackerAppState extends ConsumerState<BibleTrackerApp> {
|
|
late final LastLocationObserver _observer = LastLocationObserver((
|
|
LastLocation? location,
|
|
) async {
|
|
await ref.read(lastLocationServiceProvider).save(location);
|
|
});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return MaterialApp(
|
|
title: 'My Bible Tracker',
|
|
debugShowCheckedModeBanner: false,
|
|
theme: AppTheme.light(),
|
|
darkTheme: AppTheme.dark(),
|
|
themeMode: ThemeMode.system,
|
|
home: const HomeScreen(),
|
|
navigatorObservers: <NavigatorObserver>[_observer],
|
|
);
|
|
}
|
|
}
|