change callbacks
This commit is contained in:
parent
55b8795992
commit
a5d772f036
1 changed files with 10 additions and 6 deletions
|
|
@ -6,6 +6,7 @@ import "package:flutter_hooks/flutter_hooks.dart";
|
|||
import "package:hooks_riverpod/hooks_riverpod.dart";
|
||||
import "package:material_ui/material_ui.dart";
|
||||
import "package:material_emoji_picker/src/controllers/emoji.dart";
|
||||
import "package:material_emoji_picker/src/models/emoji.dart";
|
||||
import "package:material_emoji_picker/src/models/emoji_category.dart";
|
||||
|
||||
class EmojiPicker extends HookConsumerWidget {
|
||||
|
|
@ -13,14 +14,17 @@ class EmojiPicker extends HookConsumerWidget {
|
|||
this.prependCategories = const IList.empty(),
|
||||
this.appendCategories = const IList.empty(),
|
||||
required this.onSelection,
|
||||
this.allowFreeText = false,
|
||||
this.onFreeText,
|
||||
super.key,
|
||||
});
|
||||
|
||||
final IList<EmojiCategory> prependCategories;
|
||||
final IList<EmojiCategory> appendCategories;
|
||||
final FutureOr<void> Function(String value, bool isFreeText) onSelection;
|
||||
final bool allowFreeText;
|
||||
/// Called with the emoji that was selected.
|
||||
final FutureOr<void> Function(Emoji emoji) onSelection;
|
||||
|
||||
/// If set, the search text can be submitted as is, calling this with it.
|
||||
final FutureOr<void> Function(String text)? onFreeText;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
|
|
@ -109,11 +113,11 @@ class EmojiPicker extends HookConsumerWidget {
|
|||
leading: Icon(Icons.search),
|
||||
onChanged: (value) => search.value = value,
|
||||
trailing: [
|
||||
if (allowFreeText)
|
||||
if (onFreeText case final onFreeText?)
|
||||
IconButton(
|
||||
onPressed: search.value.isEmpty
|
||||
? null
|
||||
: () => onSelection(search.value, true),
|
||||
: () => onFreeText(search.value),
|
||||
icon: Icon(Icons.send),
|
||||
),
|
||||
],
|
||||
|
|
@ -214,7 +218,7 @@ class EmojiPicker extends HookConsumerWidget {
|
|||
return IconButton(
|
||||
padding: EdgeInsets.zero,
|
||||
onPressed: () =>
|
||||
onSelection(emoji.value, false),
|
||||
onSelection(emoji),
|
||||
icon: SizedBox.square(
|
||||
dimension: 36,
|
||||
child: FittedBox(child: emoji.widget),
|
||||
|
|
|
|||
Loading…
Reference in a new issue