diff --git a/iap/lib/src/data/films_storage_service.dart b/iap/lib/src/data/films_storage_service.dart index 9cab6b0..f49a5d9 100644 --- a/iap/lib/src/data/films_storage_service.dart +++ b/iap/lib/src/data/films_storage_service.dart @@ -1,7 +1,7 @@ import 'package:flutter/foundation.dart'; import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart'; -typedef SelectableFilm = ({T film, bool isUsed}); +typedef SelectableValue = ({T film, bool isUsed}); class FilmsStorageService { FilmsStorageService(); @@ -22,11 +22,11 @@ class FilmsStorageService { Future deleteFilm(FilmExponential _) async {} - Future>> getPredefinedFilms() async { + Future>> getPredefinedFilms() async { return const {}; } - Future>> getCustomFilms() async { + Future>> getCustomFilms() async { return const {}; } } diff --git a/integration_test/e2e_test.dart b/integration_test/e2e_test.dart index b935298..7d1c599 100644 --- a/integration_test/e2e_test.dart +++ b/integration_test/e2e_test.dart @@ -18,6 +18,7 @@ import 'package:lightmeter/screens/settings/components/shared/dialog_range_picke import 'package:lightmeter/screens/settings/screen_settings.dart'; import 'package:lightmeter/utils/double_to_zoom.dart'; import 'package:lightmeter/utils/platform_utils.dart'; +import 'package:m3_lightmeter_iap/m3_lightmeter_iap.dart'; import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart'; import 'package:meta/meta.dart'; import 'package:shared_preferences/shared_preferences.dart'; @@ -49,7 +50,7 @@ void testE2E(String description) { (tester) async { await tester.pumpApplication( equipmentProfiles: {}, - predefinedFilms: mockFilms.toFilmsMap(isUsed: true), + predefinedFilms: mockFilms.toSelectableMap(), customFilms: {}, ); diff --git a/integration_test/mocks/paid_features_mock.dart b/integration_test/mocks/paid_features_mock.dart index 56c2622..a2d99dc 100644 --- a/integration_test/mocks/paid_features_mock.dart +++ b/integration_test/mocks/paid_features_mock.dart @@ -10,24 +10,24 @@ class _MockEquipmentProfilesStorageService extends Mock implements EquipmentProf class _MockFilmsStorageService extends Mock implements FilmsStorageService {} class MockIAPProviders extends StatefulWidget { - final Map equipmentProfiles; + final SelectableMap equipmentProfiles; final String selectedEquipmentProfileId; - final Map> predefinedFilms; - final Map> customFilms; + final Map> predefinedFilms; + final Map> customFilms; final String selectedFilmId; final Widget child; MockIAPProviders({ - Map? equipmentProfiles, + SelectableMap? equipmentProfiles, this.selectedEquipmentProfileId = '', - Map>? predefinedFilms, - Map>? customFilms, + Map>? predefinedFilms, + Map>? customFilms, String? selectedFilmId, required this.child, super.key, - }) : equipmentProfiles = equipmentProfiles ?? mockEquipmentProfiles.toProfilesMap(), - predefinedFilms = predefinedFilms ?? mockFilms.toFilmsMap(), - customFilms = customFilms ?? mockFilms.toFilmsMap(), + }) : equipmentProfiles = equipmentProfiles ?? mockEquipmentProfiles.toSelectableMap(), + predefinedFilms = predefinedFilms ?? mockFilms.toSelectableMap(), + customFilms = customFilms ?? mockFilms.toSelectableMap(), selectedFilmId = selectedFilmId ?? const FilmStub().id; @override @@ -155,15 +155,6 @@ const mockFilms = [ _FilmMultiplying(id: '4', name: 'Mock film 4', iso: 1200, reciprocityMultiplier: 1.5), ]; -extension EquipmentProfileMapper on List { - Map toProfilesMap() => Map.fromEntries(map((e) => MapEntry(e.id, e))); -} - -extension FilmMapper on List { - Map toFilmsMap({bool isUsed = true}) => - Map.fromEntries(map((e) => MapEntry(e.id, (film: e as T, isUsed: isUsed)))); -} - class _FilmMultiplying extends FilmExponential { final double reciprocityMultiplier; diff --git a/integration_test/utils/widget_tester_actions.dart b/integration_test/utils/widget_tester_actions.dart index be385f0..2d8b8f6 100644 --- a/integration_test/utils/widget_tester_actions.dart +++ b/integration_test/utils/widget_tester_actions.dart @@ -20,10 +20,10 @@ const mockPhotoEv100 = 8.3; extension WidgetTesterCommonActions on WidgetTester { Future pumpApplication({ IAPProductStatus productStatus = IAPProductStatus.purchased, - Map? equipmentProfiles, + SelectableMap? equipmentProfiles, String selectedEquipmentProfileId = '', - Map>? predefinedFilms, - Map>? customFilms, + Map>? predefinedFilms, + Map>? customFilms, String selectedFilmId = '', }) async { await pumpWidget( diff --git a/lib/providers/equipment_profile_provider.dart b/lib/providers/equipment_profile_provider.dart index b09bb3c..747ae72 100644 --- a/lib/providers/equipment_profile_provider.dart +++ b/lib/providers/equipment_profile_provider.dart @@ -34,7 +34,7 @@ class EquipmentProfilesProvider extends StatefulWidget { } class EquipmentProfilesProviderState extends State { - final Map _customProfiles = {}; + final SelectableMap _customProfiles = {}; String _selectedId = ''; EquipmentProfile get _selectedProfile => _customProfiles[_selectedId] ?? EquipmentProfilesProvider.defaultProfile; diff --git a/lib/providers/films_provider.dart b/lib/providers/films_provider.dart index 5c5c683..4e0cce7 100644 --- a/lib/providers/films_provider.dart +++ b/lib/providers/films_provider.dart @@ -25,11 +25,11 @@ class FilmsProvider extends StatefulWidget { } class FilmsProviderState extends State { - final Map> predefinedFilms = {}; - final Map> customFilms = {}; + final Map> predefinedFilms = {}; + final Map> customFilms = {}; String _selectedId = ''; - Film get _selectedFilm => customFilms[_selectedId]?.film ?? predefinedFilms[_selectedId]?.film ?? const FilmStub(); + Film get _selectedFilm => customFilms[_selectedId]?.value ?? predefinedFilms[_selectedId]?.value ?? const FilmStub(); @override void initState() { @@ -60,9 +60,9 @@ class FilmsProviderState extends State { Future toggleFilm(Film film, bool enabled) async { if (predefinedFilms.containsKey(film.id)) { - predefinedFilms[film.id] = (film: film, isUsed: enabled); + predefinedFilms[film.id] = (value: film, isUsed: enabled); } else if (customFilms.containsKey(film.id)) { - customFilms[film.id] = (film: film as FilmExponential, isUsed: enabled); + customFilms[film.id] = (value: film as FilmExponential, isUsed: enabled); } else { return; } @@ -84,13 +84,13 @@ class FilmsProviderState extends State { Future addCustomFilm(FilmExponential film) async { // ignore: avoid_redundant_argument_values await widget.storageService.addFilm(film, isUsed: true); - customFilms[film.id] = (film: film, isUsed: true); + customFilms[film.id] = (value: film, isUsed: true); setState(() {}); } Future updateCustomFilm(FilmExponential film) async { await widget.storageService.updateFilm(film); - customFilms[film.id] = (film: film, isUsed: customFilms[film.id]!.isUsed); + customFilms[film.id] = (value: film, isUsed: customFilms[film.id]!.isUsed); setState(() {}); } @@ -121,10 +121,10 @@ enum _FilmsModelAspect { } class Films extends InheritedModel<_FilmsModelAspect> { - final Map> predefinedFilms; + final Map> predefinedFilms; @protected - final Map> customFilms; + final Map> customFilms; final Film selected; const Films({ @@ -138,7 +138,7 @@ class Films extends InheritedModel<_FilmsModelAspect> { return InheritedModel.inheritFrom(context, aspect: _FilmsModelAspect.predefinedFilms)! .predefinedFilms .values - .map((value) => value.film) + .map((value) => value.value) .toList(); } @@ -146,7 +146,7 @@ class Films extends InheritedModel<_FilmsModelAspect> { return InheritedModel.inheritFrom(context, aspect: _FilmsModelAspect.customFilms)! .customFilms .values - .map((value) => value.film) + .map((value) => value.value) .toList(); } @@ -155,8 +155,8 @@ class Films extends InheritedModel<_FilmsModelAspect> { final model = InheritedModel.inheritFrom(context, aspect: _FilmsModelAspect.filmsInUse)!; return [ const FilmStub(), - ...model.customFilms.values.where((e) => e.isUsed).map((e) => e.film), - ...model.predefinedFilms.values.where((e) => e.isUsed).map((e) => e.film), + ...model.customFilms.values.where((e) => e.isUsed).map((e) => e.value), + ...model.predefinedFilms.values.where((e) => e.isUsed).map((e) => e.value), ]; } diff --git a/lib/screens/equipment_profiles/screen_equipment_profiles.dart b/lib/screens/equipment_profiles/screen_equipment_profiles.dart index e5269fb..098e72c 100644 --- a/lib/screens/equipment_profiles/screen_equipment_profiles.dart +++ b/lib/screens/equipment_profiles/screen_equipment_profiles.dart @@ -89,9 +89,12 @@ class _EquipmentProfilesListBuilder extends StatelessWidget { top: index == 0 ? Dimens.paddingM : 0.0, bottom: index == values.length - 1 ? Dimens.paddingM : 0.0, ), - child: ListTile( + child: CheckboxListTile( title: Text(values[index].name), - trailing: IconButton( + controlAffinity: ListTileControlAffinity.leading, + value: false, + onChanged: (value) {}, + secondary: IconButton( onPressed: () => onEdit(values[index]), icon: const Icon(Icons.edit), ), diff --git a/screenshots/generate_screenshots.dart b/screenshots/generate_screenshots.dart index 40dc892..7683649 100644 --- a/screenshots/generate_screenshots.dart +++ b/screenshots/generate_screenshots.dart @@ -23,6 +23,7 @@ import 'package:lightmeter/screens/settings/screen_settings.dart'; import 'package:lightmeter/screens/shared/animated_circular_button/widget_button_circular_animated.dart'; import 'package:lightmeter/screens/timer/screen_timer.dart'; import 'package:lightmeter/utils/platform_utils.dart'; +import 'package:m3_lightmeter_iap/m3_lightmeter_iap.dart'; import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart'; import 'package:shared_preferences/shared_preferences.dart'; @@ -92,7 +93,7 @@ void main() { testWidgets('Generate light theme screenshots', (tester) async { await mockSharedPrefs(theme: ThemeType.light, color: _lightThemeColor); await tester.pumpApplication( - predefinedFilms: [_mockFilm].toFilmsMap(), + predefinedFilms: [_mockFilm].toSelectableMap(), customFilms: {}, selectedFilmId: _mockFilm.id, ); @@ -132,7 +133,7 @@ void main() { (tester) async { await mockSharedPrefs(theme: ThemeType.dark, color: _darkThemeColor); await tester.pumpApplication( - predefinedFilms: [_mockFilm].toFilmsMap(), + predefinedFilms: [_mockFilm].toSelectableMap(), customFilms: {}, selectedFilmId: _mockFilm.id, ); @@ -157,7 +158,7 @@ void main() { color: _lightThemeColor, ); await tester.pumpApplication( - predefinedFilms: [_mockFilm].toFilmsMap(), + predefinedFilms: [_mockFilm].toSelectableMap(), customFilms: {}, selectedFilmId: _mockFilm.id, ); diff --git a/test/providers/equipment_profile_provider_test.dart b/test/providers/equipment_profile_provider_test.dart index d9418a8..8e32395 100644 --- a/test/providers/equipment_profile_provider_test.dart +++ b/test/providers/equipment_profile_provider_test.dart @@ -27,7 +27,7 @@ void main() { ), ).thenAnswer((_) async {}); when(() => storageService.deleteProfile(any())).thenAnswer((_) async {}); - when(() => storageService.getProfiles()).thenAnswer((_) => Future.value(_customProfiles.toProfilesMap())); + when(() => storageService.getProfiles()).thenAnswer((_) => Future.value(_customProfiles.toSelectableMap())); }); tearDown(() { @@ -66,7 +66,7 @@ void main() { () { setUp(() { when(() => storageService.selectedEquipmentProfileId).thenReturn(_customProfiles.first.id); - when(() => storageService.getProfiles()).thenAnswer((_) => Future.value(_customProfiles.toProfilesMap())); + when(() => storageService.getProfiles()).thenAnswer((_) => Future.value(_customProfiles.toSelectableMap())); }); testWidgets( diff --git a/test/providers/films_provider_test.dart b/test/providers/films_provider_test.dart index 258dd37..531a9b8 100644 --- a/test/providers/films_provider_test.dart +++ b/test/providers/films_provider_test.dart @@ -305,6 +305,6 @@ const mockCustomFilms = [ ]; extension on List { - Map toFilmsMap() => - Map.fromEntries(map((e) => MapEntry(e.id, (film: e as T, isUsed: true)))); + Map toFilmsMap() => + Map.fromEntries(map((e) => MapEntry(e.id, (value: e as T, isUsed: true)))); } diff --git a/test/screens/metering/components/shared/readings_container/equipment_profile_picker_test.dart b/test/screens/metering/components/shared/readings_container/equipment_profile_picker_test.dart index 0218bb2..1b22649 100644 --- a/test/screens/metering/components/shared/readings_container/equipment_profile_picker_test.dart +++ b/test/screens/metering/components/shared/readings_container/equipment_profile_picker_test.dart @@ -18,7 +18,7 @@ void main() { setUpAll(() { storageService = _MockEquipmentProfilesStorageService(); - when(() => storageService.getProfiles()).thenAnswer((_) async => _mockEquipmentProfiles.toProfilesMap()); + when(() => storageService.getProfiles()).thenAnswer((_) async => _mockEquipmentProfiles.toSelectableMap()); when(() => storageService.selectedEquipmentProfileId).thenReturn(''); }); diff --git a/test/screens/metering/components/shared/readings_container/film_picker_test.dart b/test/screens/metering/components/shared/readings_container/film_picker_test.dart index 1ea3399..d42aba4 100644 --- a/test/screens/metering/components/shared/readings_container/film_picker_test.dart +++ b/test/screens/metering/components/shared/readings_container/film_picker_test.dart @@ -18,7 +18,7 @@ void main() { setUpAll(() { mockFilmsStorageService = _MockFilmsStorageService(); when(() => mockFilmsStorageService.getPredefinedFilms()).thenAnswer( - (_) => Future.value(Map.fromEntries(_films.map((e) => MapEntry(e.id, (film: e, isUsed: true))))), + (_) => Future.value(Map.fromEntries(_films.map((e) => MapEntry(e.id, (value: e, isUsed: true))))), ); when(() => mockFilmsStorageService.getCustomFilms()).thenAnswer( (_) => Future.value({}), diff --git a/test/screens/metering/utils/listener_equipment_profiles_test.dart b/test/screens/metering/utils/listener_equipment_profiles_test.dart index d5aa0ce..6f1579c 100644 --- a/test/screens/metering/utils/listener_equipment_profiles_test.dart +++ b/test/screens/metering/utils/listener_equipment_profiles_test.dart @@ -26,7 +26,7 @@ void main() { ), ).thenAnswer((_) async {}); when(() => storageService.deleteProfile(any())).thenAnswer((_) async {}); - when(() => storageService.getProfiles()).thenAnswer((_) => Future.value(_customProfiles.toProfilesMap())); + when(() => storageService.getProfiles()).thenAnswer((_) => Future.value(_customProfiles.toSelectableMap())); }); tearDown(() {