mirror of
https://github.com/Iconica-Development/flutter_chat.git
synced 2025-05-18 18:33:49 +02:00
feat: add tap to close keyboard on chat detail screen
This commit is contained in:
parent
3b4b456db2
commit
9b365d573d
1 changed files with 36 additions and 8 deletions
|
@ -497,19 +497,27 @@ class _ChatBody extends HookWidget {
|
||||||
bottomSpinner,
|
bottomSpinner,
|
||||||
];
|
];
|
||||||
|
|
||||||
|
var messageList = ListView.builder(
|
||||||
|
reverse: false,
|
||||||
|
controller: scrollController,
|
||||||
|
physics: const AlwaysScrollableScrollPhysics(),
|
||||||
|
padding: const EdgeInsets.only(top: 24),
|
||||||
|
itemCount: listViewChildren.length,
|
||||||
|
itemBuilder: (context, index) => listViewChildren[index],
|
||||||
|
);
|
||||||
|
|
||||||
return Column(
|
return Column(
|
||||||
children: [
|
children: [
|
||||||
if (chatIsLoading && options.enableLoadingIndicator) ...[
|
if (chatIsLoading && options.enableLoadingIndicator) ...[
|
||||||
Expanded(child: options.builders.loadingWidgetBuilder.call(context)),
|
Expanded(
|
||||||
|
child: _CloseKeyboardOnTap(
|
||||||
|
child: options.builders.loadingWidgetBuilder.call(context),
|
||||||
|
),
|
||||||
|
),
|
||||||
] else ...[
|
] else ...[
|
||||||
Expanded(
|
Expanded(
|
||||||
child: ListView.builder(
|
child: _CloseKeyboardOnTap(
|
||||||
reverse: false,
|
child: messageList,
|
||||||
controller: scrollController,
|
|
||||||
physics: const AlwaysScrollableScrollPhysics(),
|
|
||||||
padding: const EdgeInsets.only(top: 24),
|
|
||||||
itemCount: listViewChildren.length,
|
|
||||||
itemBuilder: (context, index) => listViewChildren[index],
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
@ -519,6 +527,26 @@ class _ChatBody extends HookWidget {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class _CloseKeyboardOnTap extends StatelessWidget {
|
||||||
|
const _CloseKeyboardOnTap({
|
||||||
|
required this.child,
|
||||||
|
});
|
||||||
|
|
||||||
|
final Widget child;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) => GestureDetector(
|
||||||
|
behavior: HitTestBehavior.translucent,
|
||||||
|
onTapUp: (_) {
|
||||||
|
var mediaQuery = MediaQuery.of(context);
|
||||||
|
if (mediaQuery.viewInsets.isNonNegative) {
|
||||||
|
FocusScope.of(context).unfocus();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
child: child,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/// Default widget used when displaying an error for chats.
|
/// Default widget used when displaying an error for chats.
|
||||||
class ErrorLoadingMessages extends StatelessWidget {
|
class ErrorLoadingMessages extends StatelessWidget {
|
||||||
/// Create default error displaying widget for error in loading messages
|
/// Create default error displaying widget for error in loading messages
|
||||||
|
|
Loading…
Reference in a new issue