Skip to content

Commit

Permalink
ImagePicker fix in settings and lazy load in chat
Browse files Browse the repository at this point in the history
  • Loading branch information
goranskular committed Aug 27, 2020
1 parent 663acaa commit 27bf232
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 7 deletions.
34 changes: 30 additions & 4 deletions lib/chat.dart
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ class ChatScreenState extends State<ChatScreen> {
String peerAvatar;
String id;

List<QueryDocumentSnapshot> listMessage;
List<QueryDocumentSnapshot> listMessage = new List.from([]);
int _limit = 20;
final int _limitIncrement = 20;
String groupChatId;
SharedPreferences prefs;

Expand All @@ -70,10 +72,31 @@ class ChatScreenState extends State<ChatScreen> {
final ScrollController listScrollController = ScrollController();
final FocusNode focusNode = FocusNode();

_scrollListener() {
if (listScrollController.offset >=
listScrollController.position.maxScrollExtent &&
!listScrollController.position.outOfRange) {
print("reach the bottom");
setState(() {
print("reach the bottom");
_limit += _limitIncrement;
});
}
if (listScrollController.offset <=
listScrollController.position.minScrollExtent &&
!listScrollController.position.outOfRange) {
print("reach the top");
setState(() {
print("reach the top");
});
}
}

@override
void initState() {
super.initState();
focusNode.addListener(onFocusChange);
listScrollController.addListener(_scrollListener);

groupChatId = '';

Expand Down Expand Up @@ -178,7 +201,10 @@ class ChatScreenState extends State<ChatScreen> {
listScrollController.animateTo(0.0,
duration: Duration(milliseconds: 300), curve: Curves.easeOut);
} else {
Fluttertoast.showToast(msg: 'Nothing to send');
Fluttertoast.showToast(
msg: 'Nothing to send',
backgroundColor: Colors.black,
textColor: Colors.red);
}
}

Expand Down Expand Up @@ -667,7 +693,7 @@ class ChatScreenState extends State<ChatScreen> {
.doc(groupChatId)
.collection(groupChatId)
.orderBy('timestamp', descending: true)
.limit(20)
.limit(_limit)
.snapshots(),
builder: (context, snapshot) {
if (!snapshot.hasData) {
Expand All @@ -676,7 +702,7 @@ class ChatScreenState extends State<ChatScreen> {
valueColor:
AlwaysStoppedAnimation<Color>(themeColor)));
} else {
listMessage = snapshot.data.documents;
listMessage.addAll(snapshot.data.documents);
return ListView.builder(
padding: EdgeInsets.all(10.0),
itemBuilder: (context, index) =>
Expand Down
9 changes: 6 additions & 3 deletions lib/settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,12 @@ class SettingsScreenState extends State<SettingsScreen> {
}

Future getImage() async {
ImagePicker imagePicker;
File image =
await imagePicker.getImage(source: ImageSource.gallery) as File;
ImagePicker imagePicker = ImagePicker();
PickedFile pickedFile;

pickedFile = await imagePicker.getImage(source: ImageSource.gallery);

File image = File(pickedFile.path);

if (image != null) {
setState(() {
Expand Down

0 comments on commit 27bf232

Please sign in to comment.