mirror of
https://github.com/vodemn/m3_lightmeter.git
synced 2024-12-04 21:30:39 +00:00
Compare commits
No commits in common. "2accf9f2b3fc332c5062bbae350373853a87972d" and "8bc35633a750a86abd2d8ec5d0919996a06af239" have entirely different histories.
2accf9f2b3
...
8bc35633a7
4 changed files with 47 additions and 109 deletions
|
@ -39,6 +39,7 @@ class _ApplicationWrapperState extends State<ApplicationWrapper> {
|
|||
late final bool hasLightSensor;
|
||||
|
||||
final filmsStorageService = FilmsStorageService();
|
||||
final filmsProviderKey = GlobalKey<FilmsProviderState>();
|
||||
|
||||
late final Future<void> _initFuture;
|
||||
|
||||
|
@ -50,7 +51,10 @@ class _ApplicationWrapperState extends State<ApplicationWrapper> {
|
|||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return FutureBuilder(
|
||||
return FilmsProvider(
|
||||
key: filmsProviderKey,
|
||||
filmsStorageService: filmsStorageService,
|
||||
child: FutureBuilder(
|
||||
future: _initFuture,
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.error != null) {
|
||||
|
@ -69,9 +73,6 @@ class _ApplicationWrapperState extends State<ApplicationWrapper> {
|
|||
remoteConfigService: remoteConfigService,
|
||||
child: EquipmentProfileProvider(
|
||||
storageService: iapStorageService,
|
||||
child: FilmsProvider(
|
||||
filmsStorageService: filmsStorageService,
|
||||
onInitialized: _onFilmsProviderInitialized,
|
||||
child: UserPreferencesProvider(
|
||||
hasLightSensor: hasLightSensor,
|
||||
userPreferencesService: userPreferencesService,
|
||||
|
@ -79,12 +80,12 @@ class _ApplicationWrapperState extends State<ApplicationWrapper> {
|
|||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return const SizedBox();
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -93,16 +94,13 @@ class _ApplicationWrapperState extends State<ApplicationWrapper> {
|
|||
SharedPreferences.getInstance(),
|
||||
const LightSensorService(LocalPlatform()).hasSensor(),
|
||||
remoteConfigService.activeAndFetchFeatures(),
|
||||
filmsStorageService.init(),
|
||||
filmsStorageService.init().then((_) => filmsProviderKey.currentState?.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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
import 'package:collection/collection.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:lightmeter/utils/context_utils.dart';
|
||||
import 'package:m3_lightmeter_iap/m3_lightmeter_iap.dart';
|
||||
|
@ -6,12 +5,10 @@ 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,
|
||||
});
|
||||
|
@ -31,12 +28,6 @@ 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(
|
||||
|
@ -47,13 +38,12 @@ 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 **/
|
||||
|
@ -114,8 +104,8 @@ class FilmsProviderState extends State<FilmsProvider> {
|
|||
}
|
||||
|
||||
enum _FilmsModelAspect {
|
||||
customFilms,
|
||||
predefinedFilms,
|
||||
customFilmsList,
|
||||
predefinedFilmsList,
|
||||
filmsInUse,
|
||||
selected,
|
||||
}
|
||||
|
@ -135,7 +125,7 @@ class Films extends InheritedModel<_FilmsModelAspect> {
|
|||
});
|
||||
|
||||
static List<Film> predefinedFilmsOf<T>(BuildContext context) {
|
||||
return InheritedModel.inheritFrom<Films>(context, aspect: _FilmsModelAspect.predefinedFilms)!
|
||||
return InheritedModel.inheritFrom<Films>(context, aspect: _FilmsModelAspect.predefinedFilmsList)!
|
||||
.predefinedFilms
|
||||
.values
|
||||
.map((value) => value.film)
|
||||
|
@ -143,7 +133,7 @@ class Films extends InheritedModel<_FilmsModelAspect> {
|
|||
}
|
||||
|
||||
static List<FilmExponential> customFilmsOf<T>(BuildContext context) {
|
||||
return InheritedModel.inheritFrom<Films>(context, aspect: _FilmsModelAspect.customFilms)!
|
||||
return InheritedModel.inheritFrom<Films>(context, aspect: _FilmsModelAspect.customFilmsList)!
|
||||
.customFilms
|
||||
.values
|
||||
.map((value) => value.film)
|
||||
|
@ -169,12 +159,7 @@ class Films extends InheritedModel<_FilmsModelAspect> {
|
|||
|
||||
@override
|
||||
bool updateShouldNotifyDependent(Films oldWidget, Set<_FilmsModelAspect> dependencies) {
|
||||
return (dependencies.contains(_FilmsModelAspect.selected) && oldWidget.selected != selected) ||
|
||||
((dependencies.contains(_FilmsModelAspect.predefinedFilms) ||
|
||||
dependencies.contains(_FilmsModelAspect.filmsInUse)) &&
|
||||
const DeepCollectionEquality().equals(oldWidget.predefinedFilms, predefinedFilms)) ||
|
||||
((dependencies.contains(_FilmsModelAspect.customFilms) ||
|
||||
dependencies.contains(_FilmsModelAspect.filmsInUse)) &&
|
||||
const DeepCollectionEquality().equals(oldWidget.customFilms, customFilms));
|
||||
// TODO: reduce unnecessary notifications
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,7 +13,6 @@ dependencies:
|
|||
camera: 0.10.5+2
|
||||
camera_android_camerax: 0.6.1+1
|
||||
clipboard: 0.1.3
|
||||
collection: any
|
||||
dynamic_color: 1.7.0
|
||||
exif: 3.1.4
|
||||
firebase_analytics: 10.6.2
|
||||
|
@ -32,7 +31,7 @@ dependencies:
|
|||
m3_lightmeter_iap:
|
||||
git:
|
||||
url: "https://github.com/vodemn/m3_lightmeter_iap"
|
||||
ref: v1.1.1
|
||||
ref: v1.1.0
|
||||
m3_lightmeter_resources:
|
||||
git:
|
||||
url: "https://github.com/vodemn/m3_lightmeter_resources"
|
||||
|
|
|
@ -50,19 +50,19 @@ void main() {
|
|||
}
|
||||
|
||||
void expectPredefinedFilmsCount(int count) {
|
||||
expect(find.text(_PredefinedFilmsCount.text(count)), findsOneWidget);
|
||||
expect(find.text('Predefined films count: $count'), findsOneWidget);
|
||||
}
|
||||
|
||||
void expectCustomFilmsCount(int count) {
|
||||
expect(find.text(_CustomFilmsCount.text(count)), findsOneWidget);
|
||||
expect(find.text('Custom films count: $count'), findsOneWidget);
|
||||
}
|
||||
|
||||
void expectFilmsInUseCount(int count) {
|
||||
expect(find.text(_FilmsInUseCount.text(count)), findsOneWidget);
|
||||
expect(find.text('Films in use count: $count'), findsOneWidget);
|
||||
}
|
||||
|
||||
void expectSelectedFilmName(String name) {
|
||||
expect(find.text(_SelectedFilm.text(name)), findsOneWidget);
|
||||
expect(find.text('Selected film: $name'), findsOneWidget);
|
||||
}
|
||||
|
||||
group(
|
||||
|
@ -234,15 +234,15 @@ class _Application extends StatelessWidget {
|
|||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return const MaterialApp(
|
||||
return MaterialApp(
|
||||
home: Scaffold(
|
||||
body: Center(
|
||||
child: Column(
|
||||
children: [
|
||||
_PredefinedFilmsCount(),
|
||||
_CustomFilmsCount(),
|
||||
_FilmsInUseCount(),
|
||||
_SelectedFilm(),
|
||||
Text("Predefined films count: ${Films.predefinedFilmsOf(context).length}"),
|
||||
Text("Custom films count: ${Films.customFilmsOf(context).length}"),
|
||||
Text("Films in use count: ${Films.inUseOf(context).length}"),
|
||||
Text("Selected film: ${Films.selectedOf(context).name}"),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
@ -251,50 +251,6 @@ class _Application extends StatelessWidget {
|
|||
}
|
||||
}
|
||||
|
||||
class _PredefinedFilmsCount extends StatelessWidget {
|
||||
static String text(int count) => "Predefined films count: $count";
|
||||
|
||||
const _PredefinedFilmsCount();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Text(text(Films.predefinedFilmsOf(context).length));
|
||||
}
|
||||
}
|
||||
|
||||
class _CustomFilmsCount extends StatelessWidget {
|
||||
static String text(int count) => "Custom films count: $count";
|
||||
|
||||
const _CustomFilmsCount();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Text(text(Films.customFilmsOf(context).length));
|
||||
}
|
||||
}
|
||||
|
||||
class _FilmsInUseCount extends StatelessWidget {
|
||||
static String text(int count) => "Films in use count: $count";
|
||||
|
||||
const _FilmsInUseCount();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Text(text(Films.inUseOf(context).length));
|
||||
}
|
||||
}
|
||||
|
||||
class _SelectedFilm extends StatelessWidget {
|
||||
static String text(String name) => "Selected film: $name}";
|
||||
|
||||
const _SelectedFilm();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Text(text(Films.selectedOf(context).name));
|
||||
}
|
||||
}
|
||||
|
||||
const mockPredefinedFilms = [
|
||||
FilmExponential(id: '1', name: 'Mock film 2x', iso: 400, exponent: 1.34),
|
||||
FilmExponential(id: '2', name: 'Mock film 3x', iso: 800, exponent: 1.34),
|
||||
|
|
Loading…
Reference in a new issue