mirror of
https://github.com/vodemn/m3_lightmeter.git
synced 2024-11-26 09:20:45 +00:00
added stub image for camera
This commit is contained in:
parent
ee5befb68e
commit
1cf4793a9c
9 changed files with 101 additions and 49 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -60,3 +60,4 @@ ios/Runner/GoogleService-Info.plist
|
||||||
/lib/firebase_options.dart
|
/lib/firebase_options.dart
|
||||||
|
|
||||||
coverage/
|
coverage/
|
||||||
|
screenshots/
|
BIN
assets/camera_stub_image.jpg
Normal file
BIN
assets/camera_stub_image.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 899 KiB |
|
@ -61,7 +61,7 @@ void main() {
|
||||||
|
|
||||||
setUpAll(() {
|
setUpAll(() {
|
||||||
mockUserPreferencesService = _MockUserPreferencesService();
|
mockUserPreferencesService = _MockUserPreferencesService();
|
||||||
when(() => mockUserPreferencesService.evSourceType).thenReturn(EvSourceType.sensor);
|
when(() => mockUserPreferencesService.evSourceType).thenReturn(EvSourceType.camera);
|
||||||
when(() => mockUserPreferencesService.stopType).thenReturn(StopType.third);
|
when(() => mockUserPreferencesService.stopType).thenReturn(StopType.third);
|
||||||
when(() => mockUserPreferencesService.locale).thenReturn(SupportedLocale.en);
|
when(() => mockUserPreferencesService.locale).thenReturn(SupportedLocale.en);
|
||||||
when(() => mockUserPreferencesService.caffeine).thenReturn(true);
|
when(() => mockUserPreferencesService.caffeine).thenReturn(true);
|
||||||
|
@ -143,14 +143,16 @@ void main() {
|
||||||
/// Generates several screenshots with the light theme
|
/// Generates several screenshots with the light theme
|
||||||
/// and the additionally the first one with the dark theme
|
/// and the additionally the first one with the dark theme
|
||||||
void generateScreenshots(Color color) {
|
void generateScreenshots(Color color) {
|
||||||
testWidgets(
|
testWidgets('${color.value}_light', (tester) async {
|
||||||
'${color.value}_light',
|
when(() => mockUserPreferencesService.themeType).thenReturn(ThemeType.light);
|
||||||
(tester) async {
|
|
||||||
when(() => mockUserPreferencesService.primaryColor).thenReturn(color);
|
when(() => mockUserPreferencesService.primaryColor).thenReturn(color);
|
||||||
await pumpApplication(tester);
|
await pumpApplication(tester);
|
||||||
|
|
||||||
//await tester.takeScreenshot(binding, '${color.value}_metering_reflected');
|
await tester.takePhoto();
|
||||||
|
await tester.takeScreenshot(binding, '${color.value}_metering_reflected');
|
||||||
|
|
||||||
|
await tester.tap(find.byTooltip(S.current.tooltipUseLightSensor));
|
||||||
|
await tester.pumpAndSettle();
|
||||||
await tester.tap(find.byType(MeteringMeasureButton));
|
await tester.tap(find.byType(MeteringMeasureButton));
|
||||||
await tester.tap(find.byType(MeteringMeasureButton));
|
await tester.tap(find.byType(MeteringMeasureButton));
|
||||||
await tester.takeScreenshot(binding, '${color.value}_metering_incident');
|
await tester.takeScreenshot(binding, '${color.value}_metering_incident');
|
||||||
|
@ -182,9 +184,7 @@ void main() {
|
||||||
await tester.tap(find.byIcon(Icons.iso).first);
|
await tester.tap(find.byIcon(Icons.iso).first);
|
||||||
await tester.pumpAndSettle();
|
await tester.pumpAndSettle();
|
||||||
await tester.takeScreenshot(binding, '${color.value}_equipment_profiles_iso_picker');
|
await tester.takeScreenshot(binding, '${color.value}_equipment_profiles_iso_picker');
|
||||||
},
|
});
|
||||||
skip: true,
|
|
||||||
);
|
|
||||||
|
|
||||||
testWidgets(
|
testWidgets(
|
||||||
'${color.value}_dark',
|
'${color.value}_dark',
|
||||||
|
@ -193,8 +193,11 @@ void main() {
|
||||||
when(() => mockUserPreferencesService.primaryColor).thenReturn(color);
|
when(() => mockUserPreferencesService.primaryColor).thenReturn(color);
|
||||||
await pumpApplication(tester);
|
await pumpApplication(tester);
|
||||||
|
|
||||||
//await tester.takeScreenshot(binding, '${color.value}_metering_reflected');
|
await tester.takePhoto();
|
||||||
|
await tester.takeScreenshot(binding, '${color.value}_metering_reflected');
|
||||||
|
|
||||||
|
await tester.tap(find.byTooltip(S.current.tooltipUseLightSensor));
|
||||||
|
await tester.pumpAndSettle();
|
||||||
await tester.tap(find.byType(MeteringMeasureButton));
|
await tester.tap(find.byType(MeteringMeasureButton));
|
||||||
await tester.tap(find.byType(MeteringMeasureButton));
|
await tester.tap(find.byType(MeteringMeasureButton));
|
||||||
await tester.takeScreenshot(binding, '${color.value}_metering_incident_dark');
|
await tester.takeScreenshot(binding, '${color.value}_metering_incident_dark');
|
||||||
|
@ -217,6 +220,12 @@ extension on WidgetTester {
|
||||||
await pumpAndSettle();
|
await pumpAndSettle();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<void> takePhoto() async {
|
||||||
|
await tap(find.byType(MeteringMeasureButton));
|
||||||
|
await pump(const Duration(seconds: 2)); // wait for circular progress indicator
|
||||||
|
await pumpAndSettle();
|
||||||
|
}
|
||||||
|
|
||||||
Future<void> tapCancelButton() async {
|
Future<void> tapCancelButton() async {
|
||||||
final cancelButton = find.byWidgetPredicate(
|
final cancelButton = find.byWidgetPredicate(
|
||||||
(widget) =>
|
(widget) =>
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
flutter drive \
|
flutter drive \
|
||||||
--dart-define="cameraPreviewAspectRatio=240/320" \
|
--dart-define="cameraPreviewAspectRatio=240/320" \
|
||||||
|
--dart-define="cameraStubImage=assets/camera_stub_image.jpg" \
|
||||||
--driver=test_driver/screenshot_driver.dart \
|
--driver=test_driver/screenshot_driver.dart \
|
||||||
--target=integration_test/generate_screenshots.dart \
|
--target=integration_test/generate_screenshots.dart \
|
||||||
--profile \
|
--profile \
|
||||||
|
|
|
@ -5,4 +5,6 @@ class PlatformConfig {
|
||||||
final rational = const String.fromEnvironment('cameraPreviewAspectRatio').split('/');
|
final rational = const String.fromEnvironment('cameraPreviewAspectRatio').split('/');
|
||||||
return int.parse(rational[0]) / int.parse(rational[1]);
|
return int.parse(rational[0]) / int.parse(rational[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static String get cameraStubImage => const String.fromEnvironment('cameraStubImage');
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,8 +7,10 @@ import 'dart:typed_data';
|
||||||
import 'package:camera/camera.dart';
|
import 'package:camera/camera.dart';
|
||||||
import 'package:exif/exif.dart';
|
import 'package:exif/exif.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter/services.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:lightmeter/interactors/metering_interactor.dart';
|
import 'package:lightmeter/interactors/metering_interactor.dart';
|
||||||
|
import 'package:lightmeter/platform_config.dart';
|
||||||
import 'package:lightmeter/screens/metering/communication/bloc_communication_metering.dart';
|
import 'package:lightmeter/screens/metering/communication/bloc_communication_metering.dart';
|
||||||
import 'package:lightmeter/screens/metering/communication/event_communication_metering.dart'
|
import 'package:lightmeter/screens/metering/communication/event_communication_metering.dart'
|
||||||
as communication_event;
|
as communication_event;
|
||||||
|
@ -32,7 +34,7 @@ class CameraContainerBloc extends EvSourceBlocBase<CameraContainerEvent, CameraC
|
||||||
|
|
||||||
static const _exposureMaxRange = RangeValues(-4, 4);
|
static const _exposureMaxRange = RangeValues(-4, 4);
|
||||||
RangeValues? _exposureOffsetRange;
|
RangeValues? _exposureOffsetRange;
|
||||||
double _exposureStep = 0.0;
|
double _exposureStep = 0.1;
|
||||||
double _currentExposureOffset = 0.0;
|
double _currentExposureOffset = 0.0;
|
||||||
|
|
||||||
double? _ev100 = 0.0;
|
double? _ev100 = 0.0;
|
||||||
|
@ -199,21 +201,28 @@ class CameraContainerBloc extends EvSourceBlocBase<CameraContainerEvent, CameraC
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool get _canTakePhoto => !(_cameraController == null ||
|
bool get _canTakePhoto =>
|
||||||
|
PlatformConfig.cameraStubImage.isNotEmpty ||
|
||||||
|
!(_cameraController == null ||
|
||||||
!_cameraController!.value.isInitialized ||
|
!_cameraController!.value.isInitialized ||
|
||||||
_cameraController!.value.isTakingPicture);
|
_cameraController!.value.isTakingPicture);
|
||||||
|
|
||||||
Future<double?> _takePhoto() async {
|
Future<double?> _takePhoto() async {
|
||||||
try {
|
try {
|
||||||
// https://github.com/flutter/flutter/issues/84957#issuecomment-1661155095
|
// https://github.com/flutter/flutter/issues/84957#issuecomment-1661155095
|
||||||
|
|
||||||
|
late final Uint8List bytes;
|
||||||
|
if (PlatformConfig.cameraStubImage.isNotEmpty) {
|
||||||
|
bytes = (await rootBundle.load(PlatformConfig.cameraStubImage)).buffer.asUint8List();
|
||||||
|
} else {
|
||||||
await _cameraController!.setFocusMode(FocusMode.locked);
|
await _cameraController!.setFocusMode(FocusMode.locked);
|
||||||
await _cameraController!.setExposureMode(ExposureMode.locked);
|
await _cameraController!.setExposureMode(ExposureMode.locked);
|
||||||
final file = await _cameraController!.takePicture();
|
final file = await _cameraController!.takePicture();
|
||||||
await _cameraController!.setFocusMode(FocusMode.auto);
|
await _cameraController!.setFocusMode(FocusMode.auto);
|
||||||
await _cameraController!.setExposureMode(ExposureMode.auto);
|
await _cameraController!.setExposureMode(ExposureMode.auto);
|
||||||
|
bytes = await file.readAsBytes();
|
||||||
final Uint8List bytes = await file.readAsBytes();
|
|
||||||
Directory(file.path).deleteSync(recursive: true);
|
Directory(file.path).deleteSync(recursive: true);
|
||||||
|
}
|
||||||
|
|
||||||
final tags = await readExifFromBytes(bytes);
|
final tags = await readExifFromBytes(bytes);
|
||||||
final iso = double.tryParse("${tags["EXIF ISOSpeedRatings"]}");
|
final iso = double.tryParse("${tags["EXIF ISOSpeedRatings"]}");
|
||||||
|
|
|
@ -69,6 +69,9 @@ class _CameraPreviewBuilderState extends State<_CameraPreviewBuilder> {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
if (PlatformConfig.cameraStubImage.isNotEmpty) {
|
||||||
|
return Image.asset(PlatformConfig.cameraStubImage);
|
||||||
|
}
|
||||||
return ValueListenableBuilder<bool>(
|
return ValueListenableBuilder<bool>(
|
||||||
valueListenable: _initializedNotifier,
|
valueListenable: _initializedNotifier,
|
||||||
builder: (context, value, child) => value
|
builder: (context, value, child) => value
|
||||||
|
|
|
@ -54,6 +54,8 @@ dev_dependencies:
|
||||||
|
|
||||||
flutter:
|
flutter:
|
||||||
uses-material-design: true
|
uses-material-design: true
|
||||||
|
assets:
|
||||||
|
- assets/camera_stub_image.jpg
|
||||||
|
|
||||||
flutter_intl:
|
flutter_intl:
|
||||||
enabled: true
|
enabled: true
|
||||||
|
|
|
@ -4,6 +4,31 @@ import 'package:integration_test/integration_test_driver_extended.dart';
|
||||||
|
|
||||||
Future<void> main() async {
|
Future<void> main() async {
|
||||||
try {
|
try {
|
||||||
|
final bool adbExists = Process.runSync('which', <String>['adb']).exitCode == 0;
|
||||||
|
if (!adbExists) {
|
||||||
|
log(r'This test needs ADB to exist on the $PATH. Skipping...');
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
final deviceId = await Process.run('adb', ["-s", 'shell', 'devices']).then((value) {
|
||||||
|
if (value.stdout is String) {
|
||||||
|
return RegExp(r"(?:List of devices attached\n)([A-Z0-9]*)(?:\sdevice\n)")
|
||||||
|
.firstMatch(value.stdout as String)!
|
||||||
|
.group(1);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (deviceId == null) {
|
||||||
|
log('This test needs at least one device connected');
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
await Process.run('adb', [
|
||||||
|
"-s",
|
||||||
|
deviceId, // https://github.com/flutter/flutter/issues/86295#issuecomment-1192766368
|
||||||
|
'shell',
|
||||||
|
'pm',
|
||||||
|
'grant',
|
||||||
|
'com.vodemn.lightmeter.dev',
|
||||||
|
'android.permission.CAMERA'
|
||||||
|
]);
|
||||||
await integrationDriver(
|
await integrationDriver(
|
||||||
onScreenshot: (name, bytes, [args]) async {
|
onScreenshot: (name, bytes, [args]) async {
|
||||||
final File image = await File('screenshots/$name.png').create(recursive: true);
|
final File image = await File('screenshots/$name.png').create(recursive: true);
|
||||||
|
|
Loading…
Reference in a new issue