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:hooks_riverpod/hooks_riverpod.dart";
|
||||||
import "package:material_ui/material_ui.dart";
|
import "package:material_ui/material_ui.dart";
|
||||||
import "package:material_emoji_picker/src/controllers/emoji.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";
|
import "package:material_emoji_picker/src/models/emoji_category.dart";
|
||||||
|
|
||||||
class EmojiPicker extends HookConsumerWidget {
|
class EmojiPicker extends HookConsumerWidget {
|
||||||
|
|
@ -13,14 +14,17 @@ class EmojiPicker extends HookConsumerWidget {
|
||||||
this.prependCategories = const IList.empty(),
|
this.prependCategories = const IList.empty(),
|
||||||
this.appendCategories = const IList.empty(),
|
this.appendCategories = const IList.empty(),
|
||||||
required this.onSelection,
|
required this.onSelection,
|
||||||
this.allowFreeText = false,
|
this.onFreeText,
|
||||||
super.key,
|
super.key,
|
||||||
});
|
});
|
||||||
|
|
||||||
final IList<EmojiCategory> prependCategories;
|
final IList<EmojiCategory> prependCategories;
|
||||||
final IList<EmojiCategory> appendCategories;
|
final IList<EmojiCategory> appendCategories;
|
||||||
final FutureOr<void> Function(String value, bool isFreeText) onSelection;
|
/// Called with the emoji that was selected.
|
||||||
final bool allowFreeText;
|
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
|
@override
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
Widget build(BuildContext context, WidgetRef ref) {
|
||||||
|
|
@ -109,11 +113,11 @@ class EmojiPicker extends HookConsumerWidget {
|
||||||
leading: Icon(Icons.search),
|
leading: Icon(Icons.search),
|
||||||
onChanged: (value) => search.value = value,
|
onChanged: (value) => search.value = value,
|
||||||
trailing: [
|
trailing: [
|
||||||
if (allowFreeText)
|
if (onFreeText case final onFreeText?)
|
||||||
IconButton(
|
IconButton(
|
||||||
onPressed: search.value.isEmpty
|
onPressed: search.value.isEmpty
|
||||||
? null
|
? null
|
||||||
: () => onSelection(search.value, true),
|
: () => onFreeText(search.value),
|
||||||
icon: Icon(Icons.send),
|
icon: Icon(Icons.send),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
|
@ -214,7 +218,7 @@ class EmojiPicker extends HookConsumerWidget {
|
||||||
return IconButton(
|
return IconButton(
|
||||||
padding: EdgeInsets.zero,
|
padding: EdgeInsets.zero,
|
||||||
onPressed: () =>
|
onPressed: () =>
|
||||||
onSelection(emoji.value, false),
|
onSelection(emoji),
|
||||||
icon: SizedBox.square(
|
icon: SizedBox.square(
|
||||||
dimension: 36,
|
dimension: 36,
|
||||||
child: FittedBox(child: emoji.widget),
|
child: FittedBox(child: emoji.widget),
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue