I’m growing an app utilizing flutterflow and have to randomly select a picture from the person’s gallery with out person motion (in each iOS and android). Clearly being a customized operate I used to be considering of writing it in dart.
I’ve already created this operate and it really works very effectively in android, however not in iOS.
That is the code I wrote:
// Automated FlutterFlow imports
import '/backend/backend.dart';
import '/backend/schema/structs/index.dart';
import '/backend/schema/enums/enums.dart';
import '/flutter_flow/flutter_flow_theme.dart';
import '/flutter_flow/flutter_flow_util.dart';
import '/custom_code/actions/index.dart'; // Imports different customized actions
import '/flutter_flow/custom_functions.dart'; // Imports customized features
import 'bundle:flutter/materials.dart';
// Start customized motion code
// DO NOT REMOVE OR MODIFY THE CODE ABOVE!
import 'dart:io';
import 'dart:math';
import 'bundle:file_picker/file_picker.dart';
Future<String> getRandomImagePath() async {
closing directories = [
Directory('/storage/emulated/0/DCIM'),
Directory('/storage/emulated/0/Pictures'),
Directory('/DCIM'),
Directory('/Pictures'),
Directory('/storage/emulated/0/DCIM/Camera'),
];
Record<FileSystemEntity> imageFiles = [];
Iterable<FileSystemEntity> newDirectories = [];
//search album inside folder
for (var listing in directories) {
if (await listing.exists()) {
closing components = await listing.listing().toList();
print(components);
newDirectories = components.the place((dir) => dir is Listing);
}
}
for (var listing in newDirectories) {
if (await listing.exists() && listing is Listing) {
directories.add(listing);
}
}
//search photographs inside folder
for (var listing in directories) {
if (await listing.exists()) {
closing information = await listing.listing().toList();
print('In questa $listing io vedo questi $information');
for (var file in information) {
if (file is File &&
(file.path.endsWith('.jpg') ||
file.path.endsWith('.jpeg') ||
file.path.endsWith('.png'))) {
imageFiles.add(file);
}
}
}
}
if (imageFiles.isNotEmpty) {
closing random = Random();
closing randomIndex = random.nextInt(imageFiles.size);
return imageFiles.elementAt(randomIndex).path;
}
return ""; // No picture discovered
}
What I would like is:
- possibility 1: modify this to make it work for each iOS and Android
- possibility 2: have one other operate to do the identical factor on iOS
I’ve tried varied issues however haven’t been capable of finding a approach to make it work.