Created
April 21, 2022 19:54
-
-
Save deven98/ce007db57b41b38889eaaf16f2701580 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
import 'package:stream_chat_flutter/stream_chat_flutter.dart'; | |
void main() async { | |
WidgetsFlutterBinding.ensureInitialized(); | |
final client = StreamChatClient( | |
'YOUR_API_KEY', | |
logLevel: Level.INFO, | |
); | |
await client.connectUser( | |
User(id: 'YOUR_USER_ID'), | |
'''YOUR_USER_TOKEN''', | |
); | |
final channel = client.channel('messaging', id: 'YOUR_CHANNEL_ID'); | |
await channel.watch(); | |
runApp( | |
MyApp( | |
client: client, | |
channel: channel, | |
), | |
); | |
} | |
class MyApp extends StatelessWidget { | |
const MyApp({ | |
Key? key, | |
required this.client, | |
required this.channel, | |
}) : super(key: key); | |
final StreamChatClient client; | |
/// Instance of the Channel | |
final Channel channel; | |
@override | |
Widget build(BuildContext context) => MaterialApp( | |
theme: ThemeData.light(), | |
darkTheme: ThemeData.dark(), | |
builder: (context, widget) => StreamChat( | |
client: client, | |
child: widget, | |
), | |
home: StreamChannel( | |
channel: channel, | |
child: const ChannelPage(), | |
), | |
); | |
} | |
class ChannelPage extends StatefulWidget { | |
const ChannelPage({ | |
Key? key, | |
}) : super(key: key); | |
@override | |
State<ChannelPage> createState() => _ChannelPageState(); | |
} | |
class _ChannelPageState extends State<ChannelPage> { | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: const ChannelHeader(), | |
body: Column( | |
children: <Widget>[ | |
const Expanded( | |
child: MessageListView(), | |
), | |
MessageInput( | |
attachmentLimit: 3, | |
), | |
], | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment