Skip to content

Commit 4e3981b

Browse files
committed
🎨 Demo update.
1 parent ea60b21 commit 4e3981b

File tree

1 file changed

+35
-7
lines changed

1 file changed

+35
-7
lines changed

example/lib/main.dart

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import 'dart:typed_data';
12
import 'dart:ui' as ui;
23

34
import 'package:flutter/material.dart';
@@ -37,20 +38,47 @@ class MyHomePage extends StatefulWidget {
3738
}
3839

3940
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+
4061
@override
4162
Widget build(BuildContext context) {
4263
return Scaffold(
4364
appBar: AppBar(
4465
title: Text(widget.title),
4566
),
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+
),
4780
floatingActionButton: FloatingActionButton(
48-
onPressed: () {
49-
CameraPicker.pickFromCamera(
50-
context,
51-
enableRecording: true,
52-
);
53-
},
81+
onPressed: () => pick(context),
5482
tooltip: 'Increment',
5583
child: const Icon(Icons.camera_enhance),
5684
),

0 commit comments

Comments
 (0)