diff --git a/example/macos/Flutter/GeneratedPluginRegistrant.swift b/example/macos/Flutter/GeneratedPluginRegistrant.swift index a6432e6e..8a76d078 100644 --- a/example/macos/Flutter/GeneratedPluginRegistrant.swift +++ b/example/macos/Flutter/GeneratedPluginRegistrant.swift @@ -7,6 +7,7 @@ import Foundation import device_info_plus import file_selector_macos +import gal import pasteboard import path_provider_foundation import url_launcher_macos @@ -14,6 +15,7 @@ import url_launcher_macos func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) { DeviceInfoPlusMacosPlugin.register(with: registry.registrar(forPlugin: "DeviceInfoPlusMacosPlugin")) FileSelectorPlugin.register(with: registry.registrar(forPlugin: "FileSelectorPlugin")) + GalPlugin.register(with: registry.registrar(forPlugin: "GalPlugin")) PasteboardPlugin.register(with: registry.registrar(forPlugin: "PasteboardPlugin")) PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin")) UrlLauncherPlugin.register(with: registry.registrar(forPlugin: "UrlLauncherPlugin")) diff --git a/example/windows/flutter/generated_plugin_registrant.cc b/example/windows/flutter/generated_plugin_registrant.cc index 7d98a882..bc268640 100644 --- a/example/windows/flutter/generated_plugin_registrant.cc +++ b/example/windows/flutter/generated_plugin_registrant.cc @@ -7,12 +7,15 @@ #include "generated_plugin_registrant.h" #include +#include #include #include void RegisterPlugins(flutter::PluginRegistry* registry) { FileSelectorWindowsRegisterWithRegistrar( registry->GetRegistrarForPlugin("FileSelectorWindows")); + GalPluginCApiRegisterWithRegistrar( + registry->GetRegistrarForPlugin("GalPluginCApi")); PasteboardPluginRegisterWithRegistrar( registry->GetRegistrarForPlugin("PasteboardPlugin")); UrlLauncherWindowsRegisterWithRegistrar( diff --git a/example/windows/flutter/generated_plugins.cmake b/example/windows/flutter/generated_plugins.cmake index 722afbe7..029549d7 100644 --- a/example/windows/flutter/generated_plugins.cmake +++ b/example/windows/flutter/generated_plugins.cmake @@ -4,6 +4,7 @@ list(APPEND FLUTTER_PLUGIN_LIST file_selector_windows + gal pasteboard url_launcher_windows ) diff --git a/flutter_quill_extensions/lib/embeds/builders.dart b/flutter_quill_extensions/lib/embeds/builders.dart index 6b392b8e..9eee9349 100644 --- a/flutter_quill_extensions/lib/embeds/builders.dart +++ b/flutter_quill_extensions/lib/embeds/builders.dart @@ -1,3 +1,5 @@ +import 'dart:io'; + import 'package:flutter/cupertino.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; @@ -5,7 +7,8 @@ import 'package:flutter/services.dart'; import 'package:flutter_quill/extensions.dart' as base; import 'package:flutter_quill/flutter_quill.dart' hide Text; import 'package:flutter_quill/translations.dart'; -import 'package:gallery_saver/gallery_saver.dart'; +import 'package:gal/gal.dart'; +import 'package:http/http.dart' as http; import 'package:math_keyboard/math_keyboard.dart'; import 'package:universal_html/html.dart' as html; @@ -266,13 +269,31 @@ Widget _menuOptionsForReadonlyImage( icon: Icons.save, color: Colors.greenAccent, text: 'Save'.i18n, - onPressed: () { + onPressed: () async { imageUrl = appendFileExtensionToImageUrl(imageUrl); - GallerySaver.saveImage(imageUrl).then((_) { - ScaffoldMessenger.of(context) - .showSnackBar(SnackBar(content: Text('Saved'.i18n))); - Navigator.pop(context); - }); + + // Download image + final uri = Uri.parse(imageUrl); + final response = await http.get(uri); + if (response.statusCode != 200) { + throw Exception( + 'failed to download image: ${response.statusCode}', + ); + } + + // Save image to a temporary path + final fileName = uri.pathSegments.isEmpty ? 'image.jpg' + : uri.pathSegments.last; + final imagePath = '${Directory.systemTemp.path}/menu-opt-$fileName'; + final imageFile = File(imagePath); + await imageFile.writeAsBytes(response.bodyBytes); + + // Save image to gallery + await Gal.putImage(imagePath); + + ScaffoldMessenger.of(context) + .showSnackBar(SnackBar(content: Text('Saved'.i18n))); + Navigator.pop(context); }, ); final zoomOption = _SimpleDialogItem( diff --git a/flutter_quill_extensions/pubspec.yaml b/flutter_quill_extensions/pubspec.yaml index 9b1d7fed..45c97270 100644 --- a/flutter_quill_extensions/pubspec.yaml +++ b/flutter_quill_extensions/pubspec.yaml @@ -14,11 +14,12 @@ dependencies: flutter_quill: ^7.2.19 + http: ^1.1.0 image_picker: ">=0.8.5 <2.0.0" photo_view: ^0.14.0 video_player: ^2.7.0 youtube_player_flutter: ^8.1.1 - gallery_saver: ^2.3.2 + gal: ^2.1.1 math_keyboard: ">=0.1.8 <0.3.0" string_validator: ^1.0.0 universal_html: ^2.2.1