multi_image_picker_plus 0.0.4 multi_image_picker_plus: ^0.0.4 copied to clipboard
Flutter plugin that allows you to display multi image picker on iOS and Android.
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:multi_image_picker_plus/multi_image_picker_plus.dart';
void main() => runApp(MaterialApp(
home: const MyApp(),
theme: ThemeData(
colorSchemeSeed: Colors.deepOrange,
brightness: Brightness.dark,
),
));
class MyApp extends StatefulWidget {
const MyApp({super.key});
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
List<Asset> images = <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> _loadAssets() async {
final ColorScheme colorScheme = Theme.of(context).colorScheme;
List<Asset> resultList = <Asset>[];
String error = 'No Error Dectected';
const AlbumSetting albumSetting = AlbumSetting(
fetchResults: {
PHFetchResult(
type: PHAssetCollectionType.smartAlbum,
subtype: PHAssetCollectionSubtype.smartAlbumUserLibrary,
),
PHFetchResult(
type: PHAssetCollectionType.smartAlbum,
subtype: PHAssetCollectionSubtype.smartAlbumFavorites,
),
PHFetchResult(
type: PHAssetCollectionType.album,
subtype: PHAssetCollectionSubtype.albumRegular,
),
PHFetchResult(
type: PHAssetCollectionType.smartAlbum,
subtype: PHAssetCollectionSubtype.smartAlbumSelfPortraits,
),
PHFetchResult(
type: PHAssetCollectionType.smartAlbum,
subtype: PHAssetCollectionSubtype.smartAlbumPanoramas,
),
PHFetchResult(
type: PHAssetCollectionType.smartAlbum,
subtype: PHAssetCollectionSubtype.smartAlbumVideos,
),
},
);
const SelectionSetting selectionSetting = SelectionSetting(
min: 0,
max: 3,
unselectOnReachingMax: true,
);
const DismissSetting dismissSetting = DismissSetting(
enabled: true,
allowSwipe: true,
);
final ThemeSetting themeSetting = ThemeSetting(
backgroundColor: colorScheme.background,
selectionFillColor: colorScheme.primary,
selectionStrokeColor: colorScheme.onPrimary,
previewSubtitleAttributes: const TitleAttribute(fontSize: 12.0),
previewTitleAttributes: TitleAttribute(
foregroundColor: colorScheme.primary,
),
albumTitleAttributes: TitleAttribute(
foregroundColor: colorScheme.primary,
),
);
const ListSetting listSetting = ListSetting(
spacing: 5.0,
cellsPerRow: 4,
);
final CupertinoSettings iosSettings = CupertinoSettings(
fetch: const FetchSetting(album: albumSetting),
theme: themeSetting,
selection: selectionSetting,
dismiss: dismissSetting,
list: listSetting,
);
try {
resultList = await MultiImagePicker.pickImages(
selectedAssets: images,
iosOptions: IOSOptions(
doneButton:
UIBarButtonItem(title: 'Confirm', tintColor: colorScheme.primary),
cancelButton:
UIBarButtonItem(title: 'Cancel', tintColor: colorScheme.primary),
albumButtonColor: colorScheme.primary,
settings: iosSettings,
),
androidOptions: AndroidOptions(
actionBarColor: colorScheme.surface,
actionBarTitleColor: colorScheme.onSurface,
statusBarColor: colorScheme.surface,
actionBarTitle: "Select Photo",
allViewTitle: "All Photos",
useDetailsView: false,
selectCircleStrokeColor: colorScheme.primary,
exceptMimeType: {MimeType.PNG, MimeType.JPEG},
),
);
} on Exception catch (e) {
error = e.toString();
}
// 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 Scaffold(
appBar: AppBar(
title: const Text('Plugin example app'),
),
body: Column(
children: <Widget>[
Center(child: Text('Error: $_error')),
ElevatedButton(
onPressed: _loadAssets,
child: const Text("Pick images"),
),
Expanded(
child: _buildGridView(),
)
],
),
);
}
}