This repository was archived by the owner on Feb 22, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 4 files changed +42
-4
lines changed
packages/camera/camera_web Expand file tree Collapse file tree 4 files changed +42
-4
lines changed Original file line number Diff line number Diff line change @@ -507,6 +507,24 @@ void main() {
507
507
});
508
508
});
509
509
510
+ group ('getViewType' , () {
511
+ testWidgets ('returns a correct view type' , (tester) async {
512
+ const textureId = 1 ;
513
+
514
+ final camera = Camera (
515
+ textureId: textureId,
516
+ window: window,
517
+ );
518
+
519
+ await camera.initialize ();
520
+
521
+ expect (
522
+ camera.getViewType (),
523
+ equals ('plugins.flutter.io/camera_$textureId ' ),
524
+ );
525
+ });
526
+ });
527
+
510
528
group ('dispose' , () {
511
529
testWidgets ('resets the video element\' s source' , (tester) async {
512
530
final camera = Camera (
Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ import 'package:camera_web/camera_web.dart';
11
11
import 'package:camera_web/src/camera.dart' ;
12
12
import 'package:camera_web/src/camera_settings.dart' ;
13
13
import 'package:camera_web/src/types/types.dart' ;
14
+ import 'package:flutter/widgets.dart' as widgets;
14
15
import 'package:flutter/services.dart' ;
15
16
import 'package:flutter_test/flutter_test.dart' ;
16
17
import 'package:integration_test/integration_test.dart' ;
@@ -634,10 +635,24 @@ void main() {
634
635
);
635
636
});
636
637
637
- testWidgets ('buildPreview throws UnimplementedError' , (tester) async {
638
+ testWidgets (
639
+ 'buildPreview returns an HtmlElementView '
640
+ 'with an appropriate view type' , (tester) async {
641
+ final camera = Camera (
642
+ textureId: cameraId,
643
+ window: window,
644
+ );
645
+
646
+ // Save the camera in the camera plugin.
647
+ (CameraPlatform .instance as CameraPlugin ).cameras[cameraId] = camera;
648
+
638
649
expect (
639
- () => CameraPlatform .instance.buildPreview (cameraId),
640
- throwsUnimplementedError,
650
+ CameraPlatform .instance.buildPreview (cameraId),
651
+ isA< widgets.HtmlElementView > ().having (
652
+ (view) => view.viewType,
653
+ 'viewType' ,
654
+ camera.getViewType (),
655
+ ),
641
656
);
642
657
});
643
658
Original file line number Diff line number Diff line change @@ -196,6 +196,9 @@ class Camera {
196
196
}
197
197
}
198
198
199
+ /// Returns the registered view type of the camera.
200
+ String getViewType () => _getViewType (textureId);
201
+
199
202
/// Disposes the camera by stopping the camera stream
200
203
/// and reloading the camera source.
201
204
void dispose () {
Original file line number Diff line number Diff line change @@ -361,7 +361,9 @@ class CameraPlugin extends CameraPlatform {
361
361
362
362
@override
363
363
Widget buildPreview (int cameraId) {
364
- throw UnimplementedError ('buildPreview() is not implemented.' );
364
+ return HtmlElementView (
365
+ viewType: getCamera (cameraId).getViewType (),
366
+ );
365
367
}
366
368
367
369
@override
You can’t perform that action at this time.
0 commit comments