Member-only story

Flutter image picker

Nhan Cao
1 min readDec 13, 2020

lib

image_picker: ^0.6.7+14

Info.plist

<key>NSCameraUsageDescription</key>
<string>App requires access to the camera for avatar upload</string>
<key>NSPhotoLibraryUsageDescription</key>
<string>App requires access to the photo library for avatar upload</string>

AndroidManifest.xml

android:requestLegacyExternalStorage="true"

function

Future<void> _selectImageSource(BuildContext context) async {
// Close keyboard
FocusScope.of(context).requestFocus(FocusNode());
// Define max size of image
const double maxWidth = 350;
const double maxHeight = 500;
// Show choose image source
final List<String> source = <String>['Camera', 'Gallery'];
final List<CupertinoActionSheetAction> actions = source
.map((String it) => CupertinoActionSheetAction(
isDefaultAction: true,
onPressed: () {
// pop value
Navigator.pop<int>(context, source.indexOf(it));
},
child: Text(
it,
style: boldTextStyle(14, Colors.black),
),
))
.toList(growable: false);
final int index = await showCupertinoModalPopup<int>(
context: context,
builder: (BuildContext context) => CupertinoActionSheet(
actions: actions,
cancelButton: CupertinoActionSheetAction(
isDefaultAction…

--

--

No responses yet