mirror of
https://github.com/chenasraf/pantry-flutter.git
synced 2026-05-17 17:28:03 +00:00
feat(ios): open full file picker when running on macOS
This commit is contained in:
12
lib/utils/platform_info.dart
Normal file
12
lib/utils/platform_info.dart
Normal file
@@ -0,0 +1,12 @@
|
||||
import 'dart:io' show Platform;
|
||||
|
||||
import 'package:device_info_plus/device_info_plus.dart';
|
||||
|
||||
bool? _isiOSAppOnMacCache;
|
||||
|
||||
Future<bool> isiOSAppOnMac() async {
|
||||
if (_isiOSAppOnMacCache != null) return _isiOSAppOnMacCache!;
|
||||
if (!Platform.isIOS) return _isiOSAppOnMacCache = false;
|
||||
final info = await DeviceInfoPlugin().iosInfo;
|
||||
return _isiOSAppOnMacCache = info.isiOSAppOnMac;
|
||||
}
|
||||
@@ -1,9 +1,11 @@
|
||||
import 'dart:math' as math;
|
||||
|
||||
import 'package:file_picker/file_picker.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:image_picker/image_picker.dart';
|
||||
|
||||
import 'package:pantry/i18n.dart';
|
||||
import 'package:pantry/utils/platform_info.dart';
|
||||
import 'package:pantry/views/photos/photo_board_controller.dart';
|
||||
|
||||
class PhotoAddButton extends StatefulWidget {
|
||||
@@ -52,6 +54,22 @@ class _PhotoAddButtonState extends State<PhotoAddButton>
|
||||
|
||||
Future<void> _pickPhotos() async {
|
||||
_close();
|
||||
final useFilePicker = await isiOSAppOnMac();
|
||||
if (useFilePicker) {
|
||||
final result = await FilePicker.pickFiles(
|
||||
allowMultiple: true,
|
||||
type: FileType.image,
|
||||
);
|
||||
if (result == null) return;
|
||||
final files = [
|
||||
for (final f in result.files)
|
||||
if (f.path != null) XFile(f.path!, name: f.name),
|
||||
];
|
||||
if (files.isNotEmpty) {
|
||||
widget.controller.uploadPhotos(files);
|
||||
}
|
||||
return;
|
||||
}
|
||||
final picker = ImagePicker();
|
||||
final files = await picker.pickMultiImage();
|
||||
if (files.isNotEmpty) {
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
import FlutterMacOS
|
||||
import Foundation
|
||||
|
||||
import device_info_plus
|
||||
import file_picker
|
||||
import file_selector_macos
|
||||
import flutter_local_notifications
|
||||
import flutter_secure_storage_darwin
|
||||
@@ -14,6 +16,8 @@ import url_launcher_macos
|
||||
import wakelock_plus
|
||||
|
||||
func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
|
||||
DeviceInfoPlusMacosPlugin.register(with: registry.registrar(forPlugin: "DeviceInfoPlusMacosPlugin"))
|
||||
FilePickerPlugin.register(with: registry.registrar(forPlugin: "FilePickerPlugin"))
|
||||
FileSelectorPlugin.register(with: registry.registrar(forPlugin: "FileSelectorPlugin"))
|
||||
FlutterLocalNotificationsPlugin.register(with: registry.registrar(forPlugin: "FlutterLocalNotificationsPlugin"))
|
||||
FlutterSecureStorageDarwinPlugin.register(with: registry.registrar(forPlugin: "FlutterSecureStorageDarwinPlugin"))
|
||||
|
||||
32
pubspec.lock
32
pubspec.lock
@@ -257,6 +257,22 @@ packages:
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "0.7.12"
|
||||
device_info_plus:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: device_info_plus
|
||||
sha256: b4fed1b2835da9d670d7bed7db79ae2a94b0f5ad6312268158a9b5479abbacdd
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "12.4.0"
|
||||
device_info_plus_platform_interface:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: device_info_plus_platform_interface
|
||||
sha256: e1ea89119e34903dca74b883d0dd78eb762814f97fb6c76f35e9ff74d261a18f
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "7.0.3"
|
||||
fake_async:
|
||||
dependency: transitive
|
||||
description:
|
||||
@@ -281,6 +297,14 @@ packages:
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "7.0.1"
|
||||
file_picker:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: file_picker
|
||||
sha256: f13a03000d942e476bc1ff0a736d2e9de711d2f89a95cd4c1d88f861c3348387
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "11.0.2"
|
||||
file_selector_linux:
|
||||
dependency: transitive
|
||||
description:
|
||||
@@ -1283,6 +1307,14 @@ packages:
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "5.15.0"
|
||||
win32_registry:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: win32_registry
|
||||
sha256: "6f1b564492d0147b330dd794fee8f512cec4977957f310f9951b5f9d83618dae"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.1.0"
|
||||
workmanager:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
|
||||
@@ -54,6 +54,8 @@ dependencies:
|
||||
package_info_plus: ^9.0.1
|
||||
mime: ^2.0.0
|
||||
receive_sharing_intent: ^1.8.1
|
||||
file_picker: ^11.0.2
|
||||
device_info_plus: ^12.4.0
|
||||
|
||||
dev_dependencies:
|
||||
flutter_test:
|
||||
|
||||
Reference in New Issue
Block a user