Skip to content

Commit

Permalink
feat(utils_web): implement pickImage function
Browse files Browse the repository at this point in the history
  • Loading branch information
jacob-i committed Jan 19, 2024
1 parent d3bb85d commit ea96617
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
2 changes: 2 additions & 0 deletions app/lib/utils/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ abstract class Utils {
static Future<void> downloadImage(String url, String description) async =>
UtilsPlatform.downloadImage(url, description);

static Future<dynamic> pickImage() async => UtilsPlatform.pickImage();

static Future<dynamic> startFilePicker() async =>
UtilsPlatform.startFilePicker();

Expand Down
7 changes: 6 additions & 1 deletion app/lib/utils/utils_desktop.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ class UtilsPlatform {
}
}

static Future<dynamic> pickImage() async {
throw UnsupportedError('pickImage is not supported on this platform.');
}

static Future<dynamic> startFilePicker() async {
throw UnsupportedError(
'startFilePicker is not supported on this platform.');
Expand All @@ -44,7 +48,8 @@ class UtilsPlatform {
final ui.Canvas canvas = ui.Canvas(recorder);

// Fill the canvas with a white background
final ui.Paint paintBackground = ui.Paint()..color = const ui.Color(0xFFFFFFFF);
final ui.Paint paintBackground = ui.Paint()
..color = const ui.Color(0xFFFFFFFF);
canvas.drawRect(ui.Rect.fromLTWH(0, 0, width.toDouble(), height.toDouble()),
paintBackground);

Expand Down
4 changes: 4 additions & 0 deletions app/lib/utils/utils_stub.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ class UtilsPlatform {
throw UnsupportedError('downloadImage is not supported on this platform.');
}

static Future<dynamic> pickImage() async {
throw UnsupportedError('pickImage is not supported on this platform.');
}

static Future<dynamic> startFilePicker() async {
throw UnsupportedError(
'startFilePicker is not supported on this platform.');
Expand Down
11 changes: 10 additions & 1 deletion app/lib/utils/utils_web.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'dart:async';
import 'dart:convert';
import 'dart:html' as html;
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';

// Uncomment the next line to compile the web version
Expand Down Expand Up @@ -69,6 +70,12 @@ class UtilsPlatform {
return Future.value();
}

static Future<dynamic> pickImage() async {
Completer completer = Completer<dynamic>();
// todo: implement pickImage
return completer.future;
}

static Future<dynamic> startFilePicker() async {
Completer completer = Completer<dynamic>();
try {
Expand Down Expand Up @@ -100,7 +107,9 @@ class UtilsPlatform {

uploadInput.click();
} catch (e) {
print('Error: $e'); // Log the exception
if (kDebugMode) {
print('Error: $e'); // Log the exception
} // Log the exception
completer.completeError(e);
}

Expand Down

0 comments on commit ea96617

Please sign in to comment.