Skip to content

Commit

Permalink
flutter_quill_extensions: replace gallery_saver with gal (#1403)
Browse files Browse the repository at this point in the history
  • Loading branch information
santiagos01 authored Sep 19, 2023
1 parent a39f45e commit 225a54a
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 8 deletions.
2 changes: 2 additions & 0 deletions example/macos/Flutter/GeneratedPluginRegistrant.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ import Foundation

import device_info_plus
import file_selector_macos
import gal
import pasteboard
import path_provider_foundation
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"))
Expand Down
3 changes: 3 additions & 0 deletions example/windows/flutter/generated_plugin_registrant.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@
#include "generated_plugin_registrant.h"

#include <file_selector_windows/file_selector_windows.h>
#include <gal/gal_plugin_c_api.h>
#include <pasteboard/pasteboard_plugin.h>
#include <url_launcher_windows/url_launcher_windows.h>

void RegisterPlugins(flutter::PluginRegistry* registry) {
FileSelectorWindowsRegisterWithRegistrar(
registry->GetRegistrarForPlugin("FileSelectorWindows"));
GalPluginCApiRegisterWithRegistrar(
registry->GetRegistrarForPlugin("GalPluginCApi"));
PasteboardPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("PasteboardPlugin"));
UrlLauncherWindowsRegisterWithRegistrar(
Expand Down
1 change: 1 addition & 0 deletions example/windows/flutter/generated_plugins.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

list(APPEND FLUTTER_PLUGIN_LIST
file_selector_windows
gal
pasteboard
url_launcher_windows
)
Expand Down
35 changes: 28 additions & 7 deletions flutter_quill_extensions/lib/embeds/builders.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import 'dart:io';

import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
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;

Expand Down Expand Up @@ -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(
Expand Down
3 changes: 2 additions & 1 deletion flutter_quill_extensions/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 225a54a

Please sign in to comment.