Merge branch 'master' into feat/pin-message
This commit is contained in:
@@ -120,7 +120,17 @@ class HomeScreen extends StatelessWidget {
|
|||||||
final _item = channels[index];
|
final _item = channels[index];
|
||||||
return ListTile(
|
return ListTile(
|
||||||
title: Text(_item.name),
|
title: Text(_item.name),
|
||||||
subtitle: Text(_item.state.lastMessage.text),
|
subtitle: StreamBuilder<Message>(
|
||||||
|
stream: _item.state.lastMessageStream,
|
||||||
|
initialData: _item.state.lastMessage,
|
||||||
|
builder: (context, snapshot) {
|
||||||
|
if (snapshot.hasData) {
|
||||||
|
return Text(snapshot.data.text);
|
||||||
|
}
|
||||||
|
|
||||||
|
return SizedBox();
|
||||||
|
},
|
||||||
|
),
|
||||||
onTap: () {
|
onTap: () {
|
||||||
/// Display a list of messages when the user taps on an item.
|
/// Display a list of messages when the user taps on an item.
|
||||||
/// We can use [StreamChannel] to wrap our [MessageScreen] screen
|
/// We can use [StreamChannel] to wrap our [MessageScreen] screen
|
||||||
@@ -161,6 +171,7 @@ class MessageScreen extends StatefulWidget {
|
|||||||
class _MessageScreenState extends State<MessageScreen> {
|
class _MessageScreenState extends State<MessageScreen> {
|
||||||
TextEditingController _controller;
|
TextEditingController _controller;
|
||||||
ScrollController _scrollController;
|
ScrollController _scrollController;
|
||||||
|
final messageListController = MessageListController();
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
@@ -191,68 +202,83 @@ class _MessageScreenState extends State<MessageScreen> {
|
|||||||
final channel = StreamChannel.of(context).channel;
|
final channel = StreamChannel.of(context).channel;
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
title: Text(channel.name),
|
title: StreamBuilder<List<User>>(
|
||||||
|
initialData: channel.state.typingEvents,
|
||||||
|
stream: channel.state.typingEventsStream,
|
||||||
|
builder: (context, snapshot) {
|
||||||
|
if (snapshot.hasData && snapshot.data.isNotEmpty) {
|
||||||
|
return Text('${snapshot.data.first.name} is typing...');
|
||||||
|
}
|
||||||
|
return SizedBox();
|
||||||
|
},
|
||||||
|
),
|
||||||
),
|
),
|
||||||
body: SafeArea(
|
body: SafeArea(
|
||||||
child: Column(
|
child: Column(
|
||||||
children: [
|
children: [
|
||||||
Expanded(
|
Expanded(
|
||||||
child: MessageListCore(
|
child: LazyLoadScrollView(
|
||||||
emptyBuilder: (BuildContext context) {
|
onEndOfPage: () async {
|
||||||
return Center(
|
messageListController.paginateData();
|
||||||
child: Text('Nothing here yet'),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
loadingBuilder: (BuildContext context) {
|
|
||||||
return Center(
|
|
||||||
child: SizedBox(
|
|
||||||
height: 100.0,
|
|
||||||
width: 100.0,
|
|
||||||
child: CircularProgressIndicator(),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
messageListBuilder: (
|
|
||||||
BuildContext context,
|
|
||||||
List<Message> messages,
|
|
||||||
) {
|
|
||||||
return ListView.builder(
|
|
||||||
controller: _scrollController,
|
|
||||||
itemCount: messages.length,
|
|
||||||
reverse: true,
|
|
||||||
itemBuilder: (BuildContext context, int index) {
|
|
||||||
final item = messages[index];
|
|
||||||
final client = StreamChatCore.of(context).client;
|
|
||||||
if (item.user.id == client.uid) {
|
|
||||||
return Align(
|
|
||||||
alignment: Alignment.centerRight,
|
|
||||||
child: Padding(
|
|
||||||
padding: const EdgeInsets.all(8.0),
|
|
||||||
child: Text(item.text),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
return Align(
|
|
||||||
alignment: Alignment.centerLeft,
|
|
||||||
child: Padding(
|
|
||||||
padding: const EdgeInsets.all(8.0),
|
|
||||||
child: Text(item.text),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
);
|
|
||||||
},
|
|
||||||
errorWidgetBuilder: (BuildContext context, error) {
|
|
||||||
print(error?.toString());
|
|
||||||
return Center(
|
|
||||||
child: SizedBox(
|
|
||||||
height: 100.0,
|
|
||||||
width: 100.0,
|
|
||||||
child: Text('Oh no, an error occured. Please see logs.'),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
},
|
},
|
||||||
|
child: MessageListCore(
|
||||||
|
emptyBuilder: (BuildContext context) {
|
||||||
|
return Center(
|
||||||
|
child: Text('Nothing here yet'),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
loadingBuilder: (BuildContext context) {
|
||||||
|
return Center(
|
||||||
|
child: SizedBox(
|
||||||
|
height: 100.0,
|
||||||
|
width: 100.0,
|
||||||
|
child: CircularProgressIndicator(),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
messageListBuilder: (
|
||||||
|
BuildContext context,
|
||||||
|
List<Message> messages,
|
||||||
|
) {
|
||||||
|
return ListView.builder(
|
||||||
|
controller: _scrollController,
|
||||||
|
itemCount: messages.length,
|
||||||
|
reverse: true,
|
||||||
|
itemBuilder: (BuildContext context, int index) {
|
||||||
|
final item = messages[index];
|
||||||
|
final client = StreamChatCore.of(context).client;
|
||||||
|
if (item.user.id == client.uid) {
|
||||||
|
return Align(
|
||||||
|
alignment: Alignment.centerRight,
|
||||||
|
child: Padding(
|
||||||
|
padding: const EdgeInsets.all(8.0),
|
||||||
|
child: Text(item.text),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
return Align(
|
||||||
|
alignment: Alignment.centerLeft,
|
||||||
|
child: Padding(
|
||||||
|
padding: const EdgeInsets.all(8.0),
|
||||||
|
child: Text(item.text),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
);
|
||||||
|
},
|
||||||
|
errorWidgetBuilder: (BuildContext context, error) {
|
||||||
|
print(error?.toString());
|
||||||
|
return Center(
|
||||||
|
child: SizedBox(
|
||||||
|
height: 100.0,
|
||||||
|
width: 100.0,
|
||||||
|
child:
|
||||||
|
Text('Oh no, an error occured. Please see logs.'),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
Padding(
|
Padding(
|
||||||
|
|||||||
Reference in New Issue
Block a user