Widget build()

in frontend/frontend-flutter/lib/main.dart [1017:1360]


  Widget build(BuildContext context) {
    debugPaintSizeEnabled = false;
    screenSize = MediaQuery.of(context).size;
    bool _isEarningCalls1Hovered = false;
    bool _isEarningCalls2Hovered = false;
    bool _isBookingAnalysisHovered = false;
    bool _isFunelAnalysisHovered = false;

    print("Main : build() : START");
    print("Main : build() : TuserGroupingList = ${userGroupingList}");
    print(
        "Main : build() : TextToDocParameter.currentUserGrouping = ${TextToDocParameter.currentUserGrouping}");

    return Scaffold(
      appBar: AppBar(
        title: Image.asset('assets/images/cymbal_logo.png', scale: 2),
        centerTitle: false,
        actions: [
          Padding(
            padding: const EdgeInsets.only(right: 100),
            child: Container(
              width: 320,
              child: FutureBuilder(
                future: _getUserGrouping(),
                builder: (context, snapshot) {
                  if (snapshot.connectionState == ConnectionState.waiting) {
                    return Padding(
                      padding: const EdgeInsets.only(right: 135.0, left: 135.0),
                      child: Container(
                          width: 50,
                          height: 50,
                          child: /*Text('TEST')*/ CircularProgressIndicator()),
                    ); // Loading indicator
                  } else if (snapshot.hasError) {
                    return Text('-Error-: ${snapshot.error}');
                    // Error handling
                  } else {
                    if (snapshot.data!.isNotEmpty) {
                      TextToDocParameter.currentUserGrouping =
                          snapshot.data![0];
                      TextToDocParameter.userGroupingList = snapshot.data!;
                      selectedValueNotifier.value = snapshot.data!.first;
                      print(
                          "main: build() : TextToDocParameter.currentUserGrouping = ${TextToDocParameter.currentUserGrouping}");
                      print("main: build() : selectedValue = ${selectedValue}");
                    }
                    return ValueListenableBuilder<String?>(
                        valueListenable: selectedValueNotifier,
                        builder: (context, value, child) {
                          return Container(
                            width: 300,
                            child: Row(
                              children: [
                                Text("User Grouping:   ",
                                    style: TextStyle(
                                        fontSize: 13.0, color: Colors.black)),
                                Expanded(
                                  child: DropdownButton<String>(
                                    value: value,
                                    //icon: const Icon(Icons.arrow_downward),
                                    elevation: 16,
                                    style: const TextStyle(
                                        fontSize: 13.0,
                                        color: Colors.deepPurple),
                                    onChanged: (String? value) {
                                      selectedValueNotifier.value = value!;
                                      TextToDocParameter.currentUserGrouping =
                                          value!;
                                      print(
                                          'Main: build() : DropdownButton : onChanged() : TextToDocParameter.currentUserGrouping => ${TextToDocParameter.currentUserGrouping}');
                                    },
                                    items: snapshot.data!
                                        .map<DropdownMenuItem<String>>(
                                            (String value) {
                                      return DropdownMenuItem<String>(
                                        value: value,
                                        child: Text(value),
                                      );
                                    }).toList(),
                                  ),
                                ),
                              ],
                            ),
                          );
                        });
                  }
                },
              ),
            ),
          ),
        ],
        leading: Text(""),
      ),
      body: Row(
        mainAxisSize: MainAxisSize.max,
        mainAxisAlignment: MainAxisAlignment.start,
        children: [
          _createSideMenu()!,
          const VerticalDivider(
            width: 0,
          ),
          Expanded(
            child: Stack(
              children: [
                Container(
                  padding: EdgeInsets.only(left: 100, right: 100),
                  child: Column(
                    mainAxisAlignment: MainAxisAlignment.start,
                    //mainAxisSize: MainAxisSize.min,
                    children: <Widget>[
                      BlocBuilder<DisplayStepperCubit, DisplayStepperState>(
                        builder: (context, state) {
                          print(
                              "Main: build() : BlocBuilder<DisplayStepperCubit, DisplayStepperState> : START");
                          if (state.status ==
                              displayStepperStatus.display_stepper) {
                            print(
                                "Main: build() : BlocBuilder<DisplayStepperCubit, DisplayStepperState> : state =${state.status}");
                            return Flexible(
                                fit: FlexFit.loose,
                                child: Padding(
                                  padding: const EdgeInsets.only(bottom: 5),
                                  child: _buildStepper(),
                                ),
                                flex: 2);
                          } else if (state.status ==
                              displayStepperStatus.remove_stepper) {
                            print(
                                "Main: build() : BlocBuilder<DisplayStepperCubit, DisplayStepperState> : state =${state.status}");
                            return Text("");
                          } else {
                            print(
                                "Main: build() : BlocBuilder<DisplayStepperCubit, DisplayStepperState> : ERROR : state =$state");
                            return Text("Unable to load user_grouping");
                          }
                        },
                      ),
                      bot!,
                      BlocBuilder<NewSuggestionCubit, NewSuggestionState>(
                        builder: (context, state) {
                          if (state.status == NewSuggestionStateStatus.loaded) {
                            print(
                                "Main: build() : BlocBuilder<NewSuggestionCubit, NewSuggestionState> : START : state =$state");
                            return makeSuggestions(
                                state.suggestionList!, state.scenarioNumber!);
                          } else {
                            return makeSuggestions(["x:", "x:", "x:"], 0);
                          }
                        },
                      ),
                      //const Spacer(flex: 1,),
                    ],
                  ),
                ),
                BlocBuilder<FirstQuestionCubit, FirstQuestionState>(
                  builder: (context, state) {
                    print(
                        "Main : build() : BlocBuilder<FirstQuestionCubit, FirstQuestionState> : START");
                    if (state.status ==
                        firstQuestionStatus.display_welcome_message) {
                      print(
                          "Main : build() : BlocBuilder<FirstQuestionCubit, FirstQuestionState> : state.status == firstQuestionStatus.display_welcome_message");
                      return Positioned(
                        //top: 0,
                        //left: 200, //200,
                        child: Column(
                            mainAxisAlignment: MainAxisAlignment.start,
                          children: [
                            Container(height: 100),
                            Image.asset(
                              //UNCOMMENT
                              "assets/images/gemini.png"!,
                              height: 90,
                              width: 90,
                              fit: BoxFit.cover,
                            ),
                            Padding(
                              padding: const EdgeInsets.only(bottom: 50),
                              child: Column(
                                mainAxisAlignment: MainAxisAlignment.center,
                                crossAxisAlignment: CrossAxisAlignment.center,
                                children: [
                                  Row(
                                    mainAxisAlignment: MainAxisAlignment.center,
                                    children: [
                                      Text(
                                          "Hello ${TextToDocParameter.firstName} ! ",
                                          style: TextStyle(
                                              fontSize: 40.0,
                                              fontWeight: FontWeight.bold)),
                                      GradientText(
                                        'How can I help you today ?',
                                        style: TextStyle(
                                            fontSize: 40.0,
                                            fontWeight: FontWeight.bold),
                                        colors: [
                                          Colors.blue,
                                          Colors.red,
                                          Colors.teal,
                                        ],
                                      ),
                                    ],
                                  ),
                                  const Row(
                                      mainAxisAlignment:
                                          MainAxisAlignment.center,
                                      children: [
                                        Text(
                                            'Learn more by selecting a card below\n',
                                            style: TextStyle(
                                                fontSize: 30.0,
                                                fontWeight: FontWeight.normal,
                                                color: Colors.black))
                                      ])
                                ],
                              ),
                            ),
                            FutureBuilder(
                                future: _getQuestions(),
                                builder: (context, snapshot) {
                                  if (snapshot.connectionState ==
                                      ConnectionState.waiting) {
                                    return CircularProgressIndicator(); // Loading indicator
                                  } else if (snapshot.hasError) {
                                    return Text('*Error*: ${snapshot.error}');
                                    // Error handling
                                  } else {
                                    return Container(
                                      width: screenSize!.width / 1.5,
                                      child: Column(
                                        children: [
                                          Row(
                                            crossAxisAlignment:
                                                CrossAxisAlignment.center,
                                            mainAxisAlignment:
                                                MainAxisAlignment.spaceEvenly,
                                            children: [
                                              if (snapshot.data!.length >= 1)
                                                createCardsSuggestion(
                                                    title: snapshot.data![0]
                                                            ['scenario_name'] ??
                                                        "Error - No title",
                                                    text: snapshot.data![0]
                                                            ['user_question'] ??
                                                        "Error - No question",
                                                    scenarioNumber: 2,
                                                    isHovered:
                                                        _isEarningCalls1Hovered,
                                                    imagePath:
                                                        "assets/images/last_questions.png",
                                                    timeStamp: snapshot.data![0]
                                                            ['timestamp'] ??
                                                        "Error - No timestamp",
                                                userGrouping: snapshot.data![0]
                                                ['user_grouping']),
                                              if (snapshot.data!.length >= 2)
                                                createCardsSuggestion(
                                                    title: snapshot.data![1]
                                                            ['scenario_name'] ??
                                                        "Error - No title",
                                                    text: snapshot.data![1]
                                                            ['user_question'] ??
                                                        "Error - No question",
                                                    scenarioNumber: 2,
                                                    isHovered:
                                                        _isEarningCalls1Hovered,
                                                    imagePath:
                                                        "assets/images/last_questions.png",
                                                    timeStamp: snapshot.data![1]
                                                            ['timestamp'] ??
                                                        "Error - No timestamp",
                                                    userGrouping: snapshot.data![0]
                                                    ['user_grouping']),
                                            ],
                                          ),
                                          Row(
                                              crossAxisAlignment:
                                                  CrossAxisAlignment.center,
                                              mainAxisAlignment:
                                                  MainAxisAlignment.spaceEvenly,
                                              children: [
                                                if (snapshot.data!.length >= 3)
                                                  createCardsSuggestion(
                                                      title: snapshot.data![2][
                                                              'scenario_name'] ??
                                                          "Error - No title",
                                                      text: snapshot.data![2][
                                                              'user_question'] ??
                                                          "Error - No question",
                                                      scenarioNumber: 2,
                                                      isHovered:
                                                          _isEarningCalls1Hovered,
                                                      imagePath:
                                                          "assets/images/last_questions.png",
                                                      timeStamp: snapshot
                                                                  .data![2]
                                                              ['timestamp'] ??
                                                          "Error - No timestamp",
                                                      userGrouping: snapshot.data![0]
                                                      ['user_grouping']),
                                                if (snapshot.data!.length >= 4)
                                                  createCardsSuggestion(
                                                      title: snapshot.data![3][
                                                              'scenario_name'] ??
                                                          "Error - No title",
                                                      text: snapshot.data![3][
                                                              'user_question'] ??
                                                          "Error - No question",
                                                      scenarioNumber: 2,
                                                      isHovered:
                                                          _isEarningCalls1Hovered,
                                                      imagePath:
                                                          "assets/images/last_questions.png",
                                                      timeStamp: snapshot
                                                                  .data![3]
                                                              ['timestamp'] ??
                                                          "Error - No timestamp",
                                                      userGrouping: snapshot.data![0]
                                                      ['user_grouping']),
                                              ])
                                        ],
                                      ),
                                    );
                                  }
                                }), //UNCOMMENT
                          ],
                        ), //UNCOMMENT
                      );
                    } else {
                      print(
                          "Main : build() : BlocBuilder<FirstQuestionCubit, FirstQuestionState> : state.status != firstQuestionStatus.display_welcome_message");
                      isFirstQuestionStatus = false;
                      return Text("");
                    }
                  },
                ),
              ],
            ),
          ),
        ],
      ),
      // This trailing comma makes auto-formatting nicer for build methods.
    );
  }