From e7512e47c2b81009ac0ccb38d70b9486902d6a03 Mon Sep 17 00:00:00 2001 From: Vadim <44135514+vodemn@users.noreply.github.com> Date: Sun, 3 Nov 2024 17:43:18 +0100 Subject: [PATCH] added conditions to films model `updateShouldNotifyDependent` --- lib/providers/films_provider.dart | 16 ++++++++++------ pubspec.yaml | 1 + 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/lib/providers/films_provider.dart b/lib/providers/films_provider.dart index 6bc3c0d..2291405 100644 --- a/lib/providers/films_provider.dart +++ b/lib/providers/films_provider.dart @@ -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 { } enum _FilmsModelAspect { - customFilmsList, - predefinedFilmsList, + customFilms, + predefinedFilms, filmsInUse, selected, } @@ -134,7 +135,7 @@ class Films extends InheritedModel<_FilmsModelAspect> { }); static List predefinedFilmsOf(BuildContext context) { - return InheritedModel.inheritFrom(context, aspect: _FilmsModelAspect.predefinedFilmsList)! + return InheritedModel.inheritFrom(context, aspect: _FilmsModelAspect.predefinedFilms)! .predefinedFilms .values .map((value) => value.film) @@ -142,7 +143,7 @@ class Films extends InheritedModel<_FilmsModelAspect> { } static List customFilmsOf(BuildContext context) { - return InheritedModel.inheritFrom(context, aspect: _FilmsModelAspect.customFilmsList)! + return InheritedModel.inheritFrom(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)); } } diff --git a/pubspec.yaml b/pubspec.yaml index 59060b3..3a09662 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -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