build method

  1. @override
Widget build(
  1. BuildContext context,
  2. WidgetRef ref
)
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, WidgetRef ref) {
  // 20240809 gjw Delay the rStart() until we begin to load the dataset. This
  // may solve the Windows zip install issue whereby main.R is not being
  // loaded on startup yet the remainder of the R code does get loaded. Also,
  // we load it here rather than in rLoadDataset because at this time the user
  // is paused looking at the popup to load the dataset and we have time to
  // squeeze in and async run main.R before we get the `glimpse` missing
  // error.
  //
  // 20240809 gjw Revert for now until find the proper solution.
  //
  // 20240809 gjw Moved main.R into dataset_prep.R see if that works.

  // rStart(context, ref);

  // A state to hold the selected demo dataset.

  return AlertDialog(
    content: Column(
      mainAxisSize: MainAxisSize.min,
      children: [
        const Row(
          children: [
            Icon(
              Icons.data_usage,
              size: 24,
              color: Colors.blue,
            ),
            popupIconGap,
            Text(
              'Choose the Dataset Source:',
              style: TextStyle(
                fontSize: 24,
                fontWeight: FontWeight.bold,
              ),
            ),
          ],
        ),

        popupTitleGap,

        Row(
          mainAxisAlignment: MainAxisAlignment.spaceAround,
          children: [
            // FILENAME

            ElevatedButton(
              onPressed: () async {
                String path = await datasetSelectFile();
                if (path.isNotEmpty) {
                  ref.read(pathProvider.notifier).state = path;
                  if (context.mounted) await rLoadDataset(context, ref);
                  setStatus(ref, statusChooseVariableRoles);
                  datasetLoadedUpdate(ref);

                  // Save the dataset name in lowercase to the datasetNameProvider from the path.

                  ref.read(datasetNameProvider.notifier).state = path
                      .split(RegExp(r'[/\\]'))
                      .last
                      .split('.')
                      .first
                      .toLowerCase();
                }

                // Avoid the "Do not use BuildContexts across async gaps."
                // warning.

                if (!context.mounted) return;
                Navigator.pop(context, 'Filename');

                // Access the PageController via Riverpod and move to the second page.

                ref.read(pageControllerProvider).animateToPage(
                      // Index of the second page.

                      1,
                      duration: const Duration(milliseconds: 300),
                      curve: Curves.easeInOut,
                    );
              },
              child: MarkdownTooltip(
                message: '''

                **Filename for Dataset** Tap here to popup a window to browse
                to a **csv** or **txt** file that you would like to load
                into Rattle.

                ''',
                child: Text('Filename'),
              ),
            ),

            buttonGap,

            ElevatedButton(
              onPressed: () async {
                // scrape the packages
                String stdout = ref.read(stdoutProvider);
                String content =
                    rExtract(stdout, '> package_datasets_cleaned');
                Map<String, List<String>> map = parsePackage(content);
                String path = await datasetSelectPackage(context, map, ref);
                if (path.isNotEmpty) {
                  // ref.read(pathProvider.notifier).state = path;
                  if (context.mounted) await rLoadDataset(context, ref);
                  setStatus(ref, statusChooseVariableRoles);
                  datasetLoadedUpdate(ref);
                }
                if (!context.mounted) return;
                Navigator.pop(context, 'Package');

                // Access the PageController via Riverpod and move to the second page.

                ref.read(pageControllerProvider).animateToPage(
                      // Index of the second page.

                      1,
                      duration: const Duration(milliseconds: 300),
                      curve: Curves.easeInOut,
                    );
              },
              child: const MarkdownTooltip(
                message: '''

                **Under Development** Eventually you will be able to tap here
                to popup a window to browse the list of available R datasets
                to choose one of them to load into Rattle.

                ''',
                child: Text('Package'),
              ),
            ),
          ],
        ),

        configRowGap,

        MarkdownTooltip(
          message: '''

                **Demo Datasets** Rattle provides a number of small datasets
                so you can very quickly explore the Rattle functionality.  The
                *buttons* below will load one of the demo datasets. Hover over
                any of them to see a description of that dataset.

                ''',
          child: MarkdownBody(
            data: '**Demo Datasets** '
                'Tap to load one of the available demonstration datasets:',
          ),
        ),

        configRowGap,

        //  Buttons for selecting the demo dataset.

        Consumer(
          builder: (context, ref, child) {
            return Row(
              mainAxisAlignment: MainAxisAlignment.spaceAround,
              children: [
                buttonGap,
                MarkdownTooltip(
                  message: '''

                    The **Weather** dataset is a recent dataset of one year of
                    daily observations from a weather station in Canberra,
                    Australia. It is useful to demonstrate all steps of the
                    Data Science process, to Explore, Transform, model, and
                    Evaluate. The target variable for predictive modelling is
                    the variable *Rain Tomorrow*. The amount of rain tomorrow
                    is recored as the variable *Risk MM*. Most of the
                    remaining variables could be used as inputs for building a
                    model to predict the likelihood of it raining tomorrow -
                    *should you take an umbrella with you tomorrow?*

                    The data has been collected from the Australian Bureau of
                    Meterology since 2007, covering over 50 weather stations
                    across Australia. The larger dataset is available from
                    Togaware as
                    [weatherAus.csv](https://access.togaware.com/weatherAUS.csv).

                    ''',
                  child: ElevatedButton(
                    onPressed: () async {
                      await loadDemoDataset(
                        ref,
                        context,
                        'data/weather.csv',
                        'Weather',
                      );
                    },
                    child: const Text('Weather'),
                  ),
                ),
                buttonGap,
                MarkdownTooltip(
                  message: '''

                    The **Audit** dataset is a demonstrator for predicting
                    whether the govenrment revenue authority might need to
                    audit a taxpayer. The dataset of 2,000 fictional tax
                    payers who have previously been audited includes their
                    demographics and financial variables. The target variable
                    *Adjusted* records whether their financial data had to be
                    adjusted because their originally submitted data had
                    errors affting their tax obligation. The variable
                    *Adjustment* is the dollar amount of the adjustment - the
                    adjustment to their tax liability.

                    The resulting predictive model could be used to predict
                    the likelihood of an audit of a tax payer resulting in an
                    adjustment. Auditors can thus not waste their time on
                    non-productive audits.

                    ''',
                  child: ElevatedButton(
                    onPressed: () async {
                      await loadDemoDataset(
                        ref,
                        context,
                        'data/audit.csv',
                        'Audit',
                      );
                    },
                    child: const Text('Audit'),
                  ),
                ),
                buttonGap,
                MarkdownTooltip(
                  message: '''

                    The **Protein** dataset comes from the [Tippie College of
                    Business, The University of
                    Iowa](http://www.biz.uiowa.edu/faculty/jledolter/DataMining/protein.csv). It
                    is useful for demonstrating **Cluster** analysis.

                    ''',
                  child: ElevatedButton(
                    onPressed: () async {
                      await loadDemoDataset(
                        ref,
                        context,
                        'data/protein.csv',
                        'Protein',
                      );
                    },
                    child: const Text('Protein'),
                  ),
                ),
                buttonGap,
                MarkdownTooltip(
                  message: '''

                    The **Movies** dataset is useful for demonstrating basket
                    analysis under the **Associations** feature of the
                    **Model** tab. The dataset has just two
                    columns/variables. Each basket is uniquley identified and
                    each basket can contain 1 or more items. Running the
                    association rules analysis with *Baskets* enabled will
                    build assoitation rules found in the dataset.

                    ''',
                  child: ElevatedButton(
                    onPressed: () async {
                      await loadDemoDataset(
                        ref,
                        context,
                        'data/movies.csv',
                        'Movies',
                      );
                    },
                    child: const Text('Movies'),
                  ),
                ),
                buttonGap,
                MarkdownTooltip(
                  message: '''

                    The **Sherlock** data file is a text file for
                    demonstrating the **Word Cloud** feature of the **Model**
                    tab. It is a snippet from a Sherlock Holmes novel.

                    ''',
                  child: ElevatedButton(
                    onPressed: () async {
                      await loadDemoDataset(
                        ref,
                        context,
                        'data/sherlock.txt',
                        'Sherlock',
                      );
                    },
                    child: const Text('Sherlock'),
                  ),
                ),
                buttonGap,
                MarkdownTooltip(
                  message: '''

                    The **US Census** data file is a larger **csv** file for
                    exploring a dataset. The data comes from the U.S. Census
                    Bureau, Population Division. The variables are described
                    [there](https://www2.census.gov/programs-surveys/popest/datasets/2010-2016/counties/totals/co-est2016-alldata.pdf).

                    ''',
                  child: ElevatedButton(
                    onPressed: () async {
                      await loadDemoDataset(
                        ref,
                        context,
                        'data/co-est2016-alldata.csv',
                        'US Census',
                      );
                    },
                    child: const Text('US Census'),
                  ),
                ),
              ],
            );
          },
        ),

        // SPACE between row of options and the cancel button.

        configRowGap,

        // Add a CANCEL button to do nothing but return.

        Row(
          mainAxisAlignment: MainAxisAlignment.end,
          children: [
            ElevatedButton(
              onPressed: () {
                Navigator.pop(context, 'Cancel');
              },
              child: MarkdownTooltip(
                message: '''

                **Cancel** Tap here to **not** proceed with loading a new
                  dataset.

                ''',
                child: Text('Cancel'),
              ),
            ),
          ],
        ),
      ],
    ),
  );
}