MO-Fuel-Tax-Back/lib/main.dart

74 lines
2 KiB
Dart

import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'screens/main_shell.dart';
import 'services/app_state.dart';
import 'theme/app_theme.dart';
void main() {
runApp(const FuelTaxTrackerApp());
}
class FuelTaxTrackerApp extends StatelessWidget {
const FuelTaxTrackerApp({super.key});
@override
Widget build(BuildContext context) {
return ChangeNotifierProvider(
create: (_) => AppState()..init(),
child: Consumer<AppState>(
builder: (context, appState, _) => MaterialApp(
title: 'Fuel Tax Tracker',
theme: AppTheme.light,
darkTheme: AppTheme.dark,
themeMode: appState.themeMode,
home: const AppRoot(),
),
),
);
}
}
class AppRoot extends StatelessWidget {
const AppRoot({super.key});
@override
Widget build(BuildContext context) {
return Consumer<AppState>(
builder: (context, appState, _) {
if (appState.isLoading) {
return const Scaffold(
body: Center(child: CircularProgressIndicator()),
);
}
if (appState.initError != null) {
return Scaffold(
body: Center(
child: Padding(
padding: const EdgeInsets.all(24),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Icon(Icons.error_outline,
size: 48, color: Theme.of(context).colorScheme.error),
const SizedBox(height: 16),
Text(
'Could not start the app:\n${appState.initError}',
textAlign: TextAlign.center,
),
const SizedBox(height: 16),
FilledButton(
onPressed: () => appState.init(),
child: const Text('Retry'),
),
],
),
),
),
);
}
return const MainShell();
},
);
}
}