mirror of
https://github.com/vodemn/m3_lightmeter.git
synced 2024-12-03 12:50:40 +00:00
fixed films initialization
This commit is contained in:
parent
f22086e578
commit
e29920b757
2 changed files with 42 additions and 31 deletions
|
@ -39,7 +39,6 @@ class _ApplicationWrapperState extends State<ApplicationWrapper> {
|
|||
late final bool hasLightSensor;
|
||||
|
||||
final filmsStorageService = FilmsStorageService();
|
||||
final filmsProviderKey = GlobalKey<FilmsProviderState>();
|
||||
|
||||
late final Future<void> _initFuture;
|
||||
|
||||
|
@ -51,28 +50,28 @@ class _ApplicationWrapperState extends State<ApplicationWrapper> {
|
|||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return FilmsProvider(
|
||||
key: filmsProviderKey,
|
||||
filmsStorageService: filmsStorageService,
|
||||
child: 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,
|
||||
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,
|
||||
|
@ -80,12 +79,12 @@ class _ApplicationWrapperState extends State<ApplicationWrapper> {
|
|||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return const SizedBox();
|
||||
},
|
||||
),
|
||||
return const SizedBox();
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -94,13 +93,16 @@ class _ApplicationWrapperState extends State<ApplicationWrapper> {
|
|||
SharedPreferences.getInstance(),
|
||||
const LightSensorService(LocalPlatform()).hasSensor(),
|
||||
remoteConfigService.activeAndFetchFeatures(),
|
||||
filmsStorageService.init().then((_) => filmsProviderKey.currentState?.init()),
|
||||
filmsStorageService.init(),
|
||||
]).then((value) {
|
||||
final sharedPrefs = (value[0] as SharedPreferences?)!;
|
||||
iapStorageService = IAPStorageService(sharedPrefs);
|
||||
userPreferencesService = UserPreferencesService(sharedPrefs);
|
||||
hasLightSensor = value[1] as bool? ?? false;
|
||||
FlutterNativeSplash.remove();
|
||||
});
|
||||
}
|
||||
|
||||
void _onFilmsProviderInitialized() {
|
||||
FlutterNativeSplash.remove();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,10 +5,12 @@ import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart';
|
|||
|
||||
class FilmsProvider extends StatefulWidget {
|
||||
final FilmsStorageService filmsStorageService;
|
||||
final VoidCallback? onInitialized;
|
||||
final Widget child;
|
||||
|
||||
const FilmsProvider({
|
||||
required this.filmsStorageService,
|
||||
this.onInitialized,
|
||||
required this.child,
|
||||
super.key,
|
||||
});
|
||||
|
@ -28,6 +30,12 @@ class FilmsProviderState extends State<FilmsProvider> {
|
|||
|
||||
Film get _selectedFilm => customFilms[_selectedId]?.film ?? predefinedFilms[_selectedId]?.film ?? const FilmStub();
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_init();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Films(
|
||||
|
@ -38,12 +46,13 @@ class FilmsProviderState extends State<FilmsProvider> {
|
|||
);
|
||||
}
|
||||
|
||||
Future<void> init() async {
|
||||
Future<void> _init() async {
|
||||
_selectedId = widget.filmsStorageService.selectedFilmId;
|
||||
predefinedFilms.addAll(await widget.filmsStorageService.getPredefinedFilms());
|
||||
customFilms.addAll(await widget.filmsStorageService.getCustomFilms());
|
||||
_discardSelectedIfNotIncluded();
|
||||
if (mounted) setState(() {});
|
||||
widget.onInitialized?.call();
|
||||
}
|
||||
|
||||
/* Both type of films **/
|
||||
|
|
Loading…
Reference in a new issue