@@ -17,8 +17,7 @@ Future<void> main() async {
1717 User (
1818 id: 'cool-shadow-7' ,
1919 name: 'Cool Shadow' ,
20- image:
21- 'https://getstream.io/random_png/?id=cool-shadow-7&name=Cool+shadow' ,
20+ image: 'https://getstream.io/random_png/?id=cool-shadow-7&name=Cool+shadow' ,
2221 ),
2322 '''eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoiY29vbC1zaGFkb3ctNyJ9.gkOlCRb1qgy4joHPaxFwPOdXcGvSPvp6QY0S4mpRkVo''' ,
2423 );
@@ -60,9 +59,9 @@ class StreamExample extends StatelessWidget {
6059
6160 @override
6261 Widget build (BuildContext context) => MaterialApp (
63- title: 'Stream Chat Dart Example' ,
64- home: HomeScreen (channel: channel),
65- );
62+ title: 'Stream Chat Dart Example' ,
63+ home: HomeScreen (channel: channel),
64+ );
6665}
6766
6867/// Main screen of our application. The layout is comprised of an [AppBar]
@@ -87,30 +86,31 @@ class HomeScreen extends StatelessWidget {
8786 body: SafeArea (
8887 child: StreamBuilder <List <Message >?>(
8988 stream: messages,
90- builder: (
91- BuildContext context,
92- AsyncSnapshot <List <Message >?> snapshot,
93- ) {
94- if (snapshot.hasData && snapshot.data != null ) {
95- return MessageView (
96- messages: snapshot.data! .reversed.toList (),
97- channel: channel,
98- );
99- } else if (snapshot.hasError) {
100- return const Center (
101- child: Text (
102- 'There was an error loading messages. Please see logs.' ,
103- ),
104- );
105- }
106- return const Center (
107- child: SizedBox (
108- width: 100 ,
109- height: 100 ,
110- child: CircularProgressIndicator (),
111- ),
112- );
113- },
89+ builder:
90+ (
91+ BuildContext context,
92+ AsyncSnapshot <List <Message >?> snapshot,
93+ ) {
94+ if (snapshot.hasData && snapshot.data != null ) {
95+ return MessageView (
96+ messages: snapshot.data! .reversed.toList (),
97+ channel: channel,
98+ );
99+ } else if (snapshot.hasError) {
100+ return const Center (
101+ child: Text (
102+ 'There was an error loading messages. Please see logs.' ,
103+ ),
104+ );
105+ }
106+ return const Center (
107+ child: SizedBox (
108+ width: 100 ,
109+ height: 100 ,
110+ child: CircularProgressIndicator (),
111+ ),
112+ );
113+ },
114114 ),
115115 ),
116116 );
@@ -168,80 +168,80 @@ class _MessageViewState extends State<MessageView> {
168168
169169 @override
170170 Widget build (BuildContext context) => Column (
171- children: [
172- Expanded (
173- child: ListView .builder (
174- controller: _scrollController,
175- itemCount: _messages.length,
176- reverse: true ,
177- itemBuilder: (BuildContext context, int index) {
178- final item = _messages[index];
179- if (item.user? .id == widget.channel.client.uid) {
180- return Align (
181- alignment: Alignment .centerRight,
182- child: Padding (
183- padding: const EdgeInsets .all (8 ),
184- child: Text (item.text ?? '' ),
185- ),
186- );
187- } else {
188- return Align (
189- alignment: Alignment .centerLeft,
190- child: Padding (
191- padding: const EdgeInsets .all (8 ),
192- child: Text (item.text ?? '' ),
193- ),
194- );
195- }
196- },
197- ),
198- ),
199- Padding (
200- padding: const EdgeInsets .all (8 ),
201- child: Row (
202- children: [
203- Expanded (
204- child: TextField (
205- controller: _controller,
206- decoration: const InputDecoration (
207- hintText: 'Enter your message' ,
208- ),
209- ),
171+ children: [
172+ Expanded (
173+ child: ListView .builder (
174+ controller: _scrollController,
175+ itemCount: _messages.length,
176+ reverse: true ,
177+ itemBuilder: (BuildContext context, int index) {
178+ final item = _messages[index];
179+ if (item.user? .id == widget.channel.client.uid) {
180+ return Align (
181+ alignment: Alignment .centerRight,
182+ child: Padding (
183+ padding: const EdgeInsets .all (8 ),
184+ child: Text (item.text ?? '' ),
185+ ),
186+ );
187+ } else {
188+ return Align (
189+ alignment: Alignment .centerLeft,
190+ child: Padding (
191+ padding: const EdgeInsets .all (8 ),
192+ child: Text (item.text ?? '' ),
193+ ),
194+ );
195+ }
196+ },
197+ ),
198+ ),
199+ Padding (
200+ padding: const EdgeInsets .all (8 ),
201+ child: Row (
202+ children: [
203+ Expanded (
204+ child: TextField (
205+ controller: _controller,
206+ decoration: const InputDecoration (
207+ hintText: 'Enter your message' ,
210208 ),
211- Material (
212- type : MaterialType .circle ,
213- color : Colors .blue,
214- clipBehavior : Clip .hardEdge ,
215- child : InkWell (
216- onTap : () async {
217- // We can send a new message by calling `sendMessage` on
218- // the current channel. After sending a message, the
219- // TextField is cleared and the list view is scrolled
220- // to show the new item.
221- if (_controller.value.text.isNotEmpty) {
222- await widget.channel. sendMessage (
223- Message (text : _controller.value.text),
224- );
225- _controller.clear ();
226- _updateList ( );
227- }
228- },
229- child : const Padding (
230- padding : EdgeInsets . all ( 8 ) ,
231- child: Center (
232- child : Icon (
233- Icons .send,
234- color : Colors .white,
235- ) ,
236- ) ,
209+ ),
210+ ) ,
211+ Material (
212+ type : MaterialType .circle ,
213+ color : Colors .blue,
214+ clipBehavior : Clip .hardEdge,
215+ child : InkWell (
216+ onTap : () async {
217+ // We can send a new message by calling `sendMessage` on
218+ // the current channel. After sending a message, the
219+ // TextField is cleared and the list view is scrolled
220+ // to show the new item.
221+ if ( _controller.value.text.isNotEmpty) {
222+ await widget.channel. sendMessage (
223+ Message (text : _controller.value.text),
224+ );
225+ _controller. clear ();
226+ _updateList ();
227+ }
228+ } ,
229+ child: const Padding (
230+ padding : EdgeInsets . all ( 8 ),
231+ child : Center (
232+ child : Icon (
233+ Icons .send ,
234+ color : Colors .white ,
237235 ),
238236 ),
239237 ),
240- ] ,
238+ ) ,
241239 ),
242- ),
243- ],
244- );
240+ ],
241+ ),
242+ ),
243+ ],
244+ );
245245}
246246
247247/// Helper extension for quickly retrieving
0 commit comments