Skip to content

Instantly share code, notes, and snippets.

@briankung
Created April 12, 2018 13:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save briankung/45f9d8438baab59ddcd3b6f3fe811d99 to your computer and use it in GitHub Desktop.
Save briankung/45f9d8438baab59ddcd3b6f3fe811d99 to your computer and use it in GitHub Desktop.
flutter camera problem diff
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