feat: paste image from clipboard

This commit is contained in:
ShootingStarDragons 2023-07-20 22:56:35 +08:00 committed by Krille-chan
commit 2ae4551bcc
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 {}