migrate example
This commit is contained in:
@@ -44,9 +44,9 @@ class StreamExample extends StatelessWidget {
|
||||
/// To initialize this example, an instance of
|
||||
/// [client] and [channel] is required.
|
||||
const StreamExample({
|
||||
Key key,
|
||||
@required this.client,
|
||||
@required this.channel,
|
||||
Key? key,
|
||||
required this.client,
|
||||
required this.channel,
|
||||
}) : super(key: key);
|
||||
|
||||
/// Instance of [StreamChatClient] we created earlier.
|
||||
@@ -69,28 +69,31 @@ class StreamExample extends StatelessWidget {
|
||||
/// containing the channel name and a [MessageView] displaying recent messages.
|
||||
class HomeScreen extends StatelessWidget {
|
||||
/// [HomeScreen] is constructed using the [Channel] we defined earlier.
|
||||
const HomeScreen({Key key, @required this.channel}) : super(key: key);
|
||||
const HomeScreen({
|
||||
Key? key,
|
||||
required this.channel,
|
||||
}) : super(key: key);
|
||||
|
||||
/// Channel object containing the [Channel.id] we'd like to observe.
|
||||
final Channel channel;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final messages = channel.state.channelStateStream;
|
||||
final messages = channel.state!.channelStateStream;
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text('Channel: ${channel.id}'),
|
||||
),
|
||||
body: SafeArea(
|
||||
child: StreamBuilder<ChannelState>(
|
||||
child: StreamBuilder<ChannelState?>(
|
||||
stream: messages,
|
||||
builder: (
|
||||
BuildContext context,
|
||||
AsyncSnapshot<ChannelState> snapshot,
|
||||
AsyncSnapshot<ChannelState?> snapshot,
|
||||
) {
|
||||
if (snapshot.hasData && snapshot.data != null) {
|
||||
return MessageView(
|
||||
messages: snapshot.data.messages.reversed.toList(),
|
||||
messages: snapshot.data!.messages.reversed.toList(),
|
||||
channel: channel,
|
||||
);
|
||||
} else if (snapshot.hasError) {
|
||||
@@ -119,9 +122,9 @@ class HomeScreen extends StatelessWidget {
|
||||
class MessageView extends StatefulWidget {
|
||||
/// Message takes the latest list of messages and the current channel.
|
||||
const MessageView({
|
||||
Key key,
|
||||
@required this.messages,
|
||||
@required this.channel,
|
||||
Key? key,
|
||||
required this.messages,
|
||||
required this.channel,
|
||||
}) : super(key: key);
|
||||
|
||||
/// List of messages sent in the given channel.
|
||||
@@ -135,8 +138,8 @@ class MessageView extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _MessageViewState extends State<MessageView> {
|
||||
TextEditingController _controller;
|
||||
ScrollController _scrollController;
|
||||
late final TextEditingController _controller;
|
||||
late final ScrollController _scrollController;
|
||||
|
||||
List<Message> get _messages => widget.messages;
|
||||
|
||||
@@ -174,12 +177,12 @@ class _MessageViewState extends State<MessageView> {
|
||||
reverse: true,
|
||||
itemBuilder: (BuildContext context, int index) {
|
||||
final item = _messages[index];
|
||||
if (item.user.id == widget.channel.client.uid) {
|
||||
if (item.user?.id == widget.channel.client.uid) {
|
||||
return Align(
|
||||
alignment: Alignment.centerRight,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(8),
|
||||
child: Text(item.text),
|
||||
child: Text(item.text ?? ''),
|
||||
),
|
||||
);
|
||||
} else {
|
||||
@@ -187,7 +190,7 @@ class _MessageViewState extends State<MessageView> {
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(8),
|
||||
child: Text(item.text),
|
||||
child: Text(item.text ?? ''),
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -246,5 +249,5 @@ class _MessageViewState extends State<MessageView> {
|
||||
/// Helper extension for quickly retrieving
|
||||
/// the current user id from a [StreamChatClient].
|
||||
extension on StreamChatClient {
|
||||
String get uid => state.user.id;
|
||||
String get uid => state.user!.id;
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ publish_to: "none"
|
||||
version: 1.0.0+1
|
||||
|
||||
environment:
|
||||
sdk: ">=2.7.0 <3.0.0"
|
||||
sdk: '>=2.12.0 <3.0.0'
|
||||
|
||||
dependencies:
|
||||
cupertino_icons: ^1.0.0
|
||||
|
||||
Reference in New Issue
Block a user