3

I am facing some issue when I click on the comment box the keyboard appear and then quickly disappear and reload the complete page here is the complete code.

 StreamBuilder(
                  stream: reviewStream,
                  builder: (context, AsyncSnapshot<QuerySnapshot> snapshot) {
                    if (snapshot.connectionState == ConnectionState.waiting) {
                      return Center(child: CircularProgressIndicator());
                    }
                    final List reviewList = [];
                    snapshot.data!.docs.map((DocumentSnapshot e) {
                      Map dataList = e.data() as Map<String, dynamic>;
                      reviewList.add(dataList);
                    }).toList();
                    final Stream<QuerySnapshot> reviewDisplayStream =
                        FirebaseFirestore.instance
                            .collection("customer")
                            .where("uid", isEqualTo: userId)
                            .snapshots();
                    return SafeArea(
                      child: userId == ""
                          ? logincommentChild(reviewList)
                          : StreamBuilder(
                              stream: reviewDisplayStream,
                              builder:
                                  (context, AsyncSnapshot<QuerySnapshot> snapshot) {
                                if (snapshot.connectionState ==
                                    ConnectionState.waiting) {
                                  return Center(child: CircularProgressIndicator());
                                }
                                final List reviewDisplayList = [];
                                snapshot.data!.docs.map((DocumentSnapshot e) {
                                  Map dataList = e.data() as Map<String, dynamic>;
                                  reviewDisplayList.add(dataList);
                                }).toList();
                                return Container(
                                    child: CommentBox(
                                  userImage: reviewDisplayList[0]['image'] != ''
                                      ? reviewDisplayList[0]['image']
                                      : "https://firebasestorage.googleapis.com/v0/b/fir-prictice-81c0f.appspot.com/o/profile.png?alt=media&token=8fdf702b-8f5a-4a12-b46a-091758812a5d",
                                  child: commentChild(
                                      reviewList), //display review of cusotmer....
                                  labelText: 'Write a breif review...',
                                  withBorder: true,
                                  errorText: 'Review cannot be blank',
                                  sendButtonMethod: () {
                                    if (formKey.currentState!.validate()) {
                                      print(commentController.text);
                                      setState(() async {
                                        Map<String, dynamic> value = {
                                          'name': reviewDisplayList[0]['name'],
                                          'pic': reviewDisplayList[0]['image'] != ''
                                              ? reviewDisplayList[0]['image']
                                              : "https://firebasestorage.googleapis.com/v0/b/fir-prictice-81c0f.appspot.com/o/profile.png?alt=media&token=8fdf702b-8f5a-4a12-b46a-091758812a5d",
                                          'message': commentController.text,
                                          'date and time': date
                                        };
                                        FirebaseFirestore.instance
                                            .collection("Review")
                                            .add(value);
                                      });
                                      commentController.clear();
                                      FocusScope.of(context).unfocus();
                                    } else {
                                      print("Not validated");
                                    }
                                  },
                                  formKey: formKey,
                                  commentController: commentController,
                                  backgroundColor: Colors.blue,
                                  textColor: Colors.white,
                                  sendWidget: Icon(Icons.send_sharp,
                                      size: 24, color: Colors.white),
                                ));
                              }),
                    );
                  })

BenMorel
  • 34,448
  • 50
  • 182
  • 322
  • ```FocusScope.of(context).unfocus();``` this code is changing the state of the widget which reload again the page. so as the result keyboard disappear. – Shahryar Rafique Oct 21 '21 at 06:13

0 Answers0