-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #46 from xsoulspace/emoji-and-info
Emoji and info
- Loading branch information
Showing
28 changed files
with
13,138 additions
and
98 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
part of abstract; | ||
|
||
@immutable | ||
@JsonSerializable() | ||
class Emoji { | ||
const Emoji({ | ||
required final this.category, | ||
required final this.emoji, | ||
required final this.keywords, | ||
}); | ||
static Emoji fromJson(final Map<String, dynamic> json) => | ||
_$EmojiFromJson(json); | ||
Map<String, dynamic> toJson() => _$EmojiToJson(this); | ||
final String category; | ||
final String emoji; | ||
final String keywords; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
part of widgets; | ||
|
||
class EmojiPopup extends HookWidget { | ||
const EmojiPopup({ | ||
required final this.controller, | ||
final Key? key, | ||
}) : super(key: key); | ||
final TextEditingController controller; | ||
@override | ||
Widget build(final BuildContext context) { | ||
final popupVisible = useIsBool(); | ||
final screenLayout = ScreenLayout.of(context); | ||
if (screenLayout.small && !isDesktop) return const SizedBox(); | ||
return PortalEntry( | ||
visible: popupVisible.value, | ||
portalAnchor: | ||
screenLayout.large ? Alignment.bottomLeft : Alignment.bottomRight, | ||
childAnchor: screenLayout.large ? Alignment.topRight : Alignment.topLeft, | ||
portal: EmojiGrid( | ||
onChanged: (final emoji) { | ||
final emojiChar = emoji.emoji; | ||
// Get cursor current position | ||
final cursorPos = controller.selection.base.offset; | ||
|
||
// Right text of cursor position | ||
final suffixText = controller.text.substring(cursorPos); | ||
|
||
// Add new text on cursor position | ||
final length = emojiChar.length; | ||
|
||
// Get the left text of cursor | ||
final prefixText = controller.text.substring(0, cursorPos); | ||
|
||
controller | ||
..text = prefixText + emojiChar + suffixText | ||
|
||
// Cursor move to end of added text | ||
..selection = TextSelection( | ||
baseOffset: cursorPos + length, | ||
extentOffset: cursorPos + length, | ||
); | ||
}, | ||
onClose: () => popupVisible.value = false, | ||
), | ||
child: MouseRegion( | ||
onHover: (final _) => popupVisible.value = true, | ||
child: IconButton( | ||
onPressed: () => popupVisible.value = !popupVisible.value, | ||
icon: const Icon(Icons.emoji_emotions), | ||
), | ||
), | ||
); | ||
} | ||
} | ||
|
||
class EmojiGrid extends ConsumerWidget { | ||
const EmojiGrid({ | ||
required final this.onChanged, | ||
required final this.onClose, | ||
final Key? key, | ||
}) : super(key: key); | ||
final ValueChanged<Emoji> onChanged; | ||
final VoidCallback onClose; | ||
@override | ||
Widget build(final BuildContext context, final WidgetRef ref) { | ||
final emojis = ref.read(emojisProvider); | ||
final theme = Theme.of(context); | ||
final borderColor = theme.brightness == Brightness.dark | ||
? AppColors.cleanBlack | ||
: AppColors.grey4; | ||
return Card( | ||
elevation: 0, | ||
clipBehavior: Clip.hardEdge, | ||
color: Colors.transparent, | ||
shape: RoundedRectangleBorder( | ||
borderRadius: defaultBorderRadius, | ||
side: BorderSide( | ||
color: borderColor, | ||
), | ||
), | ||
child: SizedBox( | ||
height: 300, | ||
width: 250, | ||
child: Stack( | ||
children: [ | ||
ColoredBox( | ||
color: theme.canvasColor.withOpacity(0.3), | ||
child: const SizedBox.expand(), | ||
).frosted( | ||
blur: theme.brightness == Brightness.dark ? 10 : 7, | ||
frostOpacity: 0.1, | ||
frostColor: theme.brightness == Brightness.dark | ||
? AppColors.cleanBlack | ||
: AppColors.white, | ||
), | ||
Column( | ||
mainAxisSize: MainAxisSize.min, | ||
children: [ | ||
Expanded( | ||
child: GridView.count( | ||
restorationId: 'emojis-grid', | ||
shrinkWrap: true, | ||
crossAxisCount: 6, | ||
children: emojis.values | ||
.map( | ||
(final e) => TextButton( | ||
key: ValueKey(e), | ||
onPressed: () => onChanged(e), | ||
child: Center( | ||
child: Text(e.emoji), | ||
), | ||
), | ||
) | ||
.toList(), | ||
), | ||
), | ||
Divider(color: borderColor, height: 1), | ||
Material( | ||
color: Colors.transparent, | ||
child: Row( | ||
children: [ | ||
IconButton( | ||
// constraints: BoxConstraints(maxHeight: 24), | ||
icon: const Icon(Icons.close), iconSize: 14, | ||
onPressed: onClose, | ||
), | ||
], | ||
), | ||
), | ||
], | ||
), | ||
], | ||
), | ||
), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
part of providers; | ||
|
||
final emojisProvider = | ||
StateNotifierProvider<MapState<Emoji>, Map<String, Emoji>>( | ||
(final _) => MapState<Emoji>(), | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.