m3_lightmeter/lib/application_wrapper.dart
Vadim c66381f813
ML-191 Add an ability to add a generic film, that will accept a formula (#195)
* sync with resources

* separated `ExpandableSectionList` as widget

* fixed generic type

* implemented `FilmsScreen` (wip)

* made `SliverScreen` title a widget

* [`FilmEditScreen`] wip

* [`FilmEditScreen`] added validation

* fixed title overflow for `SliverScreen`

* [`FilmEditScreen`] separated add and edit blocs

* [`FilmEditScreen`] split into separate components

* added bottom widget to `SliverScreen`

* implemented films list tabs fo `FilmsScreen`

* added films screen to navigation

* replaced explicit routes names with enum values

* implemented CRUD for custom films

* added placeholder for empty custom films list

* added `FilmsStorageService`

* fixed unit tests

* fixed integration tests

* lint

* fixed golden tests

* added iap stub methods

* added custom films to features list

* use 2.0.0 resouces

* fixed film picket tests

* migrated to iap 1.0.1

* autofocus film name field

* wait for the film to edited

* migrated to iap 1.1.0

* typo

* wait for storage initialization

* migrated to iap 1.1.1

* fixed films initialization

* added conditions to films model `updateShouldNotifyDependent`

* typo

* fixed select film discard notify

* covered films model `updateShouldNotifyDependent`
2024-11-03 20:16:01 +01:00

108 lines
4.2 KiB
Dart

import 'package:flutter/material.dart';
import 'package:flutter_native_splash/flutter_native_splash.dart';
import 'package:lightmeter/data/analytics/analytics.dart';
import 'package:lightmeter/data/analytics/api/analytics_firebase.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/remote_config_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/equipment_profile_provider.dart';
import 'package:lightmeter/providers/films_provider.dart';
import 'package:lightmeter/providers/remote_config_provider.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 StatefulWidget {
final Environment env;
final Widget child;
const ApplicationWrapper(this.env, {required this.child, super.key});
@override
State<ApplicationWrapper> createState() => _ApplicationWrapperState();
}
class _ApplicationWrapperState extends State<ApplicationWrapper> {
late final remoteConfigService = widget.env.buildType != BuildType.dev
? const RemoteConfigService(LightmeterAnalytics(api: LightmeterAnalyticsFirebase()))
: const MockRemoteConfigService();
late final IAPStorageService iapStorageService;
late final UserPreferencesService userPreferencesService;
late final bool hasLightSensor;
final filmsStorageService = FilmsStorageService();
late final Future<void> _initFuture;
@override
void initState() {
super.initState();
_initFuture = _initialize();
}
@override
Widget build(BuildContext context) {
return FutureBuilder(
future: _initFuture,
builder: (context, snapshot) {
if (snapshot.error != null) {
return Center(child: Text(snapshot.error!.toString()));
} else if (snapshot.connectionState == ConnectionState.done) {
return ServicesProvider(
analytics: const LightmeterAnalytics(api: LightmeterAnalyticsFirebase()),
caffeineService: const CaffeineService(),
environment: widget.env.copyWith(hasLightSensor: hasLightSensor),
hapticsService: const HapticsService(),
lightSensorService: const LightSensorService(LocalPlatform()),
permissionsService: const PermissionsService(),
userPreferencesService: userPreferencesService,
volumeEventsService: const VolumeEventsService(LocalPlatform()),
child: RemoteConfigProvider(
remoteConfigService: remoteConfigService,
child: EquipmentProfileProvider(
storageService: iapStorageService,
child: FilmsProvider(
filmsStorageService: filmsStorageService,
onInitialized: _onFilmsProviderInitialized,
child: UserPreferencesProvider(
hasLightSensor: hasLightSensor,
userPreferencesService: userPreferencesService,
child: widget.child,
),
),
),
),
);
}
return const SizedBox();
},
);
}
Future<void> _initialize() async {
await Future.wait([
SharedPreferences.getInstance(),
const LightSensorService(LocalPlatform()).hasSensor(),
remoteConfigService.activeAndFetchFeatures(),
filmsStorageService.init(),
]).then((value) {
final sharedPrefs = (value[0] as SharedPreferences?)!;
iapStorageService = IAPStorageService(sharedPrefs);
userPreferencesService = UserPreferencesService(sharedPrefs);
hasLightSensor = value[1] as bool? ?? false;
});
}
void _onFilmsProviderInitialized() {
FlutterNativeSplash.remove();
}
}