Skip to content

Commit

Permalink
Fix not full screen layout
Browse files Browse the repository at this point in the history
  • Loading branch information
demchenkoalex committed Aug 29, 2021
1 parent d93cab9 commit 4f72e77
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 62 deletions.
62 changes: 40 additions & 22 deletions doc/advanced-usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,12 @@ class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Chat(
// ...
onAttachmentPressed: _handleImageSelection,
body: SafeArea(
bottom: false,
child: Chat(
// ...
onAttachmentPressed: _handleImageSelection,
),
),
);
}
Expand Down Expand Up @@ -97,9 +100,12 @@ class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Chat(
// ...
onAttachmentPressed: _handleFileSelection,
body: SafeArea(
bottom: false,
child: Chat(
// ...
onAttachmentPressed: _handleFileSelection,
),
),
);
}
Expand Down Expand Up @@ -127,9 +133,12 @@ class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Chat(
// ...
onMessageTap: _handleMessageTap,
body: SafeArea(
bottom: false,
child: Chat(
// ...
onMessageTap: _handleMessageTap,
),
),
);
}
Expand Down Expand Up @@ -160,9 +169,12 @@ class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Chat(
// ...
onPreviewDataFetched: _handlePreviewDataFetched,
body: SafeArea(
bottom: false,
child: Chat(
// ...
onPreviewDataFetched: _handlePreviewDataFetched,
),
),
);
}
Expand Down Expand Up @@ -346,13 +358,16 @@ class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Chat(
messages: _messages,
onAttachmentPressed: _handleAtachmentPressed,
onMessageTap: _handleMessageTap,
onPreviewDataFetched: _handlePreviewDataFetched,
onSendPressed: _handleSendPressed,
user: _user,
body: SafeArea(
bottom: false,
child: Chat(
messages: _messages,
onAttachmentPressed: _handleAtachmentPressed,
onMessageTap: _handleMessageTap,
onPreviewDataFetched: _handlePreviewDataFetched,
onSendPressed: _handleSendPressed,
user: _user,
),
),
);
}
Expand Down Expand Up @@ -405,9 +420,12 @@ class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Chat(
// ...
onEndReached: _handleEndReached,
body: SafeArea(
bottom: false,
child: Chat(
// ...
onEndReached: _handleEndReached,
),
),
);
}
Expand Down
11 changes: 7 additions & 4 deletions doc/basic-usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,13 @@ class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Chat(
messages: _messages,
onSendPressed: _handleSendPressed,
user: _user,
body: SafeArea(
bottom: false,
child: Chat(
messages: _messages,
onSendPressed: _handleSendPressed,
user: _user,
),
),
);
}
Expand Down
17 changes: 10 additions & 7 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -184,13 +184,16 @@ class _ChatPageState extends State<ChatPage> {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Chat(
messages: _messages,
onAttachmentPressed: _handleAtachmentPressed,
onMessageTap: _handleMessageTap,
onPreviewDataFetched: _handlePreviewDataFetched,
onSendPressed: _handleSendPressed,
user: _user,
body: SafeArea(
bottom: false,
child: Chat(
messages: _messages,
onAttachmentPressed: _handleAtachmentPressed,
onMessageTap: _handleMessageTap,
onPreviewDataFetched: _handlePreviewDataFetched,
onSendPressed: _handleSendPressed,
user: _user,
),
),
);
}
Expand Down
59 changes: 30 additions & 29 deletions lib/src/widgets/chat.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ import 'inherited_user.dart';
import 'input.dart';
import 'message.dart';

/// Entry widget, represents the complete chat
/// Entry widget, represents the complete chat. If you wrap it in [SafeArea] and
/// it should be full screen, set [SafeArea]'s `bottom` to `false`.
class Chat extends StatefulWidget {
/// Creates a chat widget
const Chat({
Expand Down Expand Up @@ -234,7 +235,7 @@ class _ChatState extends State<Chat> {
);
}

Widget _buildMessage(Object object) {
Widget _buildMessage(Object object, BoxConstraints constraints) {
if (object is DateHeader) {
return Container(
alignment: Alignment.center,
Expand All @@ -256,8 +257,8 @@ class _ChatState extends State<Chat> {
final message = map['message']! as types.Message;
final _messageWidth =
widget.showUserAvatars && message.author.id != widget.user.id
? min(MediaQuery.of(context).size.width * 0.72, 440).floor()
: min(MediaQuery.of(context).size.width * 0.78, 440).floor();
? min(constraints.maxWidth * 0.72, 440).floor()
: min(constraints.maxWidth * 0.78, 440).floor();

return Message(
key: ValueKey(message.id),
Expand Down Expand Up @@ -341,39 +342,39 @@ class _ChatState extends State<Chat> {
children: [
Container(
color: widget.theme.backgroundColor,
child: SafeArea(
bottom: false,
child: Column(
children: [
Flexible(
child: widget.messages.isEmpty
? SizedBox.expand(
child: _buildEmptyState(),
)
: GestureDetector(
onTap: () => FocusManager.instance.primaryFocus
?.unfocus(),
child: ChatList(
child: Column(
children: [
Flexible(
child: widget.messages.isEmpty
? SizedBox.expand(
child: _buildEmptyState(),
)
: GestureDetector(
onTap: () =>
FocusManager.instance.primaryFocus?.unfocus(),
child: LayoutBuilder(
builder: (BuildContext context,
BoxConstraints constraints) =>
ChatList(
isLastPage: widget.isLastPage,
itemBuilder: (item, index) =>
_buildMessage(item),
_buildMessage(item, constraints),
items: _chatMessages,
onEndReached: widget.onEndReached,
onEndReachedThreshold:
widget.onEndReachedThreshold,
),
),
),
Input(
isAttachmentUploading: widget.isAttachmentUploading,
onAttachmentPressed: widget.onAttachmentPressed,
onSendPressed: widget.onSendPressed,
onTextChanged: widget.onTextChanged,
sendButtonVisibilityMode:
widget.sendButtonVisibilityMode,
),
],
),
),
),
Input(
isAttachmentUploading: widget.isAttachmentUploading,
onAttachmentPressed: widget.onAttachmentPressed,
onSendPressed: widget.onSendPressed,
onTextChanged: widget.onTextChanged,
sendButtonVisibilityMode: widget.sendButtonVisibilityMode,
),
],
),
),
if (_isImageViewVisible) _buildImageGallery(),
Expand Down

0 comments on commit 4f72e77

Please sign in to comment.