|
4 | 4 |
|
5 | 5 | import 'dart:async';
|
6 | 6 | import 'dart:io';
|
7 |
| -import 'dart:ui'; |
| 7 | +import 'dart:ui' as ui; |
8 | 8 |
|
9 | 9 | import 'package:camera/camera.dart';
|
10 |
| -import 'package:flutter/painting.dart'; |
| 10 | +import 'package:camera_example/main.dart'; |
| 11 | +import 'package:flutter/material.dart'; |
11 | 12 | import 'package:flutter_test/flutter_test.dart';
|
12 | 13 | import 'package:path_provider/path_provider.dart';
|
13 | 14 | import 'package:video_player/video_player.dart';
|
@@ -63,7 +64,9 @@ void main() {
|
63 | 64 |
|
64 | 65 | // Load picture
|
65 | 66 | final File fileImage = File(file.path);
|
66 |
| - final Image image = await decodeImageFromList(fileImage.readAsBytesSync()); |
| 67 | + final ui.Image image = await decodeImageFromList( |
| 68 | + fileImage.readAsBytesSync(), |
| 69 | + ); |
67 | 70 |
|
68 | 71 | // Verify image dimensions are as expected
|
69 | 72 | expect(image, isNotNull);
|
@@ -240,4 +243,28 @@ void main() {
|
240 | 243 | },
|
241 | 244 | skip: !Platform.isAndroid,
|
242 | 245 | );
|
| 246 | + |
| 247 | + testWidgets( |
| 248 | + 'Disposed controller removed correctly', |
| 249 | + (WidgetTester tester) async { |
| 250 | + cameras = await availableCameras(); |
| 251 | + if (cameras.isEmpty) { |
| 252 | + return; |
| 253 | + } |
| 254 | + |
| 255 | + // Bump the example. |
| 256 | + await tester.pumpWidget(CameraApp()); |
| 257 | + await tester.pumpAndSettle(const Duration(seconds: 3)); |
| 258 | + |
| 259 | + // Tap to switch to the first camera. |
| 260 | + await tester.tap( |
| 261 | + find.byIcon(getCameraLensIcon(cameras.first.lensDirection)), |
| 262 | + ); |
| 263 | + // Wait a few seconds to make sure the lifecycle changed. |
| 264 | + await tester.pumpAndSettle(const Duration(seconds: 3)); |
| 265 | + // Ensure the controller is no longer depended by widgets. |
| 266 | + final dynamic exception = tester.takeException(); |
| 267 | + expect(exception, isNull); |
| 268 | + }, |
| 269 | + ); |
243 | 270 | }
|
0 commit comments