Skip to content

Commit

Permalink
fix(image_picker): update method to pickImage
Browse files Browse the repository at this point in the history
  • Loading branch information
jacob-i committed Jan 20, 2024
1 parent a901e42 commit 635e36c
Show file tree
Hide file tree
Showing 10 changed files with 42 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ SPEC CHECKSUMS:
DKImagePickerController: b512c28220a2b8ac7419f21c491fc8534b7601ac
DKPhotoGallery: fdfad5125a9fdda9cc57df834d49df790dbb4179
file_picker: 15fd9539e4eb735dc54bae8c0534a7a9511a03de
Flutter: f04841e97a9d0b0a8025694d0796dd46242b2854
Flutter: e0871f40cf51350855a761d2e70bf5af5b9b5de7
flutter_image_compress_common: ec1d45c362c9d30a3f6a0426c297f47c52007e3e
flutter_secure_storage: 23fc622d89d073675f2eaa109381aefbcf5a49be
flutter_tts: 0f492aab6accf87059b72354fcb4ba934304771d
Expand Down
6 changes: 6 additions & 0 deletions app/ios/Runner/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,11 @@
</array>
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
<key>NSPhotoLibraryUsageDescription</key>
<string>Why your app needs access to the photo library</string>
<key>NSCameraUsageDescription</key>
<string>Why your app needs access to the camera</string>
<key>NSMicrophoneUsageDescription</key>
<string>Why your app needs access to the microphone, if you intend to record videos</string>
</dict>
</plist>
16 changes: 15 additions & 1 deletion app/lib/utils/utils_desktop.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import 'dart:convert';
import 'dart:io';
import 'dart:typed_data';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:image_picker/image_picker.dart';
import 'package:path_provider/path_provider.dart';
import 'package:http/http.dart' as http;
import 'dart:ui' as ui;
Expand All @@ -25,7 +27,19 @@ class UtilsPlatform {
}

static Future<dynamic> pickImage() async {
throw UnsupportedError('pickImage is not supported on this platform.');
if (Platform.isIOS) {
final picker = ImagePicker();
final pickedFile = await picker.pickImage(source: ImageSource.gallery);
if (pickedFile != null) {
final File imageFile = File(pickedFile.path);
return imageFile.readAsBytes();
} else {
if (kDebugMode) {
print('No image selected.');
}
return null;
}
}
}

static Future<dynamic> startFilePicker() async {
Expand Down
8 changes: 8 additions & 0 deletions app/lib/views/widgets/paint_window.dart
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,14 @@ class PaintWindowState extends State<PaintWindow> {
}

Future<void> uploadImage() async {
Utils.pickImage().then((value) {
if (value != null) {
setState(() {
imgBytes = value;
});
}
});

/*final picker = ImagePicker();
final pickedFile = await picker.getImage(source: ImageSource.gallery);
Expand Down
4 changes: 4 additions & 0 deletions app/linux/flutter/generated_plugin_registrant.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,14 @@

#include "generated_plugin_registrant.h"

#include <file_selector_linux/file_selector_plugin.h>
#include <flutter_secure_storage_linux/flutter_secure_storage_linux_plugin.h>
#include <url_launcher_linux/url_launcher_plugin.h>

void fl_register_plugins(FlPluginRegistry* registry) {
g_autoptr(FlPluginRegistrar) file_selector_linux_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "FileSelectorPlugin");
file_selector_plugin_register_with_registrar(file_selector_linux_registrar);
g_autoptr(FlPluginRegistrar) flutter_secure_storage_linux_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "FlutterSecureStorageLinuxPlugin");
flutter_secure_storage_linux_plugin_register_with_registrar(flutter_secure_storage_linux_registrar);
Expand Down
1 change: 1 addition & 0 deletions app/linux/flutter/generated_plugins.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#

list(APPEND FLUTTER_PLUGIN_LIST
file_selector_linux
flutter_secure_storage_linux
url_launcher_linux
)
Expand Down
2 changes: 2 additions & 0 deletions app/macos/Flutter/GeneratedPluginRegistrant.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import FlutterMacOS
import Foundation

import file_selector_macos
import flutter_image_compress_macos
import flutter_secure_storage_macos
import flutter_tts
Expand All @@ -13,6 +14,7 @@ import shared_preferences_foundation
import url_launcher_macos

func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
FileSelectorPlugin.register(with: registry.registrar(forPlugin: "FileSelectorPlugin"))
FlutterImageCompressMacosPlugin.register(with: registry.registrar(forPlugin: "FlutterImageCompressMacosPlugin"))
FlutterSecureStoragePlugin.register(with: registry.registrar(forPlugin: "FlutterSecureStoragePlugin"))
FlutterTtsPlugin.register(with: registry.registrar(forPlugin: "FlutterTtsPlugin"))
Expand Down
1 change: 1 addition & 0 deletions app/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ dependencies:
flutter_highlight: ^0.7.0
webview_flutter: ^4.4.4
flutter_lints: ^3.0.1
image_picker: ^1.0.7
async: any

flutter:
Expand Down
3 changes: 3 additions & 0 deletions app/windows/flutter/generated_plugin_registrant.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@

#include "generated_plugin_registrant.h"

#include <file_selector_windows/file_selector_windows.h>
#include <flutter_secure_storage_windows/flutter_secure_storage_windows_plugin.h>
#include <flutter_tts/flutter_tts_plugin.h>
#include <url_launcher_windows/url_launcher_windows.h>

void RegisterPlugins(flutter::PluginRegistry* registry) {
FileSelectorWindowsRegisterWithRegistrar(
registry->GetRegistrarForPlugin("FileSelectorWindows"));
FlutterSecureStorageWindowsPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("FlutterSecureStorageWindowsPlugin"));
FlutterTtsPluginRegisterWithRegistrar(
Expand Down
1 change: 1 addition & 0 deletions app/windows/flutter/generated_plugins.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#

list(APPEND FLUTTER_PLUGIN_LIST
file_selector_windows
flutter_secure_storage_windows
flutter_tts
url_launcher_windows
Expand Down

0 comments on commit 635e36c

Please sign in to comment.