123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- import 'package:flutter/material.dart';
- import 'dart:async';
- import 'package:flutter/services.dart';
- import 'package:multimage_picker/multimage_picker.dart';
- void main() => runApp(new MyApp());
- class MyApp extends StatefulWidget {
- @override
- _MyAppState createState() => new _MyAppState();
- }
- class _MyAppState extends State<MyApp> {
- List<Asset> images = List<Asset>();
- String _error = 'No Error Dectected';
- @override
- void initState() {
- super.initState();
- }
- Widget buildGridView() {
- return GridView.count(
- crossAxisCount: 3,
- children: List.generate(images.length, (index) {
- Asset asset = images[index];
- return AssetThumb(
- asset: asset,
- width: 300,
- height: 300,
- );
- }),
- );
- }
- Future<void> deleteAssets() async {
- await MultiImagePicker.deleteImages(assets: images);
- setState(() {
- images = List<Asset>();
- });
- }
- Future<void> loadAssets() async {
- List<Asset> resultList = List<Asset>();
- String error = 'No Error Dectected';
- try {
- resultList = await MultiImagePicker.pickImages(
- maxImages: 300,
- enableCamera: true,
- selectedAssets: images,
- cupertinoOptions: CupertinoOptions(takePhotoIcon: "chat"),
- materialOptions: MaterialOptions(
- actionBarColor: "#abcdef",
- actionBarTitle: "Example App",
- allViewTitle: "All Photos",
- selectCircleStrokeColor: "#000000",
- ));
- } on PlatformException catch (e) {
- error = e.message;
- }
- // If the widget was removed from the tree while the asynchronous platform
- // message was in flight, we want to discard the reply rather than calling
- // setState to update our non-existent appearance.
- if (!mounted) return;
- setState(() {
- images = resultList;
- _error = error;
- });
- }
- @override
- Widget build(BuildContext context) {
- return new MaterialApp(
- home: new Scaffold(
- appBar: new AppBar(
- title: const Text('Plugin example app'),
- ),
- body: Column(
- children: <Widget>[
- Center(child: Text('Error: $_error')),
- RaisedButton(
- child: Text("Pick images"),
- onPressed: loadAssets,
- ),
- images.length > 0
- ? RaisedButton(
- child: Text("Delete images"),
- onPressed: deleteAssets,
- )
- : Container(),
- Expanded(
- child: buildGridView(),
- )
- ],
- ),
- ),
- );
- }
- }
|