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-08-14 10:25:37 +00:00
|
|
|
import 'package:lightmeter/data/caffeine_service.dart';
|
|
|
|
import 'package:lightmeter/data/haptics_service.dart';
|
|
|
|
import 'package:lightmeter/data/light_sensor_service.dart';
|
2023-02-11 19:19:18 +00:00
|
|
|
import 'package:lightmeter/data/models/supported_locale.dart';
|
2023-08-14 10:25:37 +00:00
|
|
|
import 'package:lightmeter/data/permissions_service.dart';
|
|
|
|
import 'package:lightmeter/data/shared_prefs_service.dart';
|
|
|
|
import 'package:lightmeter/data/volume_events_service.dart';
|
2023-05-11 13:30:18 +00:00
|
|
|
import 'package:lightmeter/environment.dart';
|
|
|
|
import 'package:lightmeter/generated/l10n.dart';
|
2023-08-14 10:25:37 +00:00
|
|
|
import 'package:lightmeter/providers/services_provider.dart';
|
|
|
|
import 'package:lightmeter/providers/user_preferences_provider.dart';
|
2023-05-11 13:30:18 +00:00
|
|
|
import 'package:lightmeter/screens/metering/flow_metering.dart';
|
|
|
|
import 'package:lightmeter/screens/settings/flow_settings.dart';
|
2023-08-15 10:08:30 +00:00
|
|
|
import 'package:m3_lightmeter_iap/m3_lightmeter_iap.dart';
|
2023-08-14 10:25:37 +00:00
|
|
|
import 'package:platform/platform.dart';
|
|
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
2022-12-15 11:00:28 +00:00
|
|
|
|
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-08-14 10:25:37 +00:00
|
|
|
return FutureBuilder(
|
|
|
|
future: Future.wait([
|
|
|
|
SharedPreferences.getInstance(),
|
|
|
|
const LightSensorService(LocalPlatform()).hasSensor(),
|
|
|
|
]),
|
|
|
|
builder: (_, snapshot) {
|
|
|
|
if (snapshot.data != null) {
|
2023-08-15 10:08:30 +00:00
|
|
|
return IAPProviders(
|
|
|
|
sharedPreferences: snapshot.data![0] as SharedPreferences,
|
|
|
|
child: ServicesProvider(
|
|
|
|
caffeineService: const CaffeineService(),
|
|
|
|
environment: env.copyWith(hasLightSensor: snapshot.data![1] as bool),
|
|
|
|
hapticsService: const HapticsService(),
|
|
|
|
lightSensorService: const LightSensorService(LocalPlatform()),
|
|
|
|
permissionsService: const PermissionsService(),
|
|
|
|
userPreferencesService:
|
|
|
|
UserPreferencesService(snapshot.data![0] as SharedPreferences),
|
|
|
|
volumeEventsService: const VolumeEventsService(LocalPlatform()),
|
|
|
|
child: UserPreferencesProvider(
|
2023-08-14 10:25:37 +00:00
|
|
|
child: Builder(
|
|
|
|
builder: (context) {
|
|
|
|
final theme = UserPreferencesProvider.themeOf(context);
|
|
|
|
final systemIconsBrightness =
|
|
|
|
ThemeData.estimateBrightnessForColor(theme.colorScheme.onSurface);
|
|
|
|
return AnnotatedRegion(
|
|
|
|
value: SystemUiOverlayStyle(
|
|
|
|
statusBarColor: Colors.transparent,
|
|
|
|
statusBarBrightness: systemIconsBrightness == Brightness.light
|
|
|
|
? Brightness.dark
|
|
|
|
: Brightness.light,
|
|
|
|
statusBarIconBrightness: systemIconsBrightness,
|
|
|
|
systemNavigationBarColor: Colors.transparent,
|
|
|
|
systemNavigationBarIconBrightness: systemIconsBrightness,
|
|
|
|
),
|
|
|
|
child: MaterialApp(
|
|
|
|
theme: theme,
|
|
|
|
locale: Locale(UserPreferencesProvider.localeOf(context).intlName),
|
|
|
|
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-29 16:57:47 +00:00
|
|
|
),
|
2022-12-16 08:08:12 +00:00
|
|
|
),
|
2023-08-14 10:25:37 +00:00
|
|
|
),
|
|
|
|
);
|
|
|
|
} else if (snapshot.error != null) {
|
|
|
|
return Center(child: Text(snapshot.error!.toString()));
|
|
|
|
}
|
2023-02-11 19:19:18 +00:00
|
|
|
|
2023-08-14 10:25:37 +00:00
|
|
|
// TODO(@vodemn): maybe user splashscreen instead
|
|
|
|
return const SizedBox();
|
|
|
|
},
|
2023-02-11 19:19:18 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|