diff --git a/example/lib/main.dart b/example/lib/main.dart index 47d8ece9226f..a0eed3ca7de6 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -9,7 +9,7 @@ import 'package:video_player/video_player.dart'; class CameraExampleHome extends StatefulWidget { @override _CameraExampleHomeState createState() { - return new _CameraExampleHomeState(); + return _CameraExampleHomeState(); } } @@ -23,7 +23,7 @@ IconData getCameraLensIcon(CameraLensDirection direction) { case CameraLensDirection.external: return Icons.camera; } - throw new ArgumentError('Unknown lens direction'); + throw ArgumentError('Unknown lens direction'); } void logError(String code, String message) => @@ -36,28 +36,28 @@ class _CameraExampleHomeState extends State { VideoPlayerController videoController; VoidCallback videoPlayerListener; - final GlobalKey _scaffoldKey = new GlobalKey(); + final GlobalKey _scaffoldKey = GlobalKey(); @override Widget build(BuildContext context) { - return new Scaffold( + return Scaffold( key: _scaffoldKey, - appBar: new AppBar( + appBar: AppBar( title: const Text('Camera example'), ), - body: new Column( + body: Column( children: [ - new Expanded( - child: new Container( - child: new Padding( + Expanded( + child: Container( + child: Padding( padding: const EdgeInsets.all(1.0), - child: new Center( + child: Center( child: _cameraPreviewWidget(), ), ), - decoration: new BoxDecoration( + decoration: BoxDecoration( color: Colors.black, - border: new Border.all( + border: Border.all( color: controller != null && controller.value.isRecordingVideo ? Colors.redAccent : Colors.grey, @@ -67,9 +67,9 @@ class _CameraExampleHomeState extends State { ), ), _captureControlRowWidget(), - new Padding( + Padding( padding: const EdgeInsets.all(5.0), - child: new Row( + child: Row( mainAxisAlignment: MainAxisAlignment.start, children: [ _cameraTogglesRowWidget(), @@ -94,33 +94,33 @@ class _CameraExampleHomeState extends State { ), ); } else { - return new AspectRatio( + return AspectRatio( aspectRatio: controller.value.aspectRatio, - child: new CameraPreview(controller), + child: CameraPreview(controller), ); } } /// Display the thumbnail of the captured image or video. Widget _thumbnailWidget() { - return new Expanded( - child: new Align( + return Expanded( + child: Align( alignment: Alignment.centerRight, child: videoController == null && imagePath == null ? null - : new SizedBox( + : SizedBox( child: (videoController == null) - ? new Image.file(new File(imagePath)) - : new Container( - child: new Center( - child: new AspectRatio( + ? Image.file(File(imagePath)) + : Container( + child: Center( + child: AspectRatio( aspectRatio: videoController.value.size != null ? videoController.value.aspectRatio : 1.0, - child: new VideoPlayer(videoController)), + child: VideoPlayer(videoController)), ), - decoration: new BoxDecoration( - border: new Border.all(color: Colors.pink)), + decoration: BoxDecoration( + border: Border.all(color: Colors.pink)), ), width: 64.0, height: 64.0, @@ -131,11 +131,11 @@ class _CameraExampleHomeState extends State { /// Display the control bar with buttons to take pictures and record videos. Widget _captureControlRowWidget() { - return new Row( + return Row( mainAxisAlignment: MainAxisAlignment.spaceEvenly, mainAxisSize: MainAxisSize.max, children: [ - new IconButton( + IconButton( icon: const Icon(Icons.camera_alt), color: Colors.blue, onPressed: controller != null && @@ -144,7 +144,7 @@ class _CameraExampleHomeState extends State { ? onTakePictureButtonPressed : null, ), - new IconButton( + IconButton( icon: const Icon(Icons.videocam), color: Colors.blue, onPressed: controller != null && @@ -153,7 +153,7 @@ class _CameraExampleHomeState extends State { ? onVideoRecordButtonPressed : null, ), - new IconButton( + IconButton( icon: const Icon(Icons.stop), color: Colors.red, onPressed: controller != null && @@ -175,11 +175,10 @@ class _CameraExampleHomeState extends State { } else { for (CameraDescription cameraDescription in cameras) { toggles.add( - new SizedBox( + SizedBox( width: 90.0, - child: new RadioListTile( - title: - new Icon(getCameraLensIcon(cameraDescription.lensDirection)), + child: RadioListTile( + title: Icon(getCameraLensIcon(cameraDescription.lensDirection)), groupValue: controller?.description, value: cameraDescription, onChanged: controller != null && controller.value.isRecordingVideo @@ -191,21 +190,20 @@ class _CameraExampleHomeState extends State { } } - return new Row(children: toggles); + return Row(children: toggles); } - String timestamp() => new DateTime.now().millisecondsSinceEpoch.toString(); + String timestamp() => DateTime.now().millisecondsSinceEpoch.toString(); void showInSnackBar(String message) { - _scaffoldKey.currentState - .showSnackBar(new SnackBar(content: new Text(message))); + _scaffoldKey.currentState.showSnackBar(SnackBar(content: Text(message))); } void onNewCameraSelected(CameraDescription cameraDescription) async { if (controller != null) { await controller.dispose(); } - controller = new CameraController(cameraDescription, ResolutionPreset.high); + controller = CameraController(cameraDescription, ResolutionPreset.high); // If the controller is updated then update the UI. controller.addListener(() { @@ -261,7 +259,7 @@ class _CameraExampleHomeState extends State { final Directory extDir = await getApplicationDocumentsDirectory(); final String dirPath = '${extDir.path}/Movies/flutter_test'; - await new Directory(dirPath).create(recursive: true); + await Directory(dirPath).create(recursive: true); final String filePath = '$dirPath/${timestamp()}.mp4'; if (controller.value.isRecordingVideo) { @@ -296,7 +294,7 @@ class _CameraExampleHomeState extends State { Future _startVideoPlayer() async { final VideoPlayerController vcontroller = - new VideoPlayerController.file(new File(videoPath)); + VideoPlayerController.file(File(videoPath)); videoPlayerListener = () { if (videoController != null && videoController.value.size != null) { // Refreshing the state to update video player with the correct ratio. @@ -324,7 +322,7 @@ class _CameraExampleHomeState extends State { } final Directory extDir = await getApplicationDocumentsDirectory(); final String dirPath = '${extDir.path}/Pictures/flutter_test'; - await new Directory(dirPath).create(recursive: true); + await Directory(dirPath).create(recursive: true); final String filePath = '$dirPath/${timestamp()}.jpg'; if (controller.value.isTakingPicture) { @@ -350,8 +348,8 @@ class _CameraExampleHomeState extends State { class CameraApp extends StatelessWidget { @override Widget build(BuildContext context) { - return new MaterialApp( - home: new CameraExampleHome(), + return MaterialApp( + home: CameraExampleHome(), ); } } @@ -365,5 +363,5 @@ Future main() async { } on CameraException catch (e) { logError(e.code, e.description); } - runApp(new CameraApp()); + runApp(CameraApp()); } diff --git a/lib/camera.dart b/lib/camera.dart index 837e02bf12cc..115245969ed9 100644 --- a/lib/camera.dart +++ b/lib/camera.dart @@ -20,7 +20,7 @@ String serializeResolutionPreset(ResolutionPreset resolutionPreset) { case ResolutionPreset.low: return 'low'; } - throw new ArgumentError('Unknown ResolutionPreset value'); + throw ArgumentError('Unknown ResolutionPreset value'); } CameraLensDirection _parseCameraLensDirection(String string) { @@ -32,7 +32,7 @@ CameraLensDirection _parseCameraLensDirection(String string) { case 'external': return CameraLensDirection.external; } - throw new ArgumentError('Unknown CameraLensDirection value'); + throw ArgumentError('Unknown CameraLensDirection value'); } /// Completes with a list of available cameras. @@ -43,13 +43,13 @@ Future> availableCameras() async { final List cameras = await _channel.invokeMethod('availableCameras'); return cameras.map((dynamic camera) { - return new CameraDescription( + return CameraDescription( name: camera['name'], lensDirection: _parseCameraLensDirection(camera['lensFacing']), ); }).toList(); } on PlatformException catch (e) { - throw new CameraException(e.code, e.message); + throw CameraException(e.code, e.message); } } @@ -97,8 +97,8 @@ class CameraPreview extends StatelessWidget { @override Widget build(BuildContext context) { return controller.value.isInitialized - ? new Texture(textureId: controller._textureId) - : new Container(); + ? Texture(textureId: controller._textureId) + : Container(); } } @@ -148,7 +148,7 @@ class CameraValue { String errorDescription, Size previewSize, }) { - return new CameraValue( + return CameraValue( isInitialized: isInitialized ?? this.isInitialized, errorDescription: errorDescription, previewSize: previewSize ?? this.previewSize, @@ -192,10 +192,10 @@ class CameraController extends ValueNotifier { /// Throws a [CameraException] if the initialization fails. Future initialize() async { if (_isDisposed) { - return new Future.value(null); + return Future.value(null); } try { - _creatingCompleter = new Completer(); + _creatingCompleter = Completer(); final Map reply = await _channel.invokeMethod( 'initialize', { @@ -206,16 +206,16 @@ class CameraController extends ValueNotifier { _textureId = reply['textureId']; value = value.copyWith( isInitialized: true, - previewSize: new Size( + previewSize: Size( reply['previewWidth'].toDouble(), reply['previewHeight'].toDouble(), ), ); } on PlatformException catch (e) { - throw new CameraException(e.code, e.message); + throw CameraException(e.code, e.message); } _eventSubscription = - new EventChannel('flutter.io/cameraPlugin/cameraEvents$_textureId') + EventChannel('flutter.io/cameraPlugin/cameraEvents$_textureId') .receiveBroadcastStream() .listen(_listener); _creatingCompleter.complete(null); @@ -252,13 +252,13 @@ class CameraController extends ValueNotifier { /// Throws a [CameraException] if the capture fails. Future takePicture(String path) async { if (!value.isInitialized || _isDisposed) { - throw new CameraException( + throw CameraException( 'Uninitialized CameraController.', 'takePicture was called on uninitialized CameraController', ); } if (value.isTakingPicture) { - throw new CameraException( + throw CameraException( 'Previous capture has not returned yet.', 'takePicture was called before the previous capture returned.', ); @@ -272,7 +272,7 @@ class CameraController extends ValueNotifier { value = value.copyWith(isTakingPicture: false); } on PlatformException catch (e) { value = value.copyWith(isTakingPicture: false); - throw new CameraException(e.code, e.message); + throw CameraException(e.code, e.message); } } @@ -288,13 +288,13 @@ class CameraController extends ValueNotifier { /// Throws a [CameraException] if the capture fails. Future startVideoRecording(String filePath) async { if (!value.isInitialized || _isDisposed) { - throw new CameraException( + throw CameraException( 'Uninitialized CameraController', 'startVideoRecording was called on uninitialized CameraController', ); } if (value.isRecordingVideo) { - throw new CameraException( + throw CameraException( 'A video recording is already started.', 'startVideoRecording was called when a recording is already started.', ); @@ -306,20 +306,20 @@ class CameraController extends ValueNotifier { ); value = value.copyWith(isRecordingVideo: true); } on PlatformException catch (e) { - throw new CameraException(e.code, e.message); + throw CameraException(e.code, e.message); } } /// Stop recording. Future stopVideoRecording() async { if (!value.isInitialized || _isDisposed) { - throw new CameraException( + throw CameraException( 'Uninitialized CameraController', 'stopVideoRecording was called on uninitialized CameraController', ); } if (!value.isRecordingVideo) { - throw new CameraException( + throw CameraException( 'No video is recording', 'stopVideoRecording was called when no video is recording.', ); @@ -331,7 +331,7 @@ class CameraController extends ValueNotifier { {'textureId': _textureId}, ); } on PlatformException catch (e) { - throw new CameraException(e.code, e.message); + throw CameraException(e.code, e.message); } } @@ -339,12 +339,12 @@ class CameraController extends ValueNotifier { @override Future dispose() async { if (_isDisposed) { - return new Future.value(null); + return Future.value(null); } _isDisposed = true; super.dispose(); if (_creatingCompleter == null) { - return new Future.value(null); + return Future.value(null); } else { return _creatingCompleter.future.then((_) async { await _channel.invokeMethod(