mobile
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
import 'dart:io';
|
||||
import 'package:image_picker/image_picker.dart';
|
||||
|
||||
class ImagePickerHelper {
|
||||
Future<dynamic> pickImage() async {
|
||||
final ImagePicker picker = ImagePicker();
|
||||
final XFile? pickedFile = await picker.pickImage(source: ImageSource.gallery);
|
||||
|
||||
if (pickedFile != null) {
|
||||
File imageFile = File(pickedFile.path);
|
||||
return imageFile;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
class ImagePickerHelper {
|
||||
Future<void> pickImage() async {
|
||||
throw UnsupportedError('pickImage is not supported on this platform');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
// import 'package:image_picker_web/image_picker_web.dart';
|
||||
// import 'dart:typed_data';
|
||||
|
||||
// class ImagePickerHelper {
|
||||
// Future<dynamic> pickImage() async {
|
||||
// Uint8List? bytesFromPicker = await ImagePickerWeb.getImageAsBytes();
|
||||
// if (bytesFromPicker != null) {
|
||||
// return bytesFromPicker;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
import 'dart:typed_data';
|
||||
import 'dart:html' as html;
|
||||
|
||||
class ImagePickerHelper {
|
||||
Future<void> pickImage() async {
|
||||
html.FileUploadInputElement uploadInput = html.FileUploadInputElement();
|
||||
uploadInput.accept = 'image/*';
|
||||
uploadInput.click();
|
||||
|
||||
uploadInput.onChange.listen((event) async {
|
||||
final file = uploadInput.files!.first;
|
||||
final reader = html.FileReader();
|
||||
|
||||
reader.readAsArrayBuffer(file);
|
||||
reader.onLoadEnd.listen((event) {
|
||||
Uint8List imageBytes = reader.result as Uint8List;
|
||||
if (imageBytes != null) {
|
||||
return imageBytes;
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
export 'image_picker_stub.dart'
|
||||
if (dart.library.html) 'image_picker_web.dart'
|
||||
if (dart.library.io) 'image_picker_mobile.dart';
|
||||
Reference in New Issue
Block a user