diff --git a/packages/camera/camera/CHANGELOG.md b/packages/camera/camera/CHANGELOG.md index d0d58be6ca9..97a41bea6c8 100644 --- a/packages/camera/camera/CHANGELOG.md +++ b/packages/camera/camera/CHANGELOG.md @@ -1,3 +1,7 @@ +## NEXT + +* Fixes overflowed toggles in the camera example. + ## 0.11.1 * Adds API support query for image streaming. diff --git a/packages/camera/camera/example/lib/main.dart b/packages/camera/camera/example/lib/main.dart index cda92aadfd3..a11d0f7083e 100644 --- a/packages/camera/camera/example/lib/main.dart +++ b/packages/camera/camera/example/lib/main.dart @@ -225,43 +225,33 @@ class _CameraExampleHomeState extends State /// Display the thumbnail of the captured image or video. Widget _thumbnailWidget() { - final VideoPlayerController? localVideoController = videoController; - - return Expanded( - child: Align( - alignment: Alignment.centerRight, - child: Row( - mainAxisSize: MainAxisSize.min, - children: [ - if (localVideoController == null && imageFile == null) - Container() - else - SizedBox( - width: 64.0, - height: 64.0, - child: (localVideoController == null) - ? ( - // The captured image on the web contains a network-accessible URL - // pointing to a location within the browser. It may be displayed - // either with Image.network or Image.memory after loading the image - // bytes to memory. - kIsWeb - ? Image.network(imageFile!.path) - : Image.file(File(imageFile!.path))) - : Container( - decoration: BoxDecoration( - border: Border.all(color: Colors.pink)), - child: Center( - child: AspectRatio( - aspectRatio: - localVideoController.value.aspectRatio, - child: VideoPlayer(localVideoController)), - ), - ), + return Row( + mainAxisSize: MainAxisSize.min, + children: [ + if (videoController case final VideoPlayerController controller?) + Container( + width: 64.0, + height: 64.0, + decoration: BoxDecoration(border: Border.all(color: Colors.pink)), + child: Center( + child: AspectRatio( + aspectRatio: controller.value.aspectRatio, + child: VideoPlayer(controller), ), - ], - ), - ), + ), + ) + else if (imageFile?.path case final String path) + Container( + width: 64.0, + height: 64.0, + decoration: BoxDecoration(border: Border.all(color: Colors.pink)), + // The captured image on the web contains a network-accessible URL + // pointing to a location within the browser. It may be displayed + // either with Image.network or Image.memory after loading the image + // bytes to memory. + child: kIsWeb ? Image.network(path) : Image.file(File(path)), + ), + ], ); } @@ -598,7 +588,12 @@ class _CameraExampleHomeState extends State } } - return Row(children: toggles); + return Expanded( + child: SizedBox( + height: 56.0, + child: ListView(scrollDirection: Axis.horizontal, children: toggles), + ), + ); } String timestamp() => DateTime.now().millisecondsSinceEpoch.toString(); @@ -1048,6 +1043,9 @@ class CameraApp extends StatelessWidget { } } +/// Getting available cameras for testing. +@visibleForTesting +List get cameras => _cameras; List _cameras = []; Future main() async { diff --git a/packages/camera/camera/example/test/main_test.dart b/packages/camera/camera/example/test/main_test.dart index 6e909efcfc6..eb75a29f8ed 100644 --- a/packages/camera/camera/example/test/main_test.dart +++ b/packages/camera/camera/example/test/main_test.dart @@ -2,6 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +import 'package:camera/camera.dart'; import 'package:camera_example/main.dart'; import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; @@ -13,4 +14,23 @@ void main() { await tester.pumpAndSettle(); expect(find.byType(SnackBar), findsOneWidget); }); + + testWidgets( + 'CameraDescription toggles will not overflow', + (WidgetTester tester) async { + WidgetsFlutterBinding.ensureInitialized(); + // Adds 10 fake camera descriptions. + for (int i = 0; i < 10; i++) { + cameras.add( + CameraDescription( + name: 'camera_$i', + lensDirection: CameraLensDirection.back, + sensorOrientation: 90, + ), + ); + } + await tester.pumpWidget(const CameraApp()); + await tester.pumpAndSettle(); + }, + ); }