Close keyboard when open toolbar

pull/1384/head
Kelrap 1 year ago
parent 276f3ee913
commit 7fdf9a5c92

@ -423,8 +423,9 @@ class ChatView extends StatelessWidget {
), ),
), ),
// #Pangea // #Pangea
// Keep messages above minimum input bar height
SizedBox( SizedBox(
height: (PlatformInfos.isMobile ? 15 : 50), height: (PlatformInfos.isMobile ? 24 : 50),
), ),
// Pangea# // Pangea#
], ],
@ -445,7 +446,7 @@ class ChatView extends StatelessWidget {
Positioned( Positioned(
left: 0, left: 0,
right: 0, right: 0,
bottom: 7, bottom: 13,
child: Column( child: Column(
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.center,

@ -58,10 +58,9 @@ class ToolbarDisplayController {
); );
} }
void showToolbar( void showToolbar(BuildContext context, {MessageMode? mode}) {
BuildContext context, { // Close keyboard, if open
MessageMode? mode, FocusManager.instance.primaryFocus?.unfocus();
}) {
bool toolbarUp = true; bool toolbarUp = true;
if (highlighted) return; if (highlighted) return;
if (controller.selectMode) { if (controller.selectMode) {
@ -87,12 +86,13 @@ class ToolbarDisplayController {
if (targetOffset.dy < 320) { if (targetOffset.dy < 320) {
final spaceBeneath = MediaQuery.of(context).size.height - final spaceBeneath = MediaQuery.of(context).size.height -
(targetOffset.dy + transformTargetSize.height); (targetOffset.dy + transformTargetSize.height);
if (spaceBeneath >= 320) { // If toolbar is open, opening toolbar beneath without scrolling can cause issues
toolbarUp = false; // if (spaceBeneath >= 320) {
} // toolbarUp = false;
// }
// See if it's possible to scroll up to make space // See if it's possible to scroll up to make space
else if (controller.scrollController.offset - targetOffset.dy + 320 >= if (controller.scrollController.offset - targetOffset.dy + 320 >=
controller.scrollController.position.minScrollExtent && controller.scrollController.position.minScrollExtent &&
controller.scrollController.offset - targetOffset.dy + 320 <= controller.scrollController.offset - targetOffset.dy + 320 <=
controller.scrollController.position.maxScrollExtent) { controller.scrollController.position.maxScrollExtent) {
@ -152,13 +152,7 @@ class ToolbarDisplayController {
? CrossAxisAlignment.end ? CrossAxisAlignment.end
: CrossAxisAlignment.start, : CrossAxisAlignment.start,
children: [ children: [
toolbarUp toolbarUp ? toolbar! : overlayMessage,
// Column is limited to screen height
// If message portion is too tall, decrease toolbar height
// as necessary to prevent toolbar from acting strange
// Problems may still occur if toolbar height is decreased too much
? toolbar!
: overlayMessage,
const SizedBox(height: 6), const SizedBox(height: 6),
toolbarUp ? overlayMessage : toolbar!, toolbarUp ? overlayMessage : toolbar!,
], ],
@ -419,85 +413,83 @@ class MessageToolbarState extends State<MessageToolbar> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Flexible( return Material(
child: Material( type: MaterialType.transparency,
type: MaterialType.transparency, child: Container(
child: Container( padding: const EdgeInsets.all(10),
padding: const EdgeInsets.all(10), decoration: BoxDecoration(
decoration: BoxDecoration( color: Theme.of(context).cardColor,
color: Theme.of(context).cardColor, border: Border.all(
border: Border.all( width: 2,
width: 2, color: Theme.of(context).colorScheme.primary,
color: Theme.of(context).colorScheme.primary,
),
borderRadius: const BorderRadius.all(
Radius.circular(25),
),
), ),
constraints: const BoxConstraints( borderRadius: const BorderRadius.all(
maxWidth: 300, Radius.circular(25),
minWidth: 300,
maxHeight: 300,
), ),
child: Column( ),
mainAxisSize: MainAxisSize.min, constraints: const BoxConstraints(
children: [ maxWidth: 300,
Flexible( minWidth: 300,
child: SingleChildScrollView( maxHeight: 300,
child: AnimatedSize( ),
duration: FluffyThemes.animationDuration, child: Column(
child: Column( mainAxisSize: MainAxisSize.min,
children: [ children: [
Padding( Flexible(
padding: const EdgeInsets.all(8.0), child: SingleChildScrollView(
child: toolbarContent ?? const SizedBox(), child: AnimatedSize(
), duration: FluffyThemes.animationDuration,
SizedBox(height: toolbarContent == null ? 0 : 20), child: Column(
], children: [
), Padding(
padding: const EdgeInsets.all(8.0),
child: toolbarContent ?? const SizedBox(),
),
SizedBox(height: toolbarContent == null ? 0 : 20),
],
), ),
), ),
), ),
Row( ),
mainAxisSize: MainAxisSize.min, Row(
children: MessageMode.values.map((mode) { mainAxisSize: MainAxisSize.min,
if ([ children: MessageMode.values.map((mode) {
MessageMode.definition, if ([
MessageMode.textToSpeech, MessageMode.definition,
MessageMode.translation, MessageMode.textToSpeech,
].contains(mode) && MessageMode.translation,
widget.pangeaMessageEvent.isAudioMessage) { ].contains(mode) &&
return const SizedBox.shrink(); widget.pangeaMessageEvent.isAudioMessage) {
} return const SizedBox.shrink();
if (mode == MessageMode.speechToText && }
!widget.pangeaMessageEvent.isAudioMessage) { if (mode == MessageMode.speechToText &&
return const SizedBox.shrink(); !widget.pangeaMessageEvent.isAudioMessage) {
} return const SizedBox.shrink();
return Tooltip( }
message: mode.tooltip(context), return Tooltip(
child: IconButton( message: mode.tooltip(context),
icon: Icon(mode.icon), child: IconButton(
color: mode.iconColor( icon: Icon(mode.icon),
widget.pangeaMessageEvent, color: mode.iconColor(
currentMode, widget.pangeaMessageEvent,
context, currentMode,
), context,
onPressed: () => updateMode(mode),
),
);
}).toList() +
[
Tooltip(
message: L10n.of(context)!.more,
child: IconButton(
icon: const Icon(Icons.add_reaction_outlined),
onPressed: showMore,
), ),
onPressed: () => updateMode(mode),
), ),
], );
), }).toList() +
], [
), Tooltip(
message: L10n.of(context)!.more,
child: IconButton(
icon: const Icon(Icons.add_reaction_outlined),
onPressed: showMore,
),
),
],
),
],
), ),
), ),
); );

Loading…
Cancel
Save