m3_lightmeter/lib/application.dart

74 lines
2.7 KiB
Dart
Raw Permalink Normal View History

2022-12-15 11:00:28 +00:00
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:provider/provider.dart';
2022-12-16 08:08:12 +00:00
import 'package:shared_preferences/shared_preferences.dart';
2022-12-15 11:00:28 +00:00
import 'data/models/ev_source_type.dart';
import 'data/permissions_service.dart';
2022-12-16 08:08:12 +00:00
import 'data/shared_prefs_service.dart';
2022-12-15 11:00:28 +00:00
import 'generated/l10n.dart';
import 'res/theme.dart';
import 'screens/metering/flow_metering.dart';
import 'screens/settings/screen_settings.dart';
2022-12-15 11:00:28 +00:00
import 'utils/stop_type_provider.dart';
final RouteObserver<PageRoute> routeObserver = RouteObserver<PageRoute>();
2023-01-07 09:14:18 +00:00
class Application extends StatelessWidget {
2022-12-15 11:00:28 +00:00
final EvSourceType evSource;
const Application(this.evSource, {super.key});
@override
Widget build(BuildContext context) {
2022-12-16 08:08:12 +00:00
return FutureBuilder<SharedPreferences>(
future: SharedPreferences.getInstance(),
2023-01-07 09:14:18 +00:00
builder: (_, snapshot) {
2022-12-16 08:08:12 +00:00
if (snapshot.data != null) {
return MultiProvider(
providers: [
Provider(create: (_) => UserPreferencesService(snapshot.data!)),
2023-01-07 09:14:18 +00:00
Provider.value(value: evSource),
2022-12-15 11:00:28 +00:00
],
2022-12-16 08:08:12 +00:00
child: Provider(
2023-01-07 09:14:18 +00:00
create: (_) => PermissionsService(),
2022-12-16 08:08:12 +00:00
child: StopTypeProvider(
child: ThemeProvider(
initialPrimaryColor: const Color(0xFF2196f3),
2023-01-07 09:14:18 +00:00
builder: (context, child) => AnnotatedRegion(
value: SystemUiOverlayStyle(
statusBarColor: context.watch<ThemeData>().colorScheme.surface,
systemNavigationBarColor: context.watch<ThemeData>().colorScheme.surface,
),
child: MaterialApp(
theme: context.watch<ThemeData>(),
localizationsDelegates: const [
S.delegate,
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
],
supportedLocales: S.delegate.supportedLocales,
builder: (context, child) => MediaQuery(
data: MediaQuery.of(context).copyWith(textScaleFactor: 1.0),
child: child!,
),
initialRoute: "metering",
routes: {
"metering": (context) => const MeteringFlow(),
"settings": (context) => const SettingsScreen(),
},
),
2022-12-16 08:08:12 +00:00
),
),
),
2022-12-15 11:00:28 +00:00
),
2022-12-16 08:08:12 +00:00
);
}
return const SizedBox();
},
2022-12-15 11:00:28 +00:00
);
}
}