22// Use of this source code is governed by a BSD-style license that can be
33// found in the LICENSE file.
44
5+ // ignore_for_file: public_member_api_docs
6+
57import 'dart:async' ;
68import 'dart:io' ;
79
@@ -11,13 +13,9 @@ import 'package:flutter/material.dart';
1113import 'package:flutter/scheduler.dart' ;
1214import 'package:video_player/video_player.dart' ;
1315
14- /// Camera example home widget.
1516class CameraExampleHome extends StatefulWidget {
16- /// Default Constructor
17- const CameraExampleHome ({Key ? key}) : super (key: key);
18-
1917 @override
20- State < CameraExampleHome > createState () {
18+ _CameraExampleHomeState createState () {
2119 return _CameraExampleHomeState ();
2220 }
2321}
@@ -36,7 +34,7 @@ IconData getCameraLensIcon(CameraLensDirection direction) {
3634 }
3735}
3836
39- void _logError (String code, String ? message) {
37+ void logError (String code, String ? message) {
4038 if (message != null ) {
4139 print ('Error: $code \n Error Message: $message ' );
4240 } else {
@@ -136,6 +134,12 @@ class _CameraExampleHomeState extends State<CameraExampleHome>
136134 children: < Widget > [
137135 Expanded (
138136 child: Container (
137+ child: Padding (
138+ padding: const EdgeInsets .all (1.0 ),
139+ child: Center (
140+ child: _cameraPreviewWidget (),
141+ ),
142+ ),
139143 decoration: BoxDecoration (
140144 color: Colors .black,
141145 border: Border .all (
@@ -146,12 +150,6 @@ class _CameraExampleHomeState extends State<CameraExampleHome>
146150 width: 3.0 ,
147151 ),
148152 ),
149- child: Padding (
150- padding: const EdgeInsets .all (1.0 ),
151- child: Center (
152- child: _cameraPreviewWidget (),
153- ),
154- ),
155153 ),
156154 ),
157155 _captureControlRowWidget (),
@@ -235,8 +233,6 @@ class _CameraExampleHomeState extends State<CameraExampleHome>
235233 Container ()
236234 else
237235 SizedBox (
238- width: 64.0 ,
239- height: 64.0 ,
240236 child: (localVideoController == null )
241237 ? (
242238 // The captured image on the web contains a network-accessible URL
@@ -247,8 +243,6 @@ class _CameraExampleHomeState extends State<CameraExampleHome>
247243 ? Image .network (imageFile! .path)
248244 : Image .file (File (imageFile! .path)))
249245 : Container (
250- decoration: BoxDecoration (
251- border: Border .all (color: Colors .pink)),
252246 child: Center (
253247 child: AspectRatio (
254248 aspectRatio:
@@ -257,7 +251,11 @@ class _CameraExampleHomeState extends State<CameraExampleHome>
257251 : 1.0 ,
258252 child: VideoPlayer (localVideoController)),
259253 ),
254+ decoration: BoxDecoration (
255+ border: Border .all (color: Colors .pink)),
260256 ),
257+ width: 64.0 ,
258+ height: 64.0 ,
261259 ),
262260 ],
263261 ),
@@ -396,6 +394,7 @@ class _CameraExampleHomeState extends State<CameraExampleHome>
396394 mainAxisSize: MainAxisSize .max,
397395 children: < Widget > [
398396 TextButton (
397+ child: const Text ('AUTO' ),
399398 style: styleAuto,
400399 onPressed: controller != null
401400 ? () =>
@@ -407,22 +406,21 @@ class _CameraExampleHomeState extends State<CameraExampleHome>
407406 showInSnackBar ('Resetting exposure point' );
408407 }
409408 },
410- child: const Text ('AUTO' ),
411409 ),
412410 TextButton (
411+ child: const Text ('LOCKED' ),
413412 style: styleLocked,
414413 onPressed: controller != null
415414 ? () =>
416415 onSetExposureModeButtonPressed (ExposureMode .locked)
417416 : null ,
418- child: const Text ('LOCKED' ),
419417 ),
420418 TextButton (
419+ child: const Text ('RESET OFFSET' ),
421420 style: styleLocked,
422421 onPressed: controller != null
423422 ? () => controller! .setExposureOffset (0.0 )
424423 : null ,
425- child: const Text ('RESET OFFSET' ),
426424 ),
427425 ],
428426 ),
@@ -481,6 +479,7 @@ class _CameraExampleHomeState extends State<CameraExampleHome>
481479 mainAxisSize: MainAxisSize .max,
482480 children: < Widget > [
483481 TextButton (
482+ child: const Text ('AUTO' ),
484483 style: styleAuto,
485484 onPressed: controller != null
486485 ? () => onSetFocusModeButtonPressed (FocusMode .auto)
@@ -491,14 +490,13 @@ class _CameraExampleHomeState extends State<CameraExampleHome>
491490 }
492491 showInSnackBar ('Resetting focus point' );
493492 },
494- child: const Text ('AUTO' ),
495493 ),
496494 TextButton (
495+ child: const Text ('LOCKED' ),
497496 style: styleLocked,
498497 onPressed: controller != null
499498 ? () => onSetFocusModeButtonPressed (FocusMode .locked)
500499 : null ,
501- child: const Text ('LOCKED' ),
502500 ),
503501 ],
504502 ),
@@ -584,13 +582,13 @@ class _CameraExampleHomeState extends State<CameraExampleHome>
584582 onNewCameraSelected (description);
585583 };
586584
587- if (_cameras .isEmpty) {
585+ if (cameras .isEmpty) {
588586 _ambiguate (SchedulerBinding .instance)? .addPostFrameCallback ((_) async {
589587 showInSnackBar ('No camera found.' );
590588 });
591589 return const Text ('None' );
592590 } else {
593- for (final CameraDescription cameraDescription in _cameras ) {
591+ for (final CameraDescription cameraDescription in cameras ) {
594592 toggles.add (
595593 SizedBox (
596594 width: 90.0 ,
@@ -1016,35 +1014,31 @@ class _CameraExampleHomeState extends State<CameraExampleHome>
10161014 }
10171015
10181016 void _showCameraException (CameraException e) {
1019- _logError (e.code, e.description);
1017+ logError (e.code, e.description);
10201018 showInSnackBar ('Error: ${e .code }\n ${e .description }' );
10211019 }
10221020}
10231021
1024- /// CameraApp is the Main Application.
10251022class CameraApp extends StatelessWidget {
1026- /// Default Constructor
1027- const CameraApp ({Key ? key}) : super (key: key);
1028-
10291023 @override
10301024 Widget build (BuildContext context) {
1031- return const MaterialApp (
1025+ return MaterialApp (
10321026 home: CameraExampleHome (),
10331027 );
10341028 }
10351029}
10361030
1037- List <CameraDescription > _cameras = < CameraDescription > [];
1031+ List <CameraDescription > cameras = < CameraDescription > [];
10381032
10391033Future <void > main () async {
10401034 // Fetch the available cameras before initializing the app.
10411035 try {
10421036 WidgetsFlutterBinding .ensureInitialized ();
1043- _cameras = await availableCameras ();
1037+ cameras = await availableCameras ();
10441038 } on CameraException catch (e) {
1045- _logError (e.code, e.description);
1039+ logError (e.code, e.description);
10461040 }
1047- runApp (const CameraApp ());
1041+ runApp (CameraApp ());
10481042}
10491043
10501044/// This allows a value of type T or T? to be treated as a value of type T?.
0 commit comments