return FutureBuilder()

in frontend/frontend-flutter/lib/main.dart [517:798]


    return FutureBuilder(
      future: loadQuestionsFromFirestore(),
      builder: (context, snapshot) {
        return SideMenu(
          controller: sideMenu,
          style: SideMenuStyle(
            // showTooltip: false,
            displayMode: SideMenuDisplayMode.open,
            showHamburger: true,
            hoverColor: Colors.blue[100],
            selectedHoverColor: Colors.blue[100],
            selectedColor: Colors.lightBlue,
            selectedTitleTextStyle: const TextStyle(color: Colors.black),
            selectedIconColor: Colors.white,
          ),
          title: Column(
            children: [
              ConstrainedBox(
                constraints: const BoxConstraints(
                  maxHeight: 100,
                  maxWidth: 250,
                ),
                child: Image.asset(
                  'assets/images/ttmd_logo1.png', //'assets/images/drawer_header1.png',
                ),
              ),
              const Divider(
                indent: 8.0,
                endIndent: 8.0,
              ),
            ],
          ),
          footer: Padding(
            padding: const EdgeInsets.only(top: 8.0),
            child: ConstrainedBox(
              constraints: const BoxConstraints(
                maxHeight: 80,
              ),
              child: Container(
                color: const Color.fromARGB(
                    255, 240, 240, 240), // Colors.grey.withOpacity(1),////
                child: Column(
                  children: [
                    const Divider(
                      indent: 8.0,
                      endIndent: 8.0,
                    ),
                    Row(
                      mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                      mainAxisSize: MainAxisSize.max,
                      children: [
                        CircleAvatar(
                          backgroundImage:
                              //const AssetImage('assets/images/john_smith.jpeg'),
                              NetworkImage(TextToDocParameter.picture),
                          radius: 30,
                        ),
                        Text("${TextToDocParameter.email}",
                            style: TextStyle(
                                color: Colors.blueAccent, fontSize: 12.0),
                            textAlign: TextAlign.end),
                      ],
                    ),
                  ],
                ),
              ),
            ),
          ),
          items: [
            SideMenuItem(
              title: 'Open data QnA',
              onTap: (index, _) {
                //sideMenu.changePage(index);
              },
              icon: const Icon(Icons.home),
              tooltipContent: "Open data QnA",
            ),
            SideMenuItem(
              title: 'New chat',
              onTap: (index, _) {
                TextToDocParameter.sessionId = "";
                print(
                    "Main: _createSideMenu() : New chat :  : TextToDocParameter.sessionId = ${TextToDocParameter.sessionId}");
              },
              icon: const Icon(Icons.restart_alt_outlined),
            ),
            if (snapshot.hasData) //if (TextToDocParameter.expert_mode)
              SideMenuExpansionItem(
                title: "Imported questions",
                icon: const Icon(Icons.manage_history_outlined),
                children: [
                  SideMenuItem(
                    builder: (context, displayMode) {
                      return ExpandableTree(
                        nodes: importedQuestionTreeNodeList,
                        nodeBuilder: _nodeBuilder2,
                        onSelect: (node) => _nodeSelected(context, node),
                      );
                    },
                    onTap: (index, _) {
                      //sideMenu.changePage(index);
                    },
                  )
                ],
              ),
            SideMenuExpansionItem(
              title: "History",
              icon: const Icon(Icons.manage_history_outlined),
              children: [
                SideMenuItem(
                  builder: (context, displayMode) {
                    return BlocBuilder<LoadQuestionCubit, LoadQuestionState>(
                      builder: (context, state) {
                        print(
                            "Main: _createSideMenu() : BlocBuilder<LoadQuestionCubit, LoadQuestionState> : state = $state");
                        print(
                            "Main: _createSideMenu() : BlocBuilder<LoadQuestionCubit, LoadQuestionState> : state.question = ${state.question}");
                        print(
                            "Main: _createSideMenu() : BlocBuilder<LoadQuestionCubit, LoadQuestionState> : state.time = ${state.time}");
                        _addData(state.question!, true);
                        return ExpandableTree(
                          nodes: nodes,
                          nodeBuilder: _nodeBuilder1,
                          onSelect: (node) => _nodeSelected1(context, node),
                        );
                      },
                    );
                  },
                  onTap: (index, _) {
                    //sideMenu.changePage(index);
                  },
                )
              ],
            ),
            SideMenuExpansionItem(
              title: "Most popular questions",
              icon: const Icon(Icons.manage_history_outlined),
              children: [
                SideMenuItem(
                  builder: (context, displayMode) {
                    return BlocBuilder<UpdatePopularQuestionsCubit,
                        UpdatePopularQuestionsState>(
                      builder: (context, state) {
                        print(
                            "Main: _createSideMenu() : Most popular questions : BlocBuilder<UpdatePopularQuestionsCubit,UpdatePopularQuestionsState> : state.status = ${state.status}");
                        print(
                            "Main: _createSideMenu() : Most popular questions : BlocBuilder<UpdatePopularQuestionsCubit,UpdatePopularQuestionsState> : state.mostPopularQuestionsList = ${state.mostPopularQuestionsList}");

                        //_addData(state.question!, true);
                        List<TreeNode<String>> nodesMostPopularQuestions =
                            CreateNodesMostPopularQuestion(
                                state.mostPopularQuestionsList!);

                        return ExpandableTree(
                          nodes: nodesMostPopularQuestions,
                          nodeBuilder: _nodeBuilder3,
                          onSelect: (node) => _nodeSelected1(context, node),
                        );
                      },
                    );
                  },
                  onTap: (index, _) {
                    //sideMenu.changePage(index);
                  },
                )
              ],
            ),
            SideMenuItem(
              title: 'Import',
              onTap: (index, _) async {
                var questionList = await importQuestions();

                if (questionList.length == 0) {
                  print(
                      "Main: _createSideMenu() : SideMenuItem : Import : onTap() : questionList is empty");
                  return;
                }

                //sort the list of list based on the name of the database :
                //grouping, scenario, question
                //Remove the header
                questionList.removeAt(0);
                questionList.sort((a, b) => a.first.compareTo(b.first));

                //Save questions into
                SaveImportedQuestionsToFirestore(questionList);

                for (var entry in questionList)
                  print(
                      "Main: _createSideMenu() : SideMenuItem : Import : onTap() : sorted questionList = ${entry[0]}, ${entry[2]}");

                setState(() {
                  importedQuestionTreeNodeList =
                      createQuestionList(questionList);
                  //print("Main: _createSideMenu() : SideMenuItem : Import : setState() : importedQuestionTreeNodeList = ${importedQuestionTreeNodeList}");
                });

                const snackBar = SnackBar(
                  content: Text('Importing questions.'),
                  duration: Duration(seconds: 3),
                );
                ScaffoldMessenger.of(context).showSnackBar(snackBar);
              },
              icon: const Icon(Icons.file_upload_outlined),
            ),
            /* //Commented out because the export of the answers (images and tables) to a pdf is not implemented yet
            SideMenuItem(
              title: 'Export',
              onTap: (index, _) {
                _createPDF();

                const snackBar = SnackBar(
                  content: Text('Exporting data to a pdf file.'),
                  duration: Duration(seconds: 5),
                );
                ScaffoldMessenger.of(context).showSnackBar(snackBar);
              },
              icon: const Icon(Icons.import_export_outlined),
            ),*/
            /*SideMenuItem(
              // do not delete
              title: 'Clear Firestore history',
              onTap: (index, _) async {
                int count = 0;
                //get all the documents corresponding to the user id
                try {
                  var querySnapshot = await db
                      .collection("session_logs")
                      .where("user_id", isEqualTo: TextToDocParameter.userID)
                      .get();

                  print(
                      "Main: _createSideMenu() : Clear Firestore history : querySnapshot.docs.length = ${querySnapshot.docs.length}");
                  print(
                      "Main: _createSideMenu() : Clear Firestore history : querySnapshot = ${querySnapshot}");

                  //delete all these documents
                  //await db.collection("session_logs").doc('FLoOKBwvVJ8mXkzu06He').delete();

                  for (var docSnapshot in querySnapshot.docs) {
                    print(
                        'Main: _createSideMenu() : Clear Firestore history : ${docSnapshot.id} => ${docSnapshot.data()}');
                    print(
                        'Main: _createSideMenu() : Clear Firestore history : docSnapshot.reference ${docSnapshot.reference}');
                    db
                        .collection("session_logs")
                        .doc('${docSnapshot.id}')
                        .delete();
                    count++;
                  }
                } catch (e) {
                  print(
                      'Main: _createSideMenu() : Clear Firestore history : EXCEPTION : $e');
                }
                var snackBar = SnackBar(
                  content: Text('Deleted $count questions from Firestore'),
                  duration: Duration(seconds: 3),
                );
                ScaffoldMessenger.of(context).showSnackBar(snackBar);
              },
              icon: const Icon(Icons.auto_delete_outlined),
            ),*/
            SideMenuItem(
              title: 'Settings',
              onTap: (index, _) async {
                await Navigator.pushNamed(context, '/settings',
                    arguments: {"dummy": ""});
                print(
                    "Main : createSideMenu() : TextToDocParameter.expert_mode = ${TextToDocParameter.expert_mode}");
                setState(() {
                  //useExpertMode = ts.Settings.isExpert;
                  //useExpertMode = TextToDocParameter.expert_mode;
                  TextToDocParameter.expert_mode;
                });

                //GalleryScreen
              },
              icon: const Icon(Icons.settings),
            ),
          ],
        );
      },