Skip to content

Commit

Permalink
feat: add image picking functionality for web
Browse files Browse the repository at this point in the history
  • Loading branch information
jacob-i committed Jan 23, 2024
1 parent c856bbc commit 846c613
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions app/lib/utils/utils_web.dart
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,28 @@ class UtilsPlatform {
}

static Future<dynamic> pickImage() async {
Completer completer = Completer<dynamic>();
// todo: implement pickImage
return completer.future;
// Create an input element for file upload
final uploadInput = html.FileUploadInputElement();
uploadInput.accept = 'image/*'; // Accept only image files

// Trigger the file picker dialog
uploadInput.click();

// Wait for the user to select a file
await uploadInput.onChange.first;

// Get the selected file
final file = uploadInput.files!.first;

// Read the file as data URL
final reader = html.FileReader();
reader.readAsDataUrl(file);

// Wait for the file to be read
await reader.onLoadEnd.first;

// Return the result
return reader.result;
}

static Future<dynamic> startFilePicker() async {
Expand Down

0 comments on commit 846c613

Please sign in to comment.