Merge pull request #461 from Decodetalkers/feat/supportcopyimagefromclipboard

feat: paste image from clipboard
This commit is contained in:
Krille-chan 2023-07-20 19:46:45 +02:00 committed by GitHub
commit cd7d4582f8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 56 additions and 0 deletions

View file

@ -464,6 +464,22 @@ class ChatController extends State<ChatPageWithRoom> {
);
}
void sendImageFromClipBoard(Uint8List? image) async {
await showDialog(
context: context,
useRootNavigator: false,
builder: (c) => SendFileDialog(
files: [
MatrixFile(
bytes: image!,
name: "image from Clipboard",
).detectFileType,
],
room: room,
),
);
}
void sendImageAction() async {
final result = await FilePicker.platform.pickFiles(
type: FileType.image,

View file

@ -235,6 +235,7 @@ class ChatInputRow extends StatelessWidget {
textInputAction:
AppConfig.sendOnEnter ? TextInputAction.send : null,
onSubmitted: controller.onInputBarSubmitted,
onSubmitImage: controller.sendImageFromClipBoard,
focusNode: controller.inputFocus,
controller: controller.sendController,
decoration: InputDecoration(

View file

@ -5,6 +5,7 @@ import 'package:emojis/emoji.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart';
import 'package:flutter_typeahead/flutter_typeahead.dart';
import 'package:matrix/matrix.dart';
import 'package:pasteboard/pasteboard.dart';
import 'package:slugify/slugify.dart';
import 'package:fluffychat/config/app_config.dart';
@ -21,6 +22,7 @@ class InputBar extends StatelessWidget {
final TextInputType? keyboardType;
final TextInputAction? textInputAction;
final ValueChanged<String>? onSubmitted;
final ValueChanged<Uint8List?>? onSubmitImage;
final FocusNode? focusNode;
final TextEditingController? controller;
final InputDecoration? decoration;
@ -34,6 +36,7 @@ class InputBar extends StatelessWidget {
this.maxLines,
this.keyboardType,
this.onSubmitted,
this.onSubmitImage,
this.focusNode,
this.controller,
this.decoration,
@ -401,6 +404,10 @@ class InputBar extends StatelessWidget {
LogicalKeySet(LogicalKeyboardKey.shift, LogicalKeyboardKey.enter):
NewLineIntent(),
LogicalKeySet(LogicalKeyboardKey.enter): SubmitLineIntent(),
LogicalKeySet(
LogicalKeyboardKey.controlLeft,
LogicalKeyboardKey.keyM,
): PasteLineIntent()
},
child: Actions(
actions: !useShortCuts
@ -427,6 +434,16 @@ class InputBar extends StatelessWidget {
return null;
},
),
PasteLineIntent: CallbackAction(
onInvoke: (i) async {
final image = await Pasteboard.image;
if (image != null) {
onSubmitImage!(image);
return null;
}
return null;
},
)
},
child: TypeAheadField<Map<String, String?>>(
direction: AxisDirection.up,
@ -476,3 +493,5 @@ class InputBar extends StatelessWidget {
class NewLineIntent extends Intent {}
class SubmitLineIntent extends Intent {}
class PasteLineIntent extends Intent {}

View file

@ -14,6 +14,7 @@
#include <flutter_secure_storage_linux/flutter_secure_storage_linux_plugin.h>
#include <flutter_webrtc/flutter_web_r_t_c_plugin.h>
#include <handy_window/handy_window_plugin.h>
#include <pasteboard/pasteboard_plugin.h>
#include <record_linux/record_linux_plugin.h>
#include <url_launcher_linux/url_launcher_plugin.h>
#include <window_to_front/window_to_front_plugin.h>
@ -43,6 +44,9 @@ void fl_register_plugins(FlPluginRegistry* registry) {
g_autoptr(FlPluginRegistrar) handy_window_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "HandyWindowPlugin");
handy_window_plugin_register_with_registrar(handy_window_registrar);
g_autoptr(FlPluginRegistrar) pasteboard_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "PasteboardPlugin");
pasteboard_plugin_register_with_registrar(pasteboard_registrar);
g_autoptr(FlPluginRegistrar) record_linux_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "RecordLinuxPlugin");
record_linux_plugin_register_with_registrar(record_linux_registrar);

View file

@ -11,6 +11,7 @@ list(APPEND FLUTTER_PLUGIN_LIST
flutter_secure_storage_linux
flutter_webrtc
handy_window
pasteboard
record_linux
url_launcher_linux
window_to_front

View file

@ -23,6 +23,7 @@ import just_audio
import macos_ui
import macos_window_utils
import package_info_plus
import pasteboard
import path_provider_foundation
import record_macos
import share_plus
@ -53,6 +54,7 @@ func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
MacOSUiPlugin.register(with: registry.registrar(forPlugin: "MacOSUiPlugin"))
MacOSWindowUtilsPlugin.register(with: registry.registrar(forPlugin: "MacOSWindowUtilsPlugin"))
FLTPackageInfoPlusPlugin.register(with: registry.registrar(forPlugin: "FLTPackageInfoPlusPlugin"))
PasteboardPlugin.register(with: registry.registrar(forPlugin: "PasteboardPlugin"))
PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin"))
RecordMacosPlugin.register(with: registry.registrar(forPlugin: "RecordMacosPlugin"))
SharePlusMacosPlugin.register(with: registry.registrar(forPlugin: "SharePlusMacosPlugin"))

View file

@ -1261,6 +1261,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.0.1"
pasteboard:
dependency: "direct main"
description:
name: pasteboard
sha256: "1c8b6a8b3f1d12e55d4e9404433cda1b4abe66db6b17bc2d2fb5965772c04674"
url: "https://pub.dev"
source: hosted
version: "0.2.0"
path:
dependency: transitive
description:

View file

@ -66,6 +66,7 @@ dependencies:
matrix_homeserver_recommendations: ^0.3.0
native_imaging: ^0.1.0
package_info_plus: ^4.0.0
pasteboard: ^0.2.0
path_provider: ^2.0.9
permission_handler: ^10.0.0
pin_code_text_field: ^1.8.0

View file

@ -14,6 +14,7 @@
#include <file_selector_windows/file_selector_windows.h>
#include <flutter_secure_storage_windows/flutter_secure_storage_windows_plugin.h>
#include <flutter_webrtc/flutter_web_r_t_c_plugin.h>
#include <pasteboard/pasteboard_plugin.h>
#include <permission_handler_windows/permission_handler_windows_plugin.h>
#include <record_windows/record_windows_plugin_c_api.h>
#include <share_plus/share_plus_windows_plugin_c_api.h>
@ -37,6 +38,8 @@ void RegisterPlugins(flutter::PluginRegistry* registry) {
registry->GetRegistrarForPlugin("FlutterSecureStorageWindowsPlugin"));
FlutterWebRTCPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("FlutterWebRTCPlugin"));
PasteboardPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("PasteboardPlugin"));
PermissionHandlerWindowsPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("PermissionHandlerWindowsPlugin"));
RecordWindowsPluginCApiRegisterWithRegistrar(

View file

@ -11,6 +11,7 @@ list(APPEND FLUTTER_PLUGIN_LIST
file_selector_windows
flutter_secure_storage_windows
flutter_webrtc
pasteboard
permission_handler_windows
record_windows
share_plus