2023-01-29 16:57:47 +00:00
|
|
|
import 'dart:io';
|
|
|
|
|
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';
|
2023-01-29 16:57:47 +00:00
|
|
|
import 'package:light_sensor/light_sensor.dart';
|
2023-02-11 12:58:47 +00:00
|
|
|
import 'package:lightmeter/data/caffeine_service.dart';
|
2023-01-21 10:37:49 +00:00
|
|
|
import 'package:lightmeter/data/haptics_service.dart';
|
2022-12-15 11:00:28 +00:00
|
|
|
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
|
|
|
|
2023-01-29 16:57:47 +00:00
|
|
|
import 'data/light_sensor_service.dart';
|
2022-12-18 09:03:41 +00:00
|
|
|
import 'data/permissions_service.dart';
|
2022-12-16 08:08:12 +00:00
|
|
|
import 'data/shared_prefs_service.dart';
|
2023-01-25 10:08:11 +00:00
|
|
|
import 'environment.dart';
|
2022-12-15 11:00:28 +00:00
|
|
|
import 'generated/l10n.dart';
|
2023-01-29 16:57:47 +00:00
|
|
|
import 'providers/ev_source_type_provider.dart';
|
2023-01-29 17:02:18 +00:00
|
|
|
import 'providers/theme_provider.dart';
|
2022-12-15 11:00:28 +00:00
|
|
|
import 'screens/metering/flow_metering.dart';
|
2023-01-26 09:10:23 +00:00
|
|
|
import 'screens/settings/flow_settings.dart';
|
2022-12-15 11:00:28 +00:00
|
|
|
import 'utils/stop_type_provider.dart';
|
|
|
|
|
2023-01-07 09:14:18 +00:00
|
|
|
class Application extends StatelessWidget {
|
2023-01-25 10:08:11 +00:00
|
|
|
final Environment env;
|
2022-12-15 11:00:28 +00:00
|
|
|
|
2023-01-25 10:08:11 +00:00
|
|
|
const Application(this.env, {super.key});
|
2022-12-15 11:00:28 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2023-01-29 16:57:47 +00:00
|
|
|
return FutureBuilder(
|
|
|
|
future: Future.wait([
|
|
|
|
SharedPreferences.getInstance(),
|
|
|
|
Platform.isAndroid ? LightSensor.hasSensor : Future.value(false),
|
|
|
|
]),
|
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: [
|
2023-01-29 16:57:47 +00:00
|
|
|
Provider.value(value: env.copyWith(hasLightSensor: snapshot.data![1] as bool)),
|
|
|
|
Provider(create: (_) => UserPreferencesService(snapshot.data![0] as SharedPreferences)),
|
2023-02-11 12:58:47 +00:00
|
|
|
Provider(create: (_) => const CaffeineService()),
|
2023-01-22 19:30:29 +00:00
|
|
|
Provider(create: (_) => const HapticsService()),
|
|
|
|
Provider(create: (_) => PermissionsService()),
|
2023-01-29 16:57:47 +00:00
|
|
|
Provider(create: (_) => const LightSensorService()),
|
2022-12-15 11:00:28 +00:00
|
|
|
],
|
2023-01-22 19:30:29 +00:00
|
|
|
child: StopTypeProvider(
|
2023-01-29 16:57:47 +00:00
|
|
|
child: EvSourceTypeProvider(
|
|
|
|
child: ThemeProvider(
|
|
|
|
builder: (context, _) {
|
|
|
|
final systemIconsBrightness = ThemeData.estimateBrightnessForColor(
|
|
|
|
context.watch<ThemeData>().colorScheme.onSurface,
|
|
|
|
);
|
|
|
|
return AnnotatedRegion(
|
|
|
|
value: SystemUiOverlayStyle(
|
|
|
|
statusBarColor: Colors.transparent,
|
|
|
|
statusBarBrightness: systemIconsBrightness == Brightness.light
|
|
|
|
? Brightness.dark
|
|
|
|
: Brightness.light,
|
|
|
|
statusBarIconBrightness: systemIconsBrightness,
|
|
|
|
systemNavigationBarColor: context.watch<ThemeData>().colorScheme.surface,
|
|
|
|
systemNavigationBarIconBrightness: systemIconsBrightness,
|
|
|
|
),
|
|
|
|
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 SettingsFlow(),
|
|
|
|
},
|
2023-01-07 09:14:18 +00:00
|
|
|
),
|
2023-01-29 16:57:47 +00:00
|
|
|
);
|
|
|
|
},
|
|
|
|
),
|
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
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|