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-
75import 'dart:async' ;
86import 'dart:io' ;
97
@@ -13,9 +11,13 @@ import 'package:flutter/material.dart';
1311import 'package:flutter/scheduler.dart' ;
1412import 'package:video_player/video_player.dart' ;
1513
14+ /// Camera example home widget.
1615class CameraExampleHome extends StatefulWidget {
16+ /// Default Constructor
17+ const CameraExampleHome ({Key ? key}) : super (key: key);
18+
1719 @override
18- _CameraExampleHomeState createState () {
20+ State < CameraExampleHome > createState () {
1921 return _CameraExampleHomeState ();
2022 }
2123}
@@ -34,7 +36,7 @@ IconData getCameraLensIcon(CameraLensDirection direction) {
3436 }
3537}
3638
37- void logError (String code, String ? message) {
39+ void _logError (String code, String ? message) {
3840 if (message != null ) {
3941 print ('Error: $code \n Error Message: $message ' );
4042 } else {
@@ -134,12 +136,6 @@ class _CameraExampleHomeState extends State<CameraExampleHome>
134136 children: < Widget > [
135137 Expanded (
136138 child: Container (
137- child: Padding (
138- padding: const EdgeInsets .all (1.0 ),
139- child: Center (
140- child: _cameraPreviewWidget (),
141- ),
142- ),
143139 decoration: BoxDecoration (
144140 color: Colors .black,
145141 border: Border .all (
@@ -150,6 +146,12 @@ class _CameraExampleHomeState extends State<CameraExampleHome>
150146 width: 3.0 ,
151147 ),
152148 ),
149+ child: Padding (
150+ padding: const EdgeInsets .all (1.0 ),
151+ child: Center (
152+ child: _cameraPreviewWidget (),
153+ ),
154+ ),
153155 ),
154156 ),
155157 _captureControlRowWidget (),
@@ -233,6 +235,8 @@ class _CameraExampleHomeState extends State<CameraExampleHome>
233235 Container ()
234236 else
235237 SizedBox (
238+ width: 64.0 ,
239+ height: 64.0 ,
236240 child: (localVideoController == null )
237241 ? (
238242 // The captured image on the web contains a network-accessible URL
@@ -243,6 +247,8 @@ class _CameraExampleHomeState extends State<CameraExampleHome>
243247 ? Image .network (imageFile! .path)
244248 : Image .file (File (imageFile! .path)))
245249 : Container (
250+ decoration: BoxDecoration (
251+ border: Border .all (color: Colors .pink)),
246252 child: Center (
247253 child: AspectRatio (
248254 aspectRatio:
@@ -251,11 +257,7 @@ class _CameraExampleHomeState extends State<CameraExampleHome>
251257 : 1.0 ,
252258 child: VideoPlayer (localVideoController)),
253259 ),
254- decoration: BoxDecoration (
255- border: Border .all (color: Colors .pink)),
256260 ),
257- width: 64.0 ,
258- height: 64.0 ,
259261 ),
260262 ],
261263 ),
@@ -394,7 +396,6 @@ class _CameraExampleHomeState extends State<CameraExampleHome>
394396 mainAxisSize: MainAxisSize .max,
395397 children: < Widget > [
396398 TextButton (
397- child: const Text ('AUTO' ),
398399 style: styleAuto,
399400 onPressed: controller != null
400401 ? () =>
@@ -406,21 +407,22 @@ class _CameraExampleHomeState extends State<CameraExampleHome>
406407 showInSnackBar ('Resetting exposure point' );
407408 }
408409 },
410+ child: const Text ('AUTO' ),
409411 ),
410412 TextButton (
411- child: const Text ('LOCKED' ),
412413 style: styleLocked,
413414 onPressed: controller != null
414415 ? () =>
415416 onSetExposureModeButtonPressed (ExposureMode .locked)
416417 : null ,
418+ child: const Text ('LOCKED' ),
417419 ),
418420 TextButton (
419- child: const Text ('RESET OFFSET' ),
420421 style: styleLocked,
421422 onPressed: controller != null
422423 ? () => controller! .setExposureOffset (0.0 )
423424 : null ,
425+ child: const Text ('RESET OFFSET' ),
424426 ),
425427 ],
426428 ),
@@ -479,7 +481,6 @@ class _CameraExampleHomeState extends State<CameraExampleHome>
479481 mainAxisSize: MainAxisSize .max,
480482 children: < Widget > [
481483 TextButton (
482- child: const Text ('AUTO' ),
483484 style: styleAuto,
484485 onPressed: controller != null
485486 ? () => onSetFocusModeButtonPressed (FocusMode .auto)
@@ -490,13 +491,14 @@ class _CameraExampleHomeState extends State<CameraExampleHome>
490491 }
491492 showInSnackBar ('Resetting focus point' );
492493 },
494+ child: const Text ('AUTO' ),
493495 ),
494496 TextButton (
495- child: const Text ('LOCKED' ),
496497 style: styleLocked,
497498 onPressed: controller != null
498499 ? () => onSetFocusModeButtonPressed (FocusMode .locked)
499500 : null ,
501+ child: const Text ('LOCKED' ),
500502 ),
501503 ],
502504 ),
@@ -582,13 +584,13 @@ class _CameraExampleHomeState extends State<CameraExampleHome>
582584 onNewCameraSelected (description);
583585 };
584586
585- if (cameras .isEmpty) {
587+ if (_cameras .isEmpty) {
586588 _ambiguate (SchedulerBinding .instance)? .addPostFrameCallback ((_) async {
587589 showInSnackBar ('No camera found.' );
588590 });
589591 return const Text ('None' );
590592 } else {
591- for (final CameraDescription cameraDescription in cameras ) {
593+ for (final CameraDescription cameraDescription in _cameras ) {
592594 toggles.add (
593595 SizedBox (
594596 width: 90.0 ,
@@ -1014,31 +1016,35 @@ class _CameraExampleHomeState extends State<CameraExampleHome>
10141016 }
10151017
10161018 void _showCameraException (CameraException e) {
1017- logError (e.code, e.description);
1019+ _logError (e.code, e.description);
10181020 showInSnackBar ('Error: ${e .code }\n ${e .description }' );
10191021 }
10201022}
10211023
1024+ /// CameraApp is the Main Application.
10221025class CameraApp extends StatelessWidget {
1026+ /// Default Constructor
1027+ const CameraApp ({Key ? key}) : super (key: key);
1028+
10231029 @override
10241030 Widget build (BuildContext context) {
1025- return MaterialApp (
1031+ return const MaterialApp (
10261032 home: CameraExampleHome (),
10271033 );
10281034 }
10291035}
10301036
1031- List <CameraDescription > cameras = < CameraDescription > [];
1037+ List <CameraDescription > _cameras = < CameraDescription > [];
10321038
10331039Future <void > main () async {
10341040 // Fetch the available cameras before initializing the app.
10351041 try {
10361042 WidgetsFlutterBinding .ensureInitialized ();
1037- cameras = await availableCameras ();
1043+ _cameras = await availableCameras ();
10381044 } on CameraException catch (e) {
1039- logError (e.code, e.description);
1045+ _logError (e.code, e.description);
10401046 }
1041- runApp (CameraApp ());
1047+ runApp (const CameraApp ());
10421048}
10431049
10441050/// This allows a value of type T or T? to be treated as a value of type T?.
0 commit comments