added conditions to films model updateShouldNotifyDependent

This commit is contained in:
Vadim 2024-11-03 17:43:18 +01:00
parent e29920b757
commit e7512e47c2
2 changed files with 11 additions and 6 deletions

View file

@ -1,3 +1,4 @@
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';
@ -113,8 +114,8 @@ class FilmsProviderState extends State<FilmsProvider> {
}
enum _FilmsModelAspect {
customFilmsList,
predefinedFilmsList,
customFilms,
predefinedFilms,
filmsInUse,
selected,
}
@ -134,7 +135,7 @@ class Films extends InheritedModel<_FilmsModelAspect> {
});
static List<Film> predefinedFilmsOf<T>(BuildContext context) {
return InheritedModel.inheritFrom<Films>(context, aspect: _FilmsModelAspect.predefinedFilmsList)!
return InheritedModel.inheritFrom<Films>(context, aspect: _FilmsModelAspect.predefinedFilms)!
.predefinedFilms
.values
.map((value) => value.film)
@ -142,7 +143,7 @@ class Films extends InheritedModel<_FilmsModelAspect> {
}
static List<FilmExponential> customFilmsOf<T>(BuildContext context) {
return InheritedModel.inheritFrom<Films>(context, aspect: _FilmsModelAspect.customFilmsList)!
return InheritedModel.inheritFrom<Films>(context, aspect: _FilmsModelAspect.customFilms)!
.customFilms
.values
.map((value) => value.film)
@ -168,7 +169,10 @@ class Films extends InheritedModel<_FilmsModelAspect> {
@override
bool updateShouldNotifyDependent(Films oldWidget, Set<_FilmsModelAspect> dependencies) {
// TODO: reduce unnecessary notifications
return true;
return (dependencies.contains(_FilmsModelAspect.selected) && oldWidget.selected != selected) ||
(dependencies.contains(_FilmsModelAspect.predefinedFilms) &&
const DeepCollectionEquality().equals(oldWidget.predefinedFilms, predefinedFilms)) ||
(dependencies.contains(_FilmsModelAspect.predefinedFilms) &&
const DeepCollectionEquality().equals(oldWidget.predefinedFilms, predefinedFilms));
}
}

View file

@ -13,6 +13,7 @@ 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