build method

  1. @override
Widget build(
  1. BuildContext context,
  2. ScienceModel model
)
override

Builds the UI according to the state in model.

Implementation

@override
Widget build(BuildContext context, ScienceModel model) => Column(children: [
    Row(children: [  // The header at the top
      const SizedBox(width: 8),
      Text("Science Analysis", style: context.textTheme.headlineMedium),
      const SizedBox(width: 12),
      if (model.isLoading) const SizedBox(height: 20, width: 20, child: CircularProgressIndicator()),
      const Spacer(),
      DropdownButton(
        value: model.sample,
        onChanged: model.updateSample,
        items: [
          for (int i = 0; i < model.numSamples; i++) DropdownMenuItem(
            value: i,
            child: Text("Sample ${i + 1}"),
          ),
        ],
      ),
      if (model.isListening) IconButton(
        icon: const Icon(Icons.upload_file),
        onPressed: model.loadFile,
        tooltip: "Load file",
      ) else IconButton(
        icon: const Icon(Icons.clear),
        onPressed: model.clear,
        tooltip: "Clear",
      ),
      ViewsSelector(index: index),
    ],),
    Expanded(child: ListView(  // The main content of the page
      padding: const EdgeInsets.symmetric(horizontal: 4),
      children: [
        if (model.errorText != null) ...[
          Text("Error analyzing the logs", textAlign: TextAlign.center, style: context.textTheme.headlineLarge),
          const SizedBox(height: 24),
          Text("Here is the error:", textAlign: TextAlign.center, style: context.textTheme.titleLarge),
          const SizedBox(height: 12),
          Text(model.errorText!, textAlign: TextAlign.center, style: context.textTheme.titleMedium),
        ] else if (!model.isLoading) ...[
          ChartsRow(
            title: "Details",
            analyses: model.analysesForSample,
            builder: (analysis) => LineChart(getDetailsData(analysis, getColor(model.sample / model.numSamples))),
          ),
          ChartsRow(
            title: "Summary",
            analyses: model.analysesForSample,
            builder: (analysis) => BarChart(getBarChartData(analysis, getColor(model.sample / model.numSamples))),
          ),
          ChartsRow(
            title: "Results",
            height: 425,
            analyses: model.analysesForSample,
            builder: ResultsBox.new,
          ),
        ],
      ],
    ),),
    ScienceCommandEditor(),
  ],);