Last active
February 9, 2019 21:20
-
-
Save carzacc/8b11e282f586d96179702786e891da01 to your computer and use it in GitHub Desktop.
image_picker guide main file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
import 'package:image_picker/image_picker.dart'; | |
void main() =>runApp(PictureShowcaseApp()); | |
class PictureShowcaseApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
home: PictureShowcaseHome("My Best Pictures"), | |
title: "My Best Pictures" | |
); | |
} | |
} | |
class PictureShowcaseHome extends StatefulWidget { | |
final String title; | |
PictureShowcaseHome(this.title); | |
_HomePageState createState() => _HomePageState(); | |
} | |
class _HomePageState extends State<PictureShowcaseHome> { | |
List<Image> imgs = []; | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar(title: Text(widget.title)), | |
body: ListView.builder( | |
itemCount: imgs.length, | |
itemBuilder: (context, i) => | |
Column( | |
children: [ | |
imgs[i], | |
Divider() | |
] | |
), | |
), | |
floatingActionButton: FloatingActionButton( | |
child: Icon(Icons.add), | |
onPressed: () async { | |
var imgFile = await ImagePicker.pickImage( | |
source: ImageSource.camera | |
); | |
setState((){ | |
imgs.add(Image.file(imgFile)); | |
}); | |
} | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment