2023-10-20 14:12:43 +00:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:lightmeter/providers/equipment_profile_provider.dart';
|
|
|
|
import 'package:lightmeter/providers/films_provider.dart';
|
|
|
|
import 'package:m3_lightmeter_iap/m3_lightmeter_iap.dart';
|
|
|
|
import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart';
|
|
|
|
import 'package:mocktail/mocktail.dart';
|
|
|
|
|
2024-11-06 14:28:16 +00:00
|
|
|
class _MockEquipmentProfilesStorageService extends Mock implements EquipmentProfilesStorageService {}
|
2023-10-20 14:12:43 +00:00
|
|
|
|
2024-11-03 19:16:01 +00:00
|
|
|
class _MockFilmsStorageService extends Mock implements FilmsStorageService {}
|
|
|
|
|
2023-10-20 14:12:43 +00:00
|
|
|
class MockIAPProviders extends StatefulWidget {
|
2024-11-06 14:28:16 +00:00
|
|
|
final Map<String, EquipmentProfile> equipmentProfiles;
|
2023-10-20 14:12:43 +00:00
|
|
|
final String selectedEquipmentProfileId;
|
2024-11-03 19:16:01 +00:00
|
|
|
final Map<String, SelectableFilm<Film>> predefinedFilms;
|
|
|
|
final Map<String, SelectableFilm<FilmExponential>> customFilms;
|
|
|
|
final String selectedFilmId;
|
2023-10-20 14:12:43 +00:00
|
|
|
final Widget child;
|
|
|
|
|
2024-11-03 19:16:01 +00:00
|
|
|
MockIAPProviders({
|
2024-11-06 14:28:16 +00:00
|
|
|
Map<String, EquipmentProfile>? equipmentProfiles,
|
2023-10-20 14:12:43 +00:00
|
|
|
this.selectedEquipmentProfileId = '',
|
2024-11-03 19:16:01 +00:00
|
|
|
Map<String, SelectableFilm<Film>>? predefinedFilms,
|
|
|
|
Map<String, SelectableFilm<FilmExponential>>? customFilms,
|
|
|
|
String? selectedFilmId,
|
2023-10-20 14:12:43 +00:00
|
|
|
required this.child,
|
|
|
|
super.key,
|
2024-11-06 14:28:16 +00:00
|
|
|
}) : equipmentProfiles = equipmentProfiles ?? mockEquipmentProfiles.toProfilesMap(),
|
|
|
|
predefinedFilms = predefinedFilms ?? mockFilms.toFilmsMap(),
|
2024-11-03 19:16:01 +00:00
|
|
|
customFilms = customFilms ?? mockFilms.toFilmsMap(),
|
|
|
|
selectedFilmId = selectedFilmId ?? const FilmStub().id;
|
2023-10-20 14:12:43 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
State<MockIAPProviders> createState() => _MockIAPProvidersState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _MockIAPProvidersState extends State<MockIAPProviders> {
|
2024-11-06 14:28:16 +00:00
|
|
|
late final _MockEquipmentProfilesStorageService mockEquipmentProfilesStorageService;
|
2024-11-03 19:16:01 +00:00
|
|
|
late final _MockFilmsStorageService mockFilmsStorageService;
|
2023-10-20 14:12:43 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
super.initState();
|
2024-11-06 14:28:16 +00:00
|
|
|
mockEquipmentProfilesStorageService = _MockEquipmentProfilesStorageService();
|
|
|
|
when(() => mockEquipmentProfilesStorageService.init()).thenAnswer((_) async {});
|
|
|
|
when(() => mockEquipmentProfilesStorageService.getProfiles())
|
|
|
|
.thenAnswer((_) => Future.value(widget.equipmentProfiles));
|
|
|
|
when(() => mockEquipmentProfilesStorageService.selectedEquipmentProfileId)
|
|
|
|
.thenReturn(widget.selectedEquipmentProfileId);
|
2024-11-03 19:16:01 +00:00
|
|
|
|
|
|
|
mockFilmsStorageService = _MockFilmsStorageService();
|
|
|
|
when(() => mockFilmsStorageService.init()).thenAnswer((_) async {});
|
|
|
|
when(() => mockFilmsStorageService.getPredefinedFilms()).thenAnswer((_) => Future.value(widget.predefinedFilms));
|
|
|
|
when(() => mockFilmsStorageService.getCustomFilms()).thenAnswer((_) => Future.value(widget.customFilms));
|
|
|
|
when(() => mockFilmsStorageService.selectedFilmId).thenReturn(widget.selectedFilmId);
|
2023-10-20 14:12:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2024-11-06 14:28:16 +00:00
|
|
|
return EquipmentProfilesProvider(
|
|
|
|
storageService: mockEquipmentProfilesStorageService,
|
2023-10-20 14:12:43 +00:00
|
|
|
child: FilmsProvider(
|
2024-11-06 14:28:16 +00:00
|
|
|
storageService: mockFilmsStorageService,
|
2023-10-20 14:12:43 +00:00
|
|
|
child: widget.child,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const defaultEquipmentProfile = EquipmentProfile(
|
|
|
|
id: '',
|
|
|
|
name: '',
|
|
|
|
apertureValues: ApertureValue.values,
|
|
|
|
ndValues: NdValue.values,
|
|
|
|
shutterSpeedValues: ShutterSpeedValue.values,
|
|
|
|
isoValues: IsoValue.values,
|
|
|
|
);
|
|
|
|
|
|
|
|
final mockEquipmentProfiles = [
|
|
|
|
EquipmentProfile(
|
|
|
|
id: '1',
|
|
|
|
name: 'Praktica + Zenitar',
|
|
|
|
apertureValues: ApertureValue.values.sublist(
|
|
|
|
ApertureValue.values.indexOf(const ApertureValue(1.7, StopType.half)),
|
|
|
|
ApertureValue.values.indexOf(const ApertureValue(16, StopType.full)) + 1,
|
|
|
|
),
|
2024-02-21 11:33:25 +00:00
|
|
|
ndValues: const [
|
|
|
|
NdValue(0),
|
|
|
|
NdValue(2),
|
|
|
|
NdValue(4),
|
|
|
|
NdValue(8),
|
|
|
|
],
|
2023-10-20 14:12:43 +00:00
|
|
|
shutterSpeedValues: ShutterSpeedValue.values.sublist(
|
|
|
|
ShutterSpeedValue.values.indexOf(const ShutterSpeedValue(1000, true, StopType.full)),
|
2024-04-30 10:44:01 +00:00
|
|
|
ShutterSpeedValue.values.indexOf(const ShutterSpeedValue(1, false, StopType.full)) + 1,
|
2023-10-20 14:12:43 +00:00
|
|
|
),
|
|
|
|
isoValues: const [
|
|
|
|
IsoValue(50, StopType.full),
|
|
|
|
IsoValue(100, StopType.full),
|
|
|
|
IsoValue(200, StopType.full),
|
|
|
|
IsoValue(250, StopType.third),
|
|
|
|
IsoValue(400, StopType.full),
|
|
|
|
IsoValue(500, StopType.third),
|
|
|
|
IsoValue(800, StopType.full),
|
|
|
|
IsoValue(1600, StopType.full),
|
|
|
|
IsoValue(3200, StopType.full),
|
|
|
|
],
|
2024-04-07 08:54:57 +00:00
|
|
|
lensZoom: 1.91,
|
2023-10-20 14:12:43 +00:00
|
|
|
),
|
2024-03-13 14:34:26 +00:00
|
|
|
EquipmentProfile(
|
2023-10-20 14:12:43 +00:00
|
|
|
id: '2',
|
|
|
|
name: 'Praktica + Jupiter',
|
2024-03-13 14:34:26 +00:00
|
|
|
apertureValues: ApertureValue.values.sublist(
|
|
|
|
ApertureValue.values.indexOf(const ApertureValue(3.5, StopType.third)),
|
|
|
|
ApertureValue.values.indexOf(const ApertureValue(22, StopType.full)) + 1,
|
|
|
|
),
|
|
|
|
ndValues: const [
|
|
|
|
NdValue(0),
|
|
|
|
NdValue(2),
|
|
|
|
NdValue(4),
|
|
|
|
NdValue(8),
|
|
|
|
],
|
|
|
|
shutterSpeedValues: ShutterSpeedValue.values.sublist(
|
|
|
|
ShutterSpeedValue.values.indexOf(const ShutterSpeedValue(1000, true, StopType.full)),
|
2024-04-30 10:44:01 +00:00
|
|
|
ShutterSpeedValue.values.indexOf(const ShutterSpeedValue(1, false, StopType.full)) + 1,
|
2024-03-13 14:34:26 +00:00
|
|
|
),
|
|
|
|
isoValues: const [
|
|
|
|
IsoValue(50, StopType.full),
|
|
|
|
IsoValue(100, StopType.full),
|
|
|
|
IsoValue(200, StopType.full),
|
|
|
|
IsoValue(250, StopType.third),
|
|
|
|
IsoValue(400, StopType.full),
|
|
|
|
IsoValue(500, StopType.third),
|
|
|
|
IsoValue(800, StopType.full),
|
|
|
|
IsoValue(1600, StopType.full),
|
|
|
|
IsoValue(3200, StopType.full),
|
|
|
|
],
|
2024-04-07 08:54:57 +00:00
|
|
|
lensZoom: 5.02,
|
2023-10-20 14:12:43 +00:00
|
|
|
),
|
|
|
|
];
|
|
|
|
|
2024-11-03 19:16:01 +00:00
|
|
|
const mockFilms = [
|
|
|
|
_FilmMultiplying(id: '1', name: 'Mock film 1', iso: 100, reciprocityMultiplier: 2),
|
|
|
|
_FilmMultiplying(id: '2', name: 'Mock film 2', iso: 400, reciprocityMultiplier: 2),
|
|
|
|
_FilmMultiplying(id: '3', name: 'Mock film 3', iso: 800, reciprocityMultiplier: 3),
|
|
|
|
_FilmMultiplying(id: '4', name: 'Mock film 4', iso: 1200, reciprocityMultiplier: 1.5),
|
|
|
|
];
|
|
|
|
|
2024-11-06 14:28:16 +00:00
|
|
|
extension EquipmentProfileMapper on List<EquipmentProfile> {
|
|
|
|
Map<String, EquipmentProfile> toProfilesMap() => Map.fromEntries(map((e) => MapEntry(e.id, e)));
|
|
|
|
}
|
|
|
|
|
2024-11-03 19:16:01 +00:00
|
|
|
extension FilmMapper on List<Film> {
|
|
|
|
Map<String, ({T film, bool isUsed})> toFilmsMap<T extends Film>({bool isUsed = true}) =>
|
|
|
|
Map.fromEntries(map((e) => MapEntry(e.id, (film: e as T, isUsed: isUsed))));
|
|
|
|
}
|
2023-10-20 14:12:43 +00:00
|
|
|
|
2024-11-03 19:16:01 +00:00
|
|
|
class _FilmMultiplying extends FilmExponential {
|
2023-10-20 14:12:43 +00:00
|
|
|
final double reciprocityMultiplier;
|
|
|
|
|
2024-11-03 19:16:01 +00:00
|
|
|
const _FilmMultiplying({
|
|
|
|
String? id,
|
|
|
|
required String name,
|
|
|
|
required super.iso,
|
|
|
|
required this.reciprocityMultiplier,
|
|
|
|
}) : super(id: id ?? name, name: 'Mock film $iso x$reciprocityMultiplier', exponent: 1);
|
|
|
|
|
|
|
|
@override
|
|
|
|
ShutterSpeedValue reciprocityFailure(ShutterSpeedValue shutterSpeed) {
|
|
|
|
if (shutterSpeed.isFraction) {
|
|
|
|
return shutterSpeed;
|
|
|
|
} else {
|
|
|
|
return ShutterSpeedValue(
|
|
|
|
shutterSpeed.rawValue * reciprocityMultiplier,
|
|
|
|
shutterSpeed.isFraction,
|
|
|
|
shutterSpeed.stopType,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
bool operator ==(Object other) {
|
|
|
|
if (identical(this, other)) return true;
|
|
|
|
if (other.runtimeType != runtimeType) return false;
|
|
|
|
return other is _FilmMultiplying &&
|
|
|
|
other.id == id &&
|
|
|
|
other.name == name &&
|
|
|
|
other.iso == iso &&
|
|
|
|
other.reciprocityMultiplier == reciprocityMultiplier;
|
|
|
|
}
|
2023-10-20 14:12:43 +00:00
|
|
|
|
|
|
|
@override
|
2024-11-03 19:16:01 +00:00
|
|
|
int get hashCode => Object.hash(id, name, iso, reciprocityMultiplier, runtimeType);
|
2023-10-20 14:12:43 +00:00
|
|
|
}
|