getFromCamera function
Implementation
Future<List<File>> getFromCamera(
{List<File>? name,
int selectedImageNo = 5,
required BuildContext context}) async {
List<File> imageFiles = name.validate();
bool checkPermission = await checkCameraPermission;
if (checkPermission) {
await getCameraImage().then((value) {
if (imageFiles.validate().isNotEmpty) {
imageFiles.insert(0, value);
} else {
imageFiles.add(value);
}
if (imageFiles.length >= selectedImageNo) {
imageFiles.removeRange(selectedImageNo, imageFiles.length);
toast("Maximum ${selectedImageNo} Images you can add at a time.");
}
});
} else {
showDialog(
context: context,
barrierDismissible: false,
builder: (context) => AlertDialog(
title: Text(
"Go to Settings and grant permission for camera",
textAlign: TextAlign.center,
style: primaryTextStyle(
size: 16,
weight: FontWeight.bold,
),
),
actions: [
CommonPrimaryButton(
title: "Settings",
onTap: () {
finish(context);
openAppSettings();
},
),
const SizedBox(height: 10.0),
CommonPrimaryButton(
title: "Cancel",
onTap: () {
finish(context);
},
)
],
),
);
}
return imageFiles;
}