generate for 3 colors

This commit is contained in:
Vadim 2023-09-25 21:33:18 +02:00
parent 159b98dfa2
commit 89618c5f18
7 changed files with 239 additions and 315 deletions

View file

@ -2,10 +2,9 @@ import 'dart:io';
import 'package:bloc_test/bloc_test.dart'; import 'package:bloc_test/bloc_test.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/src/widgets/basic.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
import 'package:integration_test/integration_test.dart'; import 'package:integration_test/integration_test.dart';
import 'package:lightmeter/application.dart';
import 'package:lightmeter/data/caffeine_service.dart'; import 'package:lightmeter/data/caffeine_service.dart';
import 'package:lightmeter/data/haptics_service.dart'; import 'package:lightmeter/data/haptics_service.dart';
import 'package:lightmeter/data/light_sensor_service.dart'; import 'package:lightmeter/data/light_sensor_service.dart';
@ -19,24 +18,25 @@ import 'package:lightmeter/data/shared_prefs_service.dart';
import 'package:lightmeter/data/volume_events_service.dart'; import 'package:lightmeter/data/volume_events_service.dart';
import 'package:lightmeter/environment.dart'; import 'package:lightmeter/environment.dart';
import 'package:lightmeter/generated/l10n.dart'; import 'package:lightmeter/generated/l10n.dart';
import 'package:lightmeter/interactors/metering_interactor.dart'; import 'package:lightmeter/providers/services_provider.dart';
import 'package:lightmeter/providers/user_preferences_provider.dart';
import 'package:lightmeter/res/dimens.dart'; import 'package:lightmeter/res/dimens.dart';
import 'package:lightmeter/res/theme.dart';
import 'package:lightmeter/screens/metering/bloc_metering.dart'; import 'package:lightmeter/screens/metering/bloc_metering.dart';
import 'package:lightmeter/screens/metering/communication/bloc_communication_metering.dart';
import 'package:lightmeter/screens/metering/components/bottom_controls/components/measure_button/widget_button_measure.dart'; import 'package:lightmeter/screens/metering/components/bottom_controls/components/measure_button/widget_button_measure.dart';
import 'package:lightmeter/screens/metering/components/shared/readings_container/components/iso_picker/widget_picker_iso.dart'; import 'package:lightmeter/screens/metering/components/shared/readings_container/components/iso_picker/widget_picker_iso.dart';
import 'package:lightmeter/screens/metering/components/shared/readings_container/components/shared/animated_dialog_picker/components/animated_dialog/widget_dialog_animated.dart';
import 'package:lightmeter/screens/metering/components/shared/readings_container/components/shared/animated_dialog_picker/components/dialog_picker/widget_picker_dialog.dart'; import 'package:lightmeter/screens/metering/components/shared/readings_container/components/shared/animated_dialog_picker/components/dialog_picker/widget_picker_dialog.dart';
import 'package:lightmeter/screens/metering/flow_metering.dart';
import 'package:lightmeter/screens/metering/screen_metering.dart';
import 'package:lightmeter/screens/metering/state_metering.dart'; import 'package:lightmeter/screens/metering/state_metering.dart';
import 'package:lightmeter/screens/settings/flow_settings.dart'; import 'package:lightmeter/screens/settings/components/metering/components/equipment_profiles/components/equipment_profile_screen/components/equipment_profile_container/widget_container_equipment_profile.dart';
import 'package:lightmeter/screens/settings/components/metering/components/equipment_profiles/components/equipment_profile_screen/screen_equipment_profile.dart';
import 'package:lightmeter/screens/settings/screen_settings.dart'; import 'package:lightmeter/screens/settings/screen_settings.dart';
import 'package:m3_lightmeter_iap/m3_lightmeter_iap.dart';
import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart'; import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart';
import 'package:mocktail/mocktail.dart'; import 'package:mocktail/mocktail.dart';
import 'package:permission_handler/permission_handler.dart'; import 'package:permission_handler/permission_handler.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'mocks/application_mock.dart'; class _MockSharedPreferences extends Mock implements SharedPreferences {}
class _MockUserPreferencesService extends Mock implements UserPreferencesService {} class _MockUserPreferencesService extends Mock implements UserPreferencesService {}
@ -52,6 +52,7 @@ class _MockVolumeEventsService extends Mock implements VolumeEventsService {}
class _MockMeteringBloc extends Mock implements MeteringBloc {} class _MockMeteringBloc extends Mock implements MeteringBloc {}
//https://stackoverflow.com/a/67186625/13167574
void main() { void main() {
late _MockUserPreferencesService mockUserPreferencesService; late _MockUserPreferencesService mockUserPreferencesService;
late _MockCaffeineService mockCaffeineService; late _MockCaffeineService mockCaffeineService;
@ -74,7 +75,6 @@ void main() {
setUpAll(() { setUpAll(() {
mockUserPreferencesService = _MockUserPreferencesService(); mockUserPreferencesService = _MockUserPreferencesService();
when(() => mockUserPreferencesService.evSourceType).thenReturn(EvSourceType.sensor); when(() => mockUserPreferencesService.evSourceType).thenReturn(EvSourceType.sensor);
when(() => mockUserPreferencesService.stopType).thenReturn(StopType.third); when(() => mockUserPreferencesService.stopType).thenReturn(StopType.third);
when(() => mockUserPreferencesService.locale).thenReturn(SupportedLocale.en); when(() => mockUserPreferencesService.locale).thenReturn(SupportedLocale.en);
@ -95,7 +95,8 @@ void main() {
when(() => mockUserPreferencesService.dynamicColor).thenReturn(false); when(() => mockUserPreferencesService.dynamicColor).thenReturn(false);
mockCaffeineService = _MockCaffeineService(); mockCaffeineService = _MockCaffeineService();
when(() => mockCaffeineService.keepScreenOn(true)).thenAnswer((_) async => true); when(() => mockCaffeineService.isKeepScreenOn()).thenAnswer((_) async => false);
when(() => mockCaffeineService.keepScreenOn(false)).thenAnswer((_) async => false);
mockHapticsService = _MockHapticsService(); mockHapticsService = _MockHapticsService();
when(() => mockHapticsService.quickVibration()).thenAnswer((_) async {}); when(() => mockHapticsService.quickVibration()).thenAnswer((_) async {});
@ -127,75 +128,82 @@ void main() {
when(() => meteringBloc.close()).thenAnswer((_) async {}); when(() => meteringBloc.close()).thenAnswer((_) async {});
}); });
group( void generateScreenshots(Color color) {
'',
() {
const initColor = 0xff2196f3;
setUp(() {
when(() => mockUserPreferencesService.primaryColor).thenReturn(const Color(initColor));
});
testWidgets( testWidgets(
'$initColor', '${color.value}',
(tester) async { (tester) async {
when(() => mockUserPreferencesService.primaryColor).thenReturn(color);
await tester.pumpWidget( await tester.pumpWidget(
ApplicationMock( IAPProviders(
const Environment.prod().copyWith(hasLightSensor: true), sharedPreferences: _MockSharedPreferences(),
child: EquipmentProfiles(
selected: _mockEquipmentProfiles[1],
values: _mockEquipmentProfiles,
child: Films(
selected: const Film('Ilford HP5+', 400),
values: const [Film.other(), Film('Ilford HP5+', 400)],
filmsInUse: const [Film.other(), Film('Ilford HP5+', 400)],
child: ServicesProvider(
environment: const Environment.prod().copyWith(hasLightSensor: true),
userPreferencesService: mockUserPreferencesService, userPreferencesService: mockUserPreferencesService,
caffeineService: mockCaffeineService, caffeineService: mockCaffeineService,
hapticsService: mockHapticsService, hapticsService: mockHapticsService,
permissionsService: mockPermissionsService, permissionsService: mockPermissionsService,
lightSensorService: mockLightSensorService, lightSensorService: mockLightSensorService,
volumeEventsService: mockVolumeEventsService, volumeEventsService: mockVolumeEventsService,
child: const UserPreferencesProvider(
child: Application(),
),
),
),
),
), ),
); );
await tester.pumpAndSettle(); await tester.pumpAndSettle();
//await tester.takeScreenshot(binding, '$initColor-metering-reflected'); //await tester.takeScreenshot(binding, '${color.value}-metering-reflected');
await tester.tap(find.byType(MeteringMeasureButton)); await tester.tap(find.byType(MeteringMeasureButton));
await tester.tap(find.byType(MeteringMeasureButton)); await tester.tap(find.byType(MeteringMeasureButton));
await tester.takeScreenshot(binding, '$initColor-metering-incident'); await tester.takeScreenshot(binding, '${color.value}-metering-incident');
expect(find.byType(IsoValuePicker), findsOneWidget);
await tester.tap(find.byType(IsoValuePicker)); await tester.tap(find.byType(IsoValuePicker));
await tester.pumpAndSettle(Dimens.durationL); await tester.pumpAndSettle(Dimens.durationL);
expect(find.byType(IsoValuePicker), findsOneWidget); expect(find.byType(DialogPicker<IsoValue>), findsOneWidget);
await tester.takeScreenshot(binding, '$initColor-metering-iso_picker'); await tester.takeScreenshot(binding, '${color.value}-metering-iso_picker');
final cancelButton = find.byWidgetPredicate(
(widget) =>
widget is TextButton &&
widget.child is Text &&
(widget.child as Text?)?.data == (S.current.cancel),
);
expect(cancelButton, findsOneWidget);
await tester.tap(cancelButton);
// await tester.tap(
// find.descendant(
// of: find.byWidgetPredicate(
// (widget) =>
// widget is AnimatedDialog && widget.openedChild is DialogPicker<IsoValue>,
// ),
// matching: find.byType(TextButton),
// ),
// );
await tester.pumpAndSettle(Dimens.durationML);
await tester.pumpAndSettle();
await tester.tapCancelButton();
expect(find.byType(DialogPicker<IsoValue>), findsNothing);
expect(find.byTooltip(S.current.tooltipOpenSettings), findsOneWidget); expect(find.byTooltip(S.current.tooltipOpenSettings), findsOneWidget);
await tester.tap(find.byTooltip(S.current.tooltipOpenSettings)); await tester.tap(find.byTooltip(S.current.tooltipOpenSettings));
await tester.pumpAndSettle(); await tester.pumpAndSettle();
// print("============ TAP ============"); expect(find.byType(SettingsScreen), findsOneWidget);
// expect(find.byType(SettingsScreen), findsOneWidget); await tester.takeScreenshot(binding, '${color.value}-settings');
// await tester.takeScreenshot(binding, '$initColor-settings');
// await tester.takeScreenshot(binding, '$initColor-settings-metering_screen_layout'); await tester.tapListTile(S.current.meteringScreenLayout);
// await tester.takeScreenshot(binding, '$initColor-equipment_profiles'); await tester.takeScreenshot(binding, '${color.value}-settings-metering_screen_layout');
// await tester.takeScreenshot(binding, '$initColor-equipment_profiles-iso_picker');
}, await tester.tapCancelButton();
); await tester.tapListTile(S.current.equipmentProfiles);
expect(find.byType(EquipmentProfilesScreen), findsOneWidget);
await tester.tap(find.byType(EquipmentProfileContainer).first);
await tester.pumpAndSettle();
await tester.takeScreenshot(binding, '${color.value}-equipment_profiles');
await tester.tap(find.byIcon(Icons.iso).first);
await tester.pumpAndSettle();
await tester.takeScreenshot(binding, '${color.value}-equipment_profiles-iso_picker');
}, },
); );
} }
generateScreenshots(primaryColorsList[5]);
generateScreenshots(primaryColorsList[3]);
generateScreenshots(primaryColorsList[9]);
}
extension on WidgetTester { extension on WidgetTester {
Future<void> takeScreenshot(IntegrationTestWidgetsFlutterBinding binding, String name) async { Future<void> takeScreenshot(IntegrationTestWidgetsFlutterBinding binding, String name) async {
if (Platform.isAndroid) { if (Platform.isAndroid) {
@ -203,5 +211,71 @@ extension on WidgetTester {
await pumpAndSettle(); await pumpAndSettle();
} }
await binding.takeScreenshot(name); await binding.takeScreenshot(name);
await pumpAndSettle();
}
Future<void> tapCancelButton() async {
final cancelButton = find.byWidgetPredicate(
(widget) =>
widget is TextButton &&
widget.child is Text &&
(widget.child as Text?)?.data == S.current.cancel,
);
expect(cancelButton, findsOneWidget);
await tap(cancelButton);
await pumpAndSettle();
}
Future<void> tapListTile(String title) async {
final listTile = find.byWidgetPredicate(
(widget) =>
widget is ListTile && widget.title is Text && (widget.title as Text?)?.data == title,
);
expect(listTile, findsOneWidget);
await tap(listTile);
await pumpAndSettle();
} }
} }
final _mockEquipmentProfiles = [
const EquipmentProfile(
id: '',
name: '',
apertureValues: ApertureValue.values,
ndValues: NdValue.values,
shutterSpeedValues: ShutterSpeedValue.values,
isoValues: IsoValue.values,
),
EquipmentProfile(
id: '1',
name: 'Praktica + Zenitar',
apertureValues: ApertureValue.values.sublist(
ApertureValue.values.indexOf(const ApertureValue(1.7, StopType.half)),
ApertureValue.values.indexOf(const ApertureValue(16, StopType.full)),
),
ndValues: NdValue.values.sublist(0, 3),
shutterSpeedValues: ShutterSpeedValue.values.sublist(
ShutterSpeedValue.values.indexOf(const ShutterSpeedValue(1000, true, StopType.full)),
ShutterSpeedValue.values.indexOf(const ShutterSpeedValue(16, false, StopType.full)),
),
isoValues: const [
IsoValue(50, StopType.full),
IsoValue(100, StopType.full),
IsoValue(200, StopType.full),
IsoValue(250, StopType.third),
IsoValue(400, StopType.full),
IsoValue(500, StopType.third),
IsoValue(800, StopType.full),
IsoValue(1600, StopType.full),
IsoValue(3200, StopType.full),
],
),
const EquipmentProfile(
id: '2',
name: 'Praktica + Jupiter',
apertureValues: ApertureValue.values,
ndValues: NdValue.values,
shutterSpeedValues: ShutterSpeedValue.values,
isoValues: IsoValue.values,
),
];

View file

@ -1,159 +0,0 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:lightmeter/data/caffeine_service.dart';
import 'package:lightmeter/data/haptics_service.dart';
import 'package:lightmeter/data/light_sensor_service.dart';
import 'package:lightmeter/data/models/supported_locale.dart';
import 'package:lightmeter/data/permissions_service.dart';
import 'package:lightmeter/data/shared_prefs_service.dart';
import 'package:lightmeter/data/volume_events_service.dart';
import 'package:lightmeter/environment.dart';
import 'package:lightmeter/generated/l10n.dart';
import 'package:lightmeter/providers/services_provider.dart';
import 'package:lightmeter/providers/user_preferences_provider.dart';
import 'package:lightmeter/screens/metering/flow_metering.dart';
import 'package:lightmeter/screens/settings/flow_settings.dart';
import 'package:m3_lightmeter_iap/m3_lightmeter_iap.dart';
import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart';
import 'package:mocktail/mocktail.dart';
import 'package:shared_preferences/shared_preferences.dart';
class _MockSharedPreferences extends Mock implements SharedPreferences {}
class ApplicationMock extends StatelessWidget {
final Environment env;
final CaffeineService caffeineService;
final HapticsService hapticsService;
final LightSensorService lightSensorService;
final PermissionsService permissionsService;
final UserPreferencesService userPreferencesService;
final VolumeEventsService volumeEventsService;
const ApplicationMock(
this.env, {
required this.caffeineService,
required this.hapticsService,
required this.lightSensorService,
required this.permissionsService,
required this.userPreferencesService,
required this.volumeEventsService,
super.key,
});
@override
Widget build(BuildContext context) {
return IAPProviders(
sharedPreferences: _MockSharedPreferences(),
child: IAPProducts(
products: [
IAPProduct(
storeId: IAPProductType.paidFeatures.storeId,
status: IAPProductStatus.purchased,
)
],
child: EquipmentProfiles(
selected: _equipmentProfiles[1],
values: _equipmentProfiles,
child: Films(
selected: Film('Ilford HP+', 400),
values: [Film.other(), Film('Ilford HP+', 400)],
filmsInUse: [Film.other(), Film('Ilford HP+', 400)],
child: ServicesProvider(
caffeineService: caffeineService,
environment: env,
hapticsService: hapticsService,
lightSensorService: lightSensorService,
permissionsService: permissionsService,
userPreferencesService: userPreferencesService,
volumeEventsService: volumeEventsService,
child: UserPreferencesProvider(
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(),
},
),
);
},
),
),
),
),
),
),
);
}
}
final _equipmentProfiles = [
const EquipmentProfile(
id: '',
name: '',
apertureValues: ApertureValue.values,
ndValues: NdValue.values,
shutterSpeedValues: ShutterSpeedValue.values,
isoValues: IsoValue.values,
),
EquipmentProfile(
id: '1',
name: 'Praktikca + Zenitar',
apertureValues: ApertureValue.values.sublist(
ApertureValue.values.indexOf(const ApertureValue(1.7, StopType.half)),
ApertureValue.values.indexOf(const ApertureValue(16, StopType.full)),
),
ndValues: NdValue.values.sublist(0, 3),
shutterSpeedValues: ShutterSpeedValue.values.sublist(
ShutterSpeedValue.values.indexOf(const ShutterSpeedValue(1000, true, StopType.full)),
ShutterSpeedValue.values.indexOf(const ShutterSpeedValue(16, false, StopType.full)),
),
isoValues: const [
IsoValue(50, StopType.full),
IsoValue(100, StopType.full),
IsoValue(200, StopType.full),
IsoValue(250, StopType.third),
IsoValue(400, StopType.full),
IsoValue(500, StopType.third),
IsoValue(800, StopType.full),
IsoValue(1600, StopType.full),
IsoValue(3200, StopType.full),
],
),
const EquipmentProfile(
id: '2',
name: 'Praktica + Jupiter',
apertureValues: ApertureValue.values,
ndValues: NdValue.values,
shutterSpeedValues: ShutterSpeedValue.values,
isoValues: IsoValue.values,
),
];

View file

@ -1,60 +1,24 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'package:flutter_localizations/flutter_localizations.dart'; import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:lightmeter/data/caffeine_service.dart';
import 'package:lightmeter/data/haptics_service.dart';
import 'package:lightmeter/data/light_sensor_service.dart';
import 'package:lightmeter/data/models/supported_locale.dart'; import 'package:lightmeter/data/models/supported_locale.dart';
import 'package:lightmeter/data/permissions_service.dart';
import 'package:lightmeter/data/shared_prefs_service.dart';
import 'package:lightmeter/data/volume_events_service.dart';
import 'package:lightmeter/environment.dart';
import 'package:lightmeter/generated/l10n.dart'; import 'package:lightmeter/generated/l10n.dart';
import 'package:lightmeter/providers/services_provider.dart';
import 'package:lightmeter/providers/user_preferences_provider.dart'; import 'package:lightmeter/providers/user_preferences_provider.dart';
import 'package:lightmeter/screens/metering/flow_metering.dart'; import 'package:lightmeter/screens/metering/flow_metering.dart';
import 'package:lightmeter/screens/settings/flow_settings.dart'; import 'package:lightmeter/screens/settings/flow_settings.dart';
import 'package:m3_lightmeter_iap/m3_lightmeter_iap.dart';
import 'package:platform/platform.dart';
import 'package:shared_preferences/shared_preferences.dart';
class Application extends StatelessWidget { class Application extends StatelessWidget {
final Environment env; const Application({super.key});
const Application(this.env, {super.key});
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return FutureBuilder(
future: Future.wait([
SharedPreferences.getInstance(),
const LightSensorService(LocalPlatform()).hasSensor(),
]),
builder: (_, snapshot) {
if (snapshot.data != null) {
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(
child: Builder(
builder: (context) {
final theme = UserPreferencesProvider.themeOf(context); final theme = UserPreferencesProvider.themeOf(context);
final systemIconsBrightness = final systemIconsBrightness = ThemeData.estimateBrightnessForColor(theme.colorScheme.onSurface);
ThemeData.estimateBrightnessForColor(theme.colorScheme.onSurface);
return AnnotatedRegion( return AnnotatedRegion(
value: SystemUiOverlayStyle( value: SystemUiOverlayStyle(
statusBarColor: Colors.transparent, statusBarColor: Colors.transparent,
statusBarBrightness: systemIconsBrightness == Brightness.light statusBarBrightness:
? Brightness.dark systemIconsBrightness == Brightness.light ? Brightness.dark : Brightness.light,
: Brightness.light,
statusBarIconBrightness: systemIconsBrightness, statusBarIconBrightness: systemIconsBrightness,
systemNavigationBarColor: Colors.transparent, systemNavigationBarColor: Colors.transparent,
systemNavigationBarIconBrightness: systemIconsBrightness, systemNavigationBarIconBrightness: systemIconsBrightness,
@ -80,18 +44,5 @@ class Application extends StatelessWidget {
}, },
), ),
); );
},
),
),
),
);
} else if (snapshot.error != null) {
return Center(child: Text(snapshot.error!.toString()));
}
// TODO(@vodemn): maybe user splashscreen instead
return const SizedBox();
},
);
} }
} }

View file

@ -0,0 +1,55 @@
import 'package:flutter/material.dart';
import 'package:lightmeter/data/caffeine_service.dart';
import 'package:lightmeter/data/haptics_service.dart';
import 'package:lightmeter/data/light_sensor_service.dart';
import 'package:lightmeter/data/permissions_service.dart';
import 'package:lightmeter/data/shared_prefs_service.dart';
import 'package:lightmeter/data/volume_events_service.dart';
import 'package:lightmeter/environment.dart';
import 'package:lightmeter/providers/services_provider.dart';
import 'package:lightmeter/providers/user_preferences_provider.dart';
import 'package:m3_lightmeter_iap/m3_lightmeter_iap.dart';
import 'package:platform/platform.dart';
import 'package:shared_preferences/shared_preferences.dart';
class ApplicationWrapper extends StatelessWidget {
final Environment env;
final Widget child;
const ApplicationWrapper(this.env, {required this.child, super.key});
@override
Widget build(BuildContext context) {
return FutureBuilder(
future: Future.wait([
SharedPreferences.getInstance(),
const LightSensorService(LocalPlatform()).hasSensor(),
]),
builder: (_, snapshot) {
if (snapshot.data != null) {
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(
child: child,
),
),
);
} else if (snapshot.error != null) {
return Center(child: Text(snapshot.error!.toString()));
}
// TODO(@vodemn): maybe user splashscreen instead
return const SizedBox();
},
);
}
}

View file

@ -1,8 +1,9 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:lightmeter/application.dart'; import 'package:lightmeter/application.dart';
import 'package:lightmeter/application_wrapper.dart';
import 'package:lightmeter/environment.dart'; import 'package:lightmeter/environment.dart';
Future<void> main() async { Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized(); WidgetsFlutterBinding.ensureInitialized();
runApp(const Application(Environment.dev())); runApp(const ApplicationWrapper(Environment.dev(), child: Application()));
} }

View file

@ -1,10 +1,11 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:lightmeter/application.dart'; import 'package:lightmeter/application.dart';
import 'package:lightmeter/application_wrapper.dart';
import 'package:lightmeter/environment.dart'; import 'package:lightmeter/environment.dart';
import 'package:lightmeter/firebase.dart'; import 'package:lightmeter/firebase.dart';
Future<void> main() async { Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized(); WidgetsFlutterBinding.ensureInitialized();
await initializeFirebase(handleErrors: true); await initializeFirebase(handleErrors: true);
runApp(const Application(Environment.prod())); runApp(const ApplicationWrapper(Environment.prod(), child: Application()));
} }

View file

@ -1,10 +1,11 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:lightmeter/application.dart'; import 'package:lightmeter/application.dart';
import 'package:lightmeter/application_wrapper.dart';
import 'package:lightmeter/environment.dart'; import 'package:lightmeter/environment.dart';
import 'package:lightmeter/firebase.dart'; import 'package:lightmeter/firebase.dart';
Future<void> main() async { Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized(); WidgetsFlutterBinding.ensureInitialized();
await initializeFirebase(handleErrors: false); await initializeFirebase(handleErrors: false);
runApp(const Application(Environment.prod())); runApp(const ApplicationWrapper(Environment.prod(), child: Application()));
} }