From 20b3157473bd37c16552b0b6936a2373b92d1f94 Mon Sep 17 00:00:00 2001 From: Christian Pauly Date: Sat, 12 Dec 2020 17:19:53 +0100 Subject: [PATCH] feat: Implement emojipicker for reactions --- lib/views/chat.dart | 75 ++++++++++++++++++++++++++++++++------------- pubspec.lock | 49 +++++++++++++++++++++++++++++ pubspec.yaml | 1 + 3 files changed, 104 insertions(+), 21 deletions(-) diff --git a/lib/views/chat.dart b/lib/views/chat.dart index 27fa6af4..31c522a2 100644 --- a/lib/views/chat.dart +++ b/lib/views/chat.dart @@ -3,6 +3,7 @@ import 'dart:io'; import 'dart:math'; import 'package:adaptive_dialog/adaptive_dialog.dart'; +import 'package:emoji_picker/emoji_picker.dart'; import 'package:famedlysdk/famedlysdk.dart'; import 'package:file_picker_cross/file_picker_cross.dart'; import 'package:fluffychat/components/adaptive_page_layout.dart'; @@ -459,6 +460,34 @@ class _ChatState extends State<_Chat> { return filteredEvents; } + void _pickEmojiAction(BuildContext context) async { + final emoji = await showModalBottomSheet( + context: context, + backgroundColor: Colors.transparent, + builder: (context) => Column( + children: [ + Spacer(), + EmojiPicker( + onEmojiSelected: (emoji, category) => + Navigator.of(context).pop(emoji), + ), + ], + ), + ); + if (emoji == null) return; + return _sendEmojiAction(context, emoji.emoji); + } + + void _sendEmojiAction(BuildContext context, String emoji) { + SimpleDialogs(context).tryRequestWithLoadingDialog( + room.sendReaction( + selectedEvents.first.eventId, + emoji, + ), + ); + setState(() => selectedEvents.clear()); + } + @override Widget build(BuildContext context) { matrix = Matrix.of(context); @@ -830,28 +859,32 @@ class _ChatState extends State<_Chat> { }); return ListView.builder( scrollDirection: Axis.horizontal, - itemCount: emojis.length, - itemBuilder: (c, i) => InkWell( - borderRadius: BorderRadius.circular(8), - onTap: () { - SimpleDialogs(context).tryRequestWithLoadingDialog( - room.sendReaction( - selectedEvents.first.eventId, - emojis[i], + itemCount: emojis.length + 1, + itemBuilder: (c, i) => i == emojis.length + ? InkWell( + borderRadius: BorderRadius.circular(8), + child: Container( + width: 56, + height: 56, + alignment: Alignment.center, + child: Icon(Icons.add_outlined), + ), + onTap: () => _pickEmojiAction(context), + ) + : InkWell( + borderRadius: BorderRadius.circular(8), + onTap: () => + _sendEmojiAction(context, emojis[i]), + child: Container( + width: 56, + height: 56, + alignment: Alignment.center, + child: Text( + emojis[i], + style: TextStyle(fontSize: 30), + ), + ), ), - ); - setState(() => selectedEvents.clear()); - }, - child: Container( - width: 56, - height: 56, - alignment: Alignment.center, - child: Text( - emojis[i], - style: TextStyle(fontSize: 30), - ), - ), - ), ); }), ), diff --git a/pubspec.lock b/pubspec.lock index ea78ae4b..92ac65ee 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -183,6 +183,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "0.0.3" + emoji_picker: + dependency: "direct main" + description: + name: emoji_picker + url: "https://pub.dartlang.org" + source: hosted + version: "0.1.0" encrypt: dependency: transitive description: @@ -872,6 +879,48 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "0.6.5+4" + shared_preferences: + dependency: transitive + description: + name: shared_preferences + url: "https://pub.dartlang.org" + source: hosted + version: "0.5.12+4" + shared_preferences_linux: + dependency: transitive + description: + name: shared_preferences_linux + url: "https://pub.dartlang.org" + source: hosted + version: "0.0.2+4" + shared_preferences_macos: + dependency: transitive + description: + name: shared_preferences_macos + url: "https://pub.dartlang.org" + source: hosted + version: "0.0.1+11" + shared_preferences_platform_interface: + dependency: transitive + description: + name: shared_preferences_platform_interface + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.4" + shared_preferences_web: + dependency: transitive + description: + name: shared_preferences_web + url: "https://pub.dartlang.org" + source: hosted + version: "0.1.2+7" + shared_preferences_windows: + dependency: transitive + description: + name: shared_preferences_windows + url: "https://pub.dartlang.org" + source: hosted + version: "0.0.1+3" shelf: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index c47efeae..f070b071 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -64,6 +64,7 @@ dependencies: flutter_svg: 0.19.1 # Because fluffychat depends on flutter_svg >=0.19.2 which requires Flutter SDK version >=1.24.0-6.0.pre <2.0.0, version solving failed. flutter_cache_manager: ^2.0.0 open_noti_settings: ^0.0.4 + emoji_picker: ^0.1.0 dev_dependencies: flutter_test: