Browse Source

full screen camera

geyan 5 years ago
parent
commit
ab56fbe23f
5 changed files with 32 additions and 9 deletions
  1. 2 0
      ios/Runner/Info.plist
  2. 19 9
      lib/pages/CameraPage/CameraMain.dart
  3. 3 0
      lib/providers/CameraProvider.dart
  4. 7 0
      pubspec.lock
  5. 1 0
      pubspec.yaml

+ 2 - 0
ios/Runner/Info.plist

@@ -45,6 +45,8 @@
 		<string>系统将使用您的相机进行图片拍摄,视频拍摄等</string>
 		<string>系统将使用您的相机进行图片拍摄,视频拍摄等</string>
 		<key>NSMicrophoneUsageDescription</key>
 		<key>NSMicrophoneUsageDescription</key>
 		<string>系统将使用您的麦克风进行音频录制</string>
 		<string>系统将使用您的麦克风进行音频录制</string>
+		<key>NSPhotoLibraryUsageDescription</key>
+		<string>我们将存储照片至您的相册以及从相册获取图片信息</string>
 		<key>NSAppTransportSecurity</key>
 		<key>NSAppTransportSecurity</key>
 		<dict>
 		<dict>
 			<key>NSAllowsArbitraryLoads</key>
 			<key>NSAllowsArbitraryLoads</key>

+ 19 - 9
lib/pages/CameraPage/CameraMain.dart

@@ -1,9 +1,13 @@
+import 'dart:io';
+
 import 'package:camera/camera.dart';
 import 'package:camera/camera.dart';
 import 'package:camera/new/src/support_android/camera.dart';
 import 'package:camera/new/src/support_android/camera.dart';
 import 'package:douyin_demo/providers/CameraProvider.dart';
 import 'package:douyin_demo/providers/CameraProvider.dart';
 import 'package:flutter/material.dart';
 import 'package:flutter/material.dart';
 import 'package:provider/provider.dart';
 import 'package:provider/provider.dart';
 import 'package:path/path.dart' as p;
 import 'package:path/path.dart' as p;
+import 'package:image_picker_saver/image_picker_saver.dart';
+
 
 
 class CameraPage extends StatelessWidget {
 class CameraPage extends StatelessWidget {
   const CameraPage({Key key}) : super(key: key);
   const CameraPage({Key key}) : super(key: key);
@@ -86,19 +90,20 @@ class CameraMain extends StatelessWidget {
       );
       );
     }
     }
     final size = MediaQuery.of(context).size;
     final size = MediaQuery.of(context).size;
-    final deviceRatio = size.width / size.height;
     return _controller.value.isInitialized
     return _controller.value.isInitialized
         ? Stack(children: <Widget>[
         ? Stack(children: <Widget>[
             // Camera.open(cameraId),
             // Camera.open(cameraId),
 
 
-            Transform.scale(
-              scale: _controller.value.aspectRatio / deviceRatio,
-              child: Center(
-                child: AspectRatio(
-                  aspectRatio: _controller.value.aspectRatio,
-                  child: CameraPreview(_controller),
+            ClipRect(
+              child: Transform.scale(
+                scale: _controller.value.aspectRatio / size.aspectRatio,
+                child: Center(
+                  child: AspectRatio(
+                    aspectRatio: _controller.value.aspectRatio,
+                    child: CameraPreview(_controller),
+                  ),
                 ),
                 ),
-              ),
+              )
             ),
             ),
             Positioned(
             Positioned(
               //顶部关闭按钮
               //顶部关闭按钮
@@ -211,7 +216,12 @@ class CircleTakePhoto extends StatelessWidget {
         onPressed: () async {
         onPressed: () async {
           provider.changeFileName();
           provider.changeFileName();
           print(provider.fileName);
           print(provider.fileName);
-          await provider.cameraController.takePicture(provider.fileName);
+          await provider.cameraController.takePicture(provider.fileName).then((_){
+            // Navigator.push(context, MaterialPageRoute(fullscreenDialog: true,builder: (_){
+            //   return Image.file(File(provider.fileName) );
+            // }));
+            ImagePickerSaver.saveFile(fileData: File(provider.fileName).readAsBytesSync());
+          });
         },
         },
         child: Container(
         child: Container(
           width: innerBox,
           width: innerBox,

+ 3 - 0
lib/providers/CameraProvider.dart

@@ -26,6 +26,9 @@ class CameraProvider with ChangeNotifier {
 
 
   getCameras() async {
   getCameras() async {
     Directory appDocDir = await getApplicationDocumentsDirectory();
     Directory appDocDir = await getApplicationDocumentsDirectory();
+    if(!Directory(appDocDir.path).existsSync()){
+      appDocDir.createSync();
+    }
     appFolder = appDocDir.path;
     appFolder = appDocDir.path;
     cameras = await availableCameras();
     cameras = await availableCameras();
     cameraController =
     cameraController =

+ 7 - 0
pubspec.lock

@@ -242,6 +242,13 @@ packages:
       url: "https://pub.flutter-io.cn"
       url: "https://pub.flutter-io.cn"
     source: hosted
     source: hosted
     version: "3.1.3"
     version: "3.1.3"
+  image_picker_saver:
+    dependency: "direct main"
+    description:
+      name: image_picker_saver
+      url: "https://pub.flutter-io.cn"
+    source: hosted
+    version: "0.3.0"
   io:
   io:
     dependency: transitive
     dependency: transitive
     description:
     description:

+ 1 - 0
pubspec.yaml

@@ -38,6 +38,7 @@ dependencies:
   path_provider:
   path_provider:
   path:
   path:
   uuid:
   uuid:
+  image_picker_saver:
     
     
 dev_dependencies:
 dev_dependencies:
   flutter_test:
   flutter_test: