@@ -57,7 +57,9 @@ class ChatScreenState extends State<ChatScreen> {
57
57
String peerAvatar;
58
58
String id;
59
59
60
- List <QueryDocumentSnapshot > listMessage;
60
+ List <QueryDocumentSnapshot > listMessage = new List .from ([]);
61
+ int _limit = 20 ;
62
+ final int _limitIncrement = 20 ;
61
63
String groupChatId;
62
64
SharedPreferences prefs;
63
65
@@ -70,10 +72,31 @@ class ChatScreenState extends State<ChatScreen> {
70
72
final ScrollController listScrollController = ScrollController ();
71
73
final FocusNode focusNode = FocusNode ();
72
74
75
+ _scrollListener () {
76
+ if (listScrollController.offset >=
77
+ listScrollController.position.maxScrollExtent &&
78
+ ! listScrollController.position.outOfRange) {
79
+ print ("reach the bottom" );
80
+ setState (() {
81
+ print ("reach the bottom" );
82
+ _limit += _limitIncrement;
83
+ });
84
+ }
85
+ if (listScrollController.offset <=
86
+ listScrollController.position.minScrollExtent &&
87
+ ! listScrollController.position.outOfRange) {
88
+ print ("reach the top" );
89
+ setState (() {
90
+ print ("reach the top" );
91
+ });
92
+ }
93
+ }
94
+
73
95
@override
74
96
void initState () {
75
97
super .initState ();
76
98
focusNode.addListener (onFocusChange);
99
+ listScrollController.addListener (_scrollListener);
77
100
78
101
groupChatId = '' ;
79
102
@@ -178,7 +201,10 @@ class ChatScreenState extends State<ChatScreen> {
178
201
listScrollController.animateTo (0.0 ,
179
202
duration: Duration (milliseconds: 300 ), curve: Curves .easeOut);
180
203
} else {
181
- Fluttertoast .showToast (msg: 'Nothing to send' );
204
+ Fluttertoast .showToast (
205
+ msg: 'Nothing to send' ,
206
+ backgroundColor: Colors .black,
207
+ textColor: Colors .red);
182
208
}
183
209
}
184
210
@@ -667,7 +693,7 @@ class ChatScreenState extends State<ChatScreen> {
667
693
.doc (groupChatId)
668
694
.collection (groupChatId)
669
695
.orderBy ('timestamp' , descending: true )
670
- .limit (20 )
696
+ .limit (_limit )
671
697
.snapshots (),
672
698
builder: (context, snapshot) {
673
699
if (! snapshot.hasData) {
@@ -676,7 +702,7 @@ class ChatScreenState extends State<ChatScreen> {
676
702
valueColor:
677
703
AlwaysStoppedAnimation <Color >(themeColor)));
678
704
} else {
679
- listMessage = snapshot.data.documents;
705
+ listMessage. addAll ( snapshot.data.documents) ;
680
706
return ListView .builder (
681
707
padding: EdgeInsets .all (10.0 ),
682
708
itemBuilder: (context, index) =>
0 commit comments