Advertisement
Guest User

Untitled

a guest
Sep 4th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 0.97 KB | None | 0 0
  1. import 'dart:io';
  2.  
  3. import 'package:flutter/material.dart';
  4. import 'package:image_picker/image_picker.dart';
  5.  
  6. void main() => runApp(MyApp());
  7.  
  8. class MyApp extends StatefulWidget {
  9.   @override
  10.   State<StatefulWidget> createState() => new _MyAppState();
  11. }
  12.  
  13. class _MyAppState extends State<MyApp>{
  14.   File _image;
  15.  
  16.   Future getImage() async{
  17.     var image = await ImagePicker.pickImage(source: ImageSource.camera);
  18.     setState(() {
  19.       _image = image;
  20.     });
  21.   }
  22.  
  23.   @override
  24.   Widget build(BuildContext context) {
  25.     return new MaterialApp(title: "Image Picker",
  26.     home: new Scaffold(
  27.       appBar: new AppBar(title: new Text("Camera Demo"),
  28.       ),
  29.       body: new Center(child: _image == null ? new Text("Sem imagens selecionadas") : new Image.file(_image) ,
  30.       ),
  31.       floatingActionButton: new FloatingActionButton(
  32.         onPressed: getImage ,
  33.         tooltip: "Pick image",
  34.         child: new Icon(Icons.camera),),
  35.         ),);
  36.   }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement