flutter camera problem diff
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/lib/main.dart b/lib/main.dart | |
index 0d5a596..3cda549 100644 | |
--- a/lib/main.dart | |
+++ b/lib/main.dart | |
@@ -1,7 +1,10 @@ | |
import 'dart:async'; | |
+import 'dart:io'; | |
+ | |
import 'package:flutter/material.dart'; | |
import 'package:camera/camera.dart'; | |
import 'package:flutter/services.dart'; | |
+import 'package:path_provider/path_provider.dart'; | |
List<CameraDescription> cameras; | |
@@ -21,11 +24,22 @@ class CameraApp extends StatefulWidget { | |
} | |
class _CameraAppState extends State<CameraApp> { | |
+ String _appDirectoryPath; | |
CameraController controller; | |
+ Future<void> _requestAppDirectory() async { | |
+ // `path_provider` doesn't have getCameraRollDirectory() | |
+ Directory _appDirectory = await getApplicationDocumentsDirectory(); | |
+ | |
+ setState(() { | |
+ _appDirectoryPath = _appDirectory.path; | |
+ }); | |
+ } | |
+ | |
@override | |
void initState() { | |
super.initState(); | |
+ _requestAppDirectory(); | |
controller = new CameraController(cameras[0], ResolutionPreset.medium); | |
controller.initialize().then((_) { | |
if (!mounted) { | |
@@ -63,7 +77,9 @@ class _CameraAppState extends State<CameraApp> { | |
tooltip: 'Increment', | |
child: new Icon(Icons.camera), | |
onPressed: () { | |
+ print('capturing'); | |
+ print(_appDirectoryPath); | |
+ controller.capture(_appDirectoryPath); | |
}, | |
), | |
floatingActionButtonLocation: FloatingActionButtonLocation.centerFloat, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment