Browse Source

fix camera issue

geyan 5 years ago
parent
commit
948d51ccb6

+ 3 - 3
ios/Runner.xcodeproj/project.pbxproj

@@ -364,7 +364,7 @@
 				GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
 				GCC_WARN_UNUSED_FUNCTION = YES;
 				GCC_WARN_UNUSED_VARIABLE = YES;
-				IPHONEOS_DEPLOYMENT_TARGET = 8.0;
+				IPHONEOS_DEPLOYMENT_TARGET = 9.3;
 				MTL_ENABLE_DEBUG_INFO = NO;
 				SDKROOT = iphoneos;
 				TARGETED_DEVICE_FAMILY = "1,2";
@@ -448,7 +448,7 @@
 				GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
 				GCC_WARN_UNUSED_FUNCTION = YES;
 				GCC_WARN_UNUSED_VARIABLE = YES;
-				IPHONEOS_DEPLOYMENT_TARGET = 8.0;
+				IPHONEOS_DEPLOYMENT_TARGET = 9.3;
 				MTL_ENABLE_DEBUG_INFO = YES;
 				ONLY_ACTIVE_ARCH = YES;
 				SDKROOT = iphoneos;
@@ -497,7 +497,7 @@
 				GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
 				GCC_WARN_UNUSED_FUNCTION = YES;
 				GCC_WARN_UNUSED_VARIABLE = YES;
-				IPHONEOS_DEPLOYMENT_TARGET = 8.0;
+				IPHONEOS_DEPLOYMENT_TARGET = 9.3;
 				MTL_ENABLE_DEBUG_INFO = NO;
 				SDKROOT = iphoneos;
 				SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";

+ 3 - 0
lib/main.dart

@@ -68,6 +68,9 @@ class RecommendPage extends StatelessWidget {
   @override
   Widget build(BuildContext context) {
     double rpx = MediaQuery.of(context).size.width / 750;
+    // MediaQuery.of(context).padding.top
+    // MediaQuery.of(context).padding.bottom
+
     return MultiProvider(
         providers: [
           ChangeNotifierProvider(

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

@@ -18,15 +18,9 @@ class CameraPage extends StatelessWidget {
   Widget build(BuildContext context) {
     return Scaffold(
       backgroundColor: Theme.of(context).primaryColor,
-      body: MultiProvider(
-          providers: [
-            ChangeNotifierProvider(
-              builder: (_) => CameraProvider(),
-            )
-          ],
-          child: CameraMain(
+      body: CameraMain(
             rpx: MediaQuery.of(context).size.width / 750,
-          )),
+          ),
       bottomNavigationBar: BottomAppBar(),
     );
   }
@@ -53,7 +47,7 @@ class _CameraMainState extends State<CameraMain> {
     super.initState();
 
     // provider = Provider.of<CameraProvider>(context);
-    getCameras();
+    // getCameras();
     rpx = widget.rpx;
     toTop = 100 * rpx;
     outBox = 170 * rpx;
@@ -141,6 +135,7 @@ class _CameraMainState extends State<CameraMain> {
   @override
   Widget build(BuildContext context) {
     provider = Provider.of<CameraProvider>(context);
+    _controller=provider.cameraController;
     if (provider == null || _controller == null) {
       return Container(
         child: Center(child: CircularProgressIndicator()),

+ 12 - 2
lib/providers/CameraProvider.dart

@@ -56,8 +56,18 @@ class CameraProvider extends State<StatefulWidget>
     }
     appFolder = appDocDir.path;
     cameras = await availableCameras();
-    // cameraController =
-    //     CameraController(cameras[curCamera], ResolutionPreset.low);
+    cameraController =
+        CameraController(cameras[curCamera], ResolutionPreset.high);
+        
+    try {
+      await cameraController.initialize();
+    } catch (e) {
+      print(e);
+    }
+    
+        // cameraController.startImageStream(onAvailable);
+        
+        notifyListeners();
     // cameraController.initialize().then((_) {
       
     //   cameraController.prepareForVideoRecording();

+ 11 - 2
lib/widgets/BottomBar.dart

@@ -4,6 +4,7 @@ import 'package:douyin_demo/pages/FaceDetect/FaceDetection.dart';
 import 'package:douyin_demo/pages/loadData/loadData.dart';
 import 'package:douyin_demo/pages/sameCity/SameCityPage.dart';
 import 'package:douyin_demo/pages/selfHome/HomePage.dart';
+import 'package:douyin_demo/providers/CameraProvider.dart';
 import 'package:douyin_demo/providers/PostsGalleryProvider.dart';
 import 'package:douyin_demo/providers/RecommendProvider.dart';
 import 'package:flutter/material.dart';
@@ -100,8 +101,16 @@ class _BtmBarState extends State<BtmBar> {
       case 3:
         Navigator.of(context).push(new MaterialPageRoute(
       builder: (BuildContext context) {
-        return  LoadDataDemo()
-        ;
+        return  MultiProvider(
+          providers: [
+            ChangeNotifierProvider(
+              builder: (_) => CameraProvider(),
+            )
+          ],
+          child: CameraPage(
+            // rpx: MediaQuery.of(context).size.width / 750,
+          )
+        );
       },
     fullscreenDialog: true
   ));