sync with resources

This commit is contained in:
Vadim 2024-10-06 20:26:40 +02:00
parent 98262fc4ee
commit 4498167ddc
10 changed files with 40 additions and 61 deletions

View file

@ -9,7 +9,7 @@ class IAPStorageService {
List<EquipmentProfile> get equipmentProfiles => [];
set equipmentProfiles(List<EquipmentProfile> profiles) {}
Film get selectedFilm => const Film.other();
Film get selectedFilm => const FilmStub();
set selectedFilm(Film value) {}
List<Film> get filmsInUse => [];

View file

@ -20,7 +20,7 @@ class MockIAPProviders extends StatefulWidget {
this.selectedEquipmentProfileId = '',
List<Film>? availableFilms,
List<Film>? filmsInUse,
this.selectedFilm = const Film.other(),
this.selectedFilm = const FilmStub(),
required this.child,
super.key,
}) : availableFilms = availableFilms ?? mockFilms,
@ -128,13 +128,9 @@ final mockEquipmentProfiles = [
),
];
const mockFilms = [_MockFilm(100, 2), _MockFilm(400, 2), _MockFilm(3, 800), _MockFilm(400, 1.5)];
class _MockFilm extends Film {
final double reciprocityMultiplier;
const _MockFilm(int iso, this.reciprocityMultiplier) : super('Mock film $iso x$reciprocityMultiplier', iso);
@override
double reciprocityFormula(double t) => t * reciprocityMultiplier;
}
const mockFilms = [
FilmExponential(id: '1', name: 'Mock film 1', iso: 100, exponent: 1.34),
FilmExponential(id: '2', name: 'Mock film 2', iso: 400, exponent: 1.34),
FilmExponential(id: '3', name: 'Mock film 3', iso: 800, exponent: 1.34),
FilmExponential(id: '4', name: 'Mock film 4', iso: 1200, exponent: 1.34),
];

View file

@ -24,7 +24,7 @@ extension WidgetTesterCommonActions on WidgetTester {
String selectedEquipmentProfileId = '',
List<Film>? availableFilms,
List<Film>? filmsInUse,
Film selectedFilm = const Film.other(),
Film selectedFilm = const FilmStub(),
}) async {
await pumpWidget(
MockIAPProductsProvider(

View file

@ -40,14 +40,14 @@ class FilmsProviderState extends State<FilmsProvider> {
Widget build(BuildContext context) {
return Films(
values: [
const Film.other(),
const FilmStub(),
...widget.availableFilms ?? films,
],
filmsInUse: [
const Film.other(),
const FilmStub(),
if (context.isPro) ..._filmsInUse,
],
selected: context.isPro ? _selected : const Film.other(),
selected: context.isPro ? _selected : const FilmStub(),
child: widget.child,
);
}
@ -68,9 +68,9 @@ class FilmsProviderState extends State<FilmsProvider> {
}
void _discardSelectedIfNotIncluded() {
if (_selected != const Film.other() && !_filmsInUse.contains(_selected)) {
_selected = const Film.other();
widget.storageService.selectedFilm = const Film.other();
if (_selected != const FilmStub() && !_filmsInUse.contains(_selected)) {
_selected = const FilmStub();
widget.storageService.selectedFilm = const FilmStub();
}
}
}
@ -86,12 +86,12 @@ class Films extends SelectableInheritedModel<Film> {
required super.child,
});
/// [Film.other()] + all the custom fields with actual reciprocity formulas
/// [FilmStub()] + all the custom fields with actual reciprocity formulas
static List<Film> of(BuildContext context) {
return InheritedModel.inheritFrom<Films>(context)!.values;
}
/// [Film.other()] + films in use selected by user
/// [FilmStub()] + films in use selected by user
static List<Film> inUseOf<T>(BuildContext context) {
return InheritedModel.inheritFrom<Films>(
context,

View file

@ -30,7 +30,7 @@ class FilmPicker extends StatelessWidget {
}
String _label(BuildContext context) {
if (Films.selectedOf(context) == const Film.other() || Films.selectedOf(context).iso == selectedIso.value) {
if (Films.selectedOf(context) == const FilmStub() || Films.selectedOf(context).iso == selectedIso.value) {
return S.of(context).film;
}

View file

@ -39,7 +39,7 @@ class MeteringScreenLayoutListTile extends StatelessWidget {
EquipmentProfileProvider.of(context).setProfile(EquipmentProfiles.of(context).first);
}
if (!value[MeteringScreenLayoutFeature.filmPicker]!) {
FilmsProvider.of(context).setFilm(const Film.other());
FilmsProvider.of(context).setFilm(const FilmStub());
}
UserPreferencesProvider.of(context).setMeteringScreenLayout(value);
},

View file

@ -32,7 +32,7 @@ import 'models/screenshot_args.dart';
//https://stackoverflow.com/a/67186625/13167574
const _mockFilm = Film('Ilford HP5+', 400);
const _mockFilm = FilmExponential(id: '1', name: 'Ilford HP5+', iso: 400, exponent: 1.34);
final Color _lightThemeColor = primaryColorsList[5];
final Color _darkThemeColor = primaryColorsList[3];
final ThemeData _themeLight = themeFrom(_lightThemeColor, Brightness.light);

View file

@ -96,7 +96,7 @@ void main() {
testWidgets(
'Select films in use',
(tester) async {
when(() => mockIAPStorageService.selectedFilm).thenReturn(const Film.other());
when(() => mockIAPStorageService.selectedFilm).thenReturn(const FilmStub());
when(() => mockIAPStorageService.filmsInUse).thenReturn([]);
/// Init
@ -113,14 +113,14 @@ void main() {
expectSelectedFilmName('');
verify(() => mockIAPStorageService.filmsInUse = mockFilms.skip(0).toList()).called(1);
verifyNever(() => mockIAPStorageService.selectedFilm = const Film.other());
verifyNever(() => mockIAPStorageService.selectedFilm = const FilmStub());
},
);
testWidgets(
'Select film',
(tester) async {
when(() => mockIAPStorageService.selectedFilm).thenReturn(const Film.other());
when(() => mockIAPStorageService.selectedFilm).thenReturn(const FilmStub());
when(() => mockIAPStorageService.filmsInUse).thenReturn(mockFilms);
/// Init
@ -156,14 +156,14 @@ void main() {
expectSelectedFilmName('');
verifyNever(() => mockIAPStorageService.filmsInUse = any<List<Film>>());
verify(() => mockIAPStorageService.selectedFilm = const Film.other()).called(1);
verify(() => mockIAPStorageService.selectedFilm = const FilmStub()).called(1);
},
);
testWidgets(
'None film selected',
(tester) async {
when(() => mockIAPStorageService.selectedFilm).thenReturn(const Film.other());
when(() => mockIAPStorageService.selectedFilm).thenReturn(const FilmStub());
when(() => mockIAPStorageService.filmsInUse).thenReturn([]);
/// Init
@ -172,7 +172,7 @@ void main() {
expectSelectedFilmName('');
verifyNever(() => mockIAPStorageService.filmsInUse = any<List<Film>>());
verifyNever(() => mockIAPStorageService.selectedFilm = const Film.other());
verifyNever(() => mockIAPStorageService.selectedFilm = const FilmStub());
},
);
},
@ -198,7 +198,7 @@ void main() {
expectSelectedFilmName('');
verify(() => mockIAPStorageService.filmsInUse = mockFilms.skip(1).toList()).called(1);
verify(() => mockIAPStorageService.selectedFilm = const Film.other()).called(1);
verify(() => mockIAPStorageService.selectedFilm = const FilmStub()).called(1);
},
);
},
@ -252,25 +252,8 @@ class _Application extends StatelessWidget {
}
}
const mockFilms = [_MockFilm2x(), _MockFilm3x(), _MockFilm4x()];
class _MockFilm2x extends Film {
const _MockFilm2x() : super('Mock film 2x', 400);
@override
double reciprocityFormula(double t) => t * 2;
}
class _MockFilm3x extends Film {
const _MockFilm3x() : super('Mock film 3x', 800);
@override
double reciprocityFormula(double t) => t * 3;
}
class _MockFilm4x extends Film {
const _MockFilm4x() : super('Mock film 4x', 1600);
@override
double reciprocityFormula(double t) => t * 4;
}
const mockFilms = [
FilmExponential(id: '1', name: 'Mock film 2x', iso: 400, exponent: 1.34),
FilmExponential(id: '2', name: 'Mock film 3x', iso: 800, exponent: 1.34),
FilmExponential(id: '3', name: 'Mock film 4x', iso: 1200, exponent: 1.34),
];

View file

@ -50,9 +50,9 @@ extension WidgetTesterActions on WidgetTester {
}) async {
await pumpWidget(
Films(
values: const [Film.other()],
filmsInUse: const [Film.other()],
selected: const Film.other(),
values: const [FilmStub()],
filmsInUse: const [FilmStub()],
selected: const FilmStub(),
child: WidgetTestApplicationMock(
child: Row(
children: [

View file

@ -51,7 +51,7 @@ void main() {
testWidgets(
'Film.other()',
(tester) async {
when(() => mockIAPStorageService.selectedFilm).thenReturn(const Film.other());
when(() => mockIAPStorageService.selectedFilm).thenReturn(const FilmStub());
await pumpApplication(tester);
expectReadingValueContainerText(S.current.film);
expectReadingValueContainerText(S.current.none);
@ -104,8 +104,8 @@ void main() {
}
const _films = [
Film('ISO 100 Film', 100),
Film('ISO 400 Film', 400),
Film('ISO 800 Film', 800),
Film('ISO 1600 Film', 1600),
FilmExponential(id: '', name: 'ISO 100 Film', iso: 100, exponent: 1.34),
FilmExponential(id: '', name: 'ISO 400 Film', iso: 400, exponent: 1.34),
FilmExponential(id: '', name: 'ISO 800 Film', iso: 800, exponent: 1.34),
FilmExponential(id: '', name: 'ISO 1600 Film', iso: 1600, exponent: 1.34),
];