File tree Expand file tree Collapse file tree 1 file changed +35
-7
lines changed Expand file tree Collapse file tree 1 file changed +35
-7
lines changed Original file line number Diff line number Diff line change
1
+ import 'dart:typed_data' ;
1
2
import 'dart:ui' as ui;
2
3
3
4
import 'package:flutter/material.dart' ;
@@ -37,20 +38,47 @@ class MyHomePage extends StatefulWidget {
37
38
}
38
39
39
40
class _MyHomePageState extends State <MyHomePage > {
41
+ AssetEntity entity;
42
+ Uint8List data;
43
+
44
+ Future <void > pick (BuildContext context) async {
45
+ final AssetEntity _entity = await CameraPicker .pickFromCamera (
46
+ context,
47
+ enableRecording: true ,
48
+ );
49
+ if (_entity != null && entity != _entity) {
50
+ entity = _entity;
51
+ if (mounted) {
52
+ setState (() {});
53
+ }
54
+ data = await entity.thumbData;
55
+ if (mounted) {
56
+ setState (() {});
57
+ }
58
+ }
59
+ }
60
+
40
61
@override
41
62
Widget build (BuildContext context) {
42
63
return Scaffold (
43
64
appBar: AppBar (
44
65
title: Text (widget.title),
45
66
),
46
- body: const Center (child: Text ('Click the button to start picking.' )),
67
+ body: SizedBox .expand (
68
+ child: Column (
69
+ mainAxisAlignment: MainAxisAlignment .center,
70
+ children: < Widget > [
71
+ if (entity != null && data != null )
72
+ Image .memory (data)
73
+ else if (entity != null && data == null )
74
+ const CircularProgressIndicator ()
75
+ else
76
+ const Text ('Click the button to start picking.' ),
77
+ ],
78
+ ),
79
+ ),
47
80
floatingActionButton: FloatingActionButton (
48
- onPressed: () {
49
- CameraPicker .pickFromCamera (
50
- context,
51
- enableRecording: true ,
52
- );
53
- },
81
+ onPressed: () => pick (context),
54
82
tooltip: 'Increment' ,
55
83
child: const Icon (Icons .camera_enhance),
56
84
),
You can’t perform that action at this time.
0 commit comments