Explorar el Código

update: 更新example,修复重复进入不能预览问题

hwh97 hace 5 años
padre
commit
286b1a3475
Se han modificado 1 ficheros con 117 adiciones y 84 borrados
  1. 117 84
      example/lib/main.dart

+ 117 - 84
example/lib/main.dart

@@ -9,7 +9,42 @@ import 'package:path/path.dart' as path;
 void main() async {
   WidgetsFlutterBinding.ensureInitialized();
   await FlutterAliCameraController.initializeSdk();
-  runApp(MyApp());
+  runApp(FirstPage());
+}
+
+class FirstPage extends StatefulWidget {
+  @override
+  State<StatefulWidget> createState() {
+    return FirstPageState();
+  }
+}
+
+class FirstPageState extends State<FirstPage> {
+  @override
+  Widget build(BuildContext context) {
+    return MaterialApp(
+      home: FirstState(),
+    );
+  }
+}
+
+class FirstState extends StatelessWidget {
+  @override
+  Widget build(BuildContext context) {
+    return Scaffold(
+      body: Center(
+        child: RawMaterialButton(
+          child: Text("push",),
+          onPressed: () {
+            Navigator.of(context).push(MaterialPageRoute(builder: (ctx){
+              return MyApp();
+            }));
+          },
+        ),
+      ),
+    );
+  }
+
 }
 
 class MyApp extends StatefulWidget {
@@ -37,6 +72,10 @@ class _MyAppState extends State<MyApp> {
     super.dispose();
   }
 
+  void _onPlatformViewCreated() {
+    initPlatform();
+  }
+
   Future<void> initPlatform() async {
     await _controller.create(
         recordOption: CameraRecordOption(
@@ -54,10 +93,6 @@ class _MyAppState extends State<MyApp> {
     setState(() {});
   }
 
-  void _onPlatformViewCreated() {
-    initPlatform();
-  }
-
   static Future<String> _findLocalPath() async {
     final directory = Platform.isAndroid
         ? await getExternalStorageDirectory()
@@ -94,86 +129,84 @@ class _MyAppState extends State<MyApp> {
 
   @override
   Widget build(BuildContext context) {
-    return MaterialApp(
-      home: Scaffold(
-        backgroundColor: Colors.white,
-        appBar: AppBar(
-          title: const Text('Plugin example app'),
-        ),
-        body: ListView(
-          padding: EdgeInsets.symmetric(horizontal: 10),
-          children: <Widget>[
-            SizedBox(
-              width: double.maxFinite,
-              height: 200,
-              child: _controller.buildView(_onPlatformViewCreated),
-            ),
-            Row(
-              mainAxisAlignment: MainAxisAlignment.spaceEvenly,
-              children: <Widget>[
-                IconButton(
-                    icon: Icon(
-                      Icons.play_arrow,
-                      size: 26,
-                    ),
-                    onPressed: () {
-                      if (!recording) _controller.startPreview();
-                    }),
-                IconButton(
-                    icon: Icon(
-                      Icons.pause,
-                      size: 26,
-                    ),
-                    onPressed: () {
-                      if (!recording) _controller.stopPreview();
-                    }),
-                IconButton(
-                    icon: Icon(
-                      Icons.switch_camera,
-                      size: 26,
-                    ),
-                    onPressed: () {
-                      if (!recording) _controller.switchCamera();
-                    }),
-                IconButton(
-                    icon: Icon(
-                      recording ? Icons.stop : Icons.fiber_manual_record,
-                      size: 26,
-                    ),
-                    onPressed: () {
-                      if (!recording) _record();
-                    }),
-                IconButton(
-                    icon: Icon(
-                      Icons.settings,
-                      size: 26,
-                    ),
-                    onPressed: () {
-                      if (!recording) _compose();
+    return Scaffold(
+      backgroundColor: Colors.white,
+      appBar: AppBar(
+        title: const Text('Plugin example app'),
+      ),
+      body: ListView(
+        padding: EdgeInsets.symmetric(horizontal: 10),
+        children: <Widget>[
+          SizedBox(
+            width: double.maxFinite,
+            height: 200,
+            child: _controller.buildView(_onPlatformViewCreated),
+          ),
+          Row(
+            mainAxisAlignment: MainAxisAlignment.spaceEvenly,
+            children: <Widget>[
+              IconButton(
+                  icon: Icon(
+                    Icons.play_arrow,
+                    size: 26,
+                  ),
+                  onPressed: () {
+                    if (!recording) _controller.startPreview();
+                  }),
+              IconButton(
+                  icon: Icon(
+                    Icons.pause,
+                    size: 26,
+                  ),
+                  onPressed: () {
+                    if (!recording) _controller.stopPreview();
+                  }),
+              IconButton(
+                  icon: Icon(
+                    Icons.switch_camera,
+                    size: 26,
+                  ),
+                  onPressed: () {
+                    if (!recording) _controller.switchCamera();
+                  }),
+              IconButton(
+                  icon: Icon(
+                    recording ? Icons.stop : Icons.fiber_manual_record,
+                    size: 26,
+                  ),
+                  onPressed: () {
+                    if (!recording) _record();
+                  }),
+              IconButton(
+                  icon: Icon(
+                    Icons.settings,
+                    size: 26,
+                  ),
+                  onPressed: () {
+                    if (!recording) _compose();
+                  }),
+            ],
+          ),
+          SizedBox(
+            height: 5,
+          ),
+          Row(
+            children: <Widget>[
+              Text("美颜0-100"),
+              Expanded(
+                child: Slider(
+                    value: value,
+                    max: 100,
+                    onChanged: (value) {
+                      _controller.setBeauty(value.toInt());
+                      setState(() {
+                        this.value = value;
+                      });
                     }),
-              ],
-            ),
-            SizedBox(
-              height: 5,
-            ),
-            Row(
-              children: <Widget>[
-                Text("美颜0-100"),
-                Expanded(
-                  child: Slider(
-                      value: value,
-                      max: 100,
-                      onChanged: (value) {
-                        _controller.setBeauty(value.toInt());
-                        setState(() {
-                          this.value = value;
-                        });
-                      }),
-                ),
-              ],
-            ),
-          ],
-        ),
+              ),
+            ],
+          ),
+        ],
       ),
     );
   }