build method

  1. @override
Widget build(
  1. BuildContext context
)
override

Describes the part of the user interface represented by this widget.

The framework calls this method when this widget is inserted into the tree in a given BuildContext and when the dependencies of this widget change (e.g., an InheritedWidget referenced by this widget changes). This method can potentially be called in every frame and should not have any side effects beyond building a widget.

The framework replaces the subtree below this widget with the widget returned by this method, either by updating the existing subtree or by removing the subtree and inflating a new subtree, depending on whether the widget returned by this method can update the root of the existing subtree, as determined by calling Widget.canUpdate.

Typically implementations return a newly created constellation of widgets that are configured with information from this widget's constructor and from the given BuildContext.

The given BuildContext contains information about the location in the tree at which this widget is being built. For example, the context provides the set of inherited widgets for this location in the tree. A given widget might be built with multiple different BuildContext arguments over time if the widget is moved around the tree or if the widget is inserted into the tree in multiple places at once.

The implementation of this method must only depend on:

If a widget's build method is to depend on anything else, use a StatefulWidget instead.

See also:

  • StatelessWidget, which contains the discussion on performance considerations.

Implementation

@override
Widget build(BuildContext context) {
  List<Widget> telemetryData = <Widget>[];
  int lastYear = -1;
  int lastMonth = -1;
  late bool makeNewMonthDivision;
  for (double i = 0; i <= getLastEntryIndex(); i++) {
    EphemeralTelemetry iTele = getEntry(i);
    DateTime iTeleTimeStamp =
        DateTime.fromMillisecondsSinceEpoch(iTele.entryTimeEpochMS);
    if (lastYear == -1 || lastMonth == -1) {
      lastYear = iTeleTimeStamp.year;
      lastMonth = iTeleTimeStamp.month;
      makeNewMonthDivision = true;
    } else {
      if (lastMonth != iTeleTimeStamp.month) {
        lastMonth = iTeleTimeStamp.month;
        makeNewMonthDivision = true;
      } else {
        makeNewMonthDivision = false;
      }
    }
    telemetryData.add(
      Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          if (makeNewMonthDivision)
            Text.rich(TextSpan(children: [
              TextSpan(
                  text: monthNumToName(lastMonth),
                  style: TextStyle(
                      color: monthColor(lastMonth),
                      fontSize: 22,
                      fontWeight: FontWeight.w700)),
              TextSpan(
                  text: " $lastYear",
                  style: const TextStyle(
                      color: Colors.black,
                      fontSize: 18,
                      fontWeight: FontWeight.w500))
            ])),
          if (makeNewMonthDivision) const SizedBox(height: 10),
          _makeBorderComponent(
            child: SizedBox(
              width: double.infinity,
              child: Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    Text.rich(TextSpan(children: [
                      TextSpan(
                          text:
                              "Entry: #${iTele.entryIndex.toInt() + 1}\n",
                          style: const TextStyle(
                              fontWeight: FontWeight.w700,
                              fontSize: 16)),
                      const TextSpan(
                          text: "Mood Rating:\n",
                          style: TextStyle(
                              fontWeight: FontWeight.w700)),
                      TextSpan(
                          text:
                              "${iTele.moodScale == -1 ? "??" : iTele.moodScale} / 10\n",
                          style: const TextStyle(
                              fontWeight: FontWeight.w500)),
                      const TextSpan(
                          text: "Hours of sleep:\n",
                          style: TextStyle(
                              fontWeight: FontWeight.w700)),
                      TextSpan(
                          text:
                              "${iTele.hoursOfSleep == -1 ? "??" : actionableSliderHoursContext(1, 12, iTele.hoursOfSleep.toDouble())}\n",
                          style: const TextStyle(
                              fontWeight: FontWeight.w500)),
                      const TextSpan(
                          text: "Sleep quality rating:\n",
                          style: TextStyle(
                              fontWeight: FontWeight.w700)),
                      TextSpan(
                          text:
                              "${iTele.sleepRating == -1 ? "??" : iTele.sleepRating} / 10\n",
                          style: const TextStyle(
                              fontWeight: FontWeight.w500)),
                      const TextSpan(
                          text: "Hours spent with family:\n",
                          style: TextStyle(
                              fontWeight: FontWeight.w700)),
                      TextSpan(
                          text:
                              "${iTele.hoursSpentWithFamily == -1 ? "??" : actionableSliderHoursContext(1, 12, iTele.hoursSpentWithFamily.toDouble())}\n",
                          style: const TextStyle(
                              fontWeight: FontWeight.w500)),
                      const TextSpan(
                          text: "Hours of exercise:\n",
                          style: TextStyle(
                              fontWeight: FontWeight.w700)),
                      TextSpan(
                          text:
                              "${iTele.hoursExercising == -1 ? "??" : actionableSliderHoursContext(1, 8, iTele.hoursExercising.toDouble())}\n",
                          style: const TextStyle(
                              fontWeight: FontWeight.w500)),
                      const TextSpan(
                          text: "Hours on screen:\n",
                          style: TextStyle(
                              fontWeight: FontWeight.w700)),
                      TextSpan(
                          text:
                              "${iTele.hoursOnScreen == -1 ? "??" : actionableSliderHoursContext(1, 12, iTele.hoursOnScreen.toDouble())}\n",
                          style: const TextStyle(
                              fontWeight: FontWeight.w500)),
                      const TextSpan(
                          text: "How stressed were you:\n",
                          style: TextStyle(
                              fontWeight: FontWeight.w700)),
                      TextSpan(
                          text:
                              "${iTele.howStressed == -1 ? "??" : iTele.howStressed}/10\n",
                          style: const TextStyle(
                              fontWeight: FontWeight.w500)),
                      const TextSpan(
                          text: "Emotion tags:\n",
                          style: TextStyle(
                              fontWeight: FontWeight.w700)),
                      TextSpan(
                          text: "${iTele.emotionTags}\n",
                          style: const TextStyle(
                              fontWeight: FontWeight.w500)),
                      const TextSpan(
                          text: "Stressors of today:\n",
                          style: TextStyle(
                              fontWeight: FontWeight.w700)),
                      TextSpan(
                          text: "${iTele.stressorsOfToday}\n",
                          style: const TextStyle(
                              fontWeight: FontWeight.w500)),
                      const TextSpan(
                          text: "Brief note:\n",
                          style: TextStyle(
                              fontWeight: FontWeight.w700)),
                      TextSpan(
                          text: "${iTele.briefNote}\n",
                          style: const TextStyle(
                              fontWeight: FontWeight.w500)),
                      const TextSpan(
                          text: "Entry time:\n",
                          style: TextStyle(
                              fontWeight: FontWeight.w700)),
                      TextSpan(
                          text: fmtDateTime(
                              DateTime.fromMillisecondsSinceEpoch(
                                  iTele.entryTimeEpochMS)),
                          style: const TextStyle(
                              fontWeight: FontWeight.w500)),
                    ]))
                  ]),
            ),
          ),
          const SizedBox(height: 10)
        ],
      ),
    );
  }
  return SingleChildScrollView(
    child: Padding(
      padding: const EdgeInsets.all(10.0),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.center,
        children: [
          _makeBorderComponent(
            child: Padding(
              padding: const EdgeInsets.all(10.0),
              child: Center(
                child: Flex(
                  direction: Axis.horizontal,
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    Flexible(
                      flex: 0,
                      child: RandomAvatar(getUserAvatarSVG(),
                          height: 134, width: 134),
                    ),
                    const SizedBox(width: 40),
                    Flexible(
                        flex: 1,
                        fit: FlexFit.tight,
                        child: Column(
                            crossAxisAlignment:
                                CrossAxisAlignment.start,
                            children: [
                              Text(getUserName(),
                                  style: const TextStyle(
                                      fontWeight: FontWeight.w800,
                                      fontSize: 28)),
                              const SizedBox(height: 6),
                              Text.rich(
                                  TextSpan(children: [
                                    const TextSpan(
                                        text: "Gender: ",
                                        style: TextStyle(
                                            fontWeight:
                                                FontWeight.w800)),
                                    TextSpan(
                                      text: (getUserSex() ==
                                              "female"
                                          ? "♀️ Female"
                                          : getUserSex() == "male"
                                              ? "♂️ Male"
                                              : "❓ Not specified"),
                                    )
                                  ]),
                                  style: const TextStyle(
                                      fontSize: 18,
                                      fontWeight:
                                          FontWeight.normal)),
                              const SizedBox(height: 6),
                              Text.rich(
                                  TextSpan(children: [
                                    const TextSpan(
                                        text: "Age Range: ",
                                        style: TextStyle(
                                            fontWeight:
                                                FontWeight.w800)),
                                    TextSpan(
                                      text:
                                          "${getUserAgeGroup().toInt()}-${getUserAgeGroup().toInt() + 10}",
                                    )
                                  ]),
                                  style: const TextStyle(
                                      fontSize: 18,
                                      fontWeight:
                                          FontWeight.normal))
                            ]))
                  ],
                ),
              ),
            ),
          ),
          const SizedBox(height: 10),
          _makeBorderComponent(
              child: SizedBox(
                  width: double.infinity,
                  child: Text.rich(TextSpan(children: [
                    const TextSpan(
                        text: "Statistics\n",
                        style: TextStyle(
                            fontSize: 24,
                            fontWeight: FontWeight.w800)),
                    const TextSpan(
                        text: "Last Entry Time: ",
                        style: TextStyle(
                            fontSize: 18,
                            fontWeight: FontWeight.w600)),
                    TextSpan(
                        text: fmtDateTime(
                            DateTime.fromMillisecondsSinceEpoch(
                                getLastEntryTime())),
                        style: const TextStyle(fontSize: 18)),
                    const TextSpan(
                        text: "\nTotal entries: ",
                        style: TextStyle(
                            fontSize: 18,
                            fontWeight: FontWeight.w600)),
                    TextSpan(
                        text:
                            getLastEntryIndex().toInt().toString(),
                        style: const TextStyle(fontSize: 18))
                  ])))),
          const SizedBox(height: 10),
          if (getLastEntryIndex() == 0)
            const Text.rich(TextSpan(children: [
              TextSpan(
                  text: "No entries found!",
                  style: TextStyle(
                      color: Color.fromARGB(150, 180, 180, 180),
                      fontWeight: FontWeight.w800,
                      fontSize: 24))
            ]))
          else
            ...telemetryData
        ],
      ),
    ),
  );
}