loadDemoDataset function

Future<void> loadDemoDataset(
  1. WidgetRef ref,
  2. BuildContext context,
  3. String assetPath,
  4. String dsname,
)

Implementation

Future<void> loadDemoDataset(
  WidgetRef ref,
  BuildContext context,
  String assetPath,
  String dsname,
) async {
  // Save the dataset name in lowercase to the dsnameProvider.

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

  // Copy the asset to a temporary directory.

  String dest = await copyAssetToTempDir(asset: assetPath);

  // Update the path provider state with the dataset path.

  ref.read(pathProvider.notifier).state = dest;

  // Check if the context is still mounted before proceeding and load the dataset.

  if (context.mounted) await rLoadDataset(context, ref);

  // Update the status to indicate variable roles can now be chosen.

  setStatus(ref, statusChooseVariableRoles);

  // Close the current dialog if the context is still mounted.

  if (context.mounted) Navigator.pop(context, dsname);

  // Mark the dataset as loaded in the state management system.

  datasetLoadedUpdate(ref);

  // Navigate to the second page using the page controller.

  // 20250226 gjw For now we try not moving to the dataset page
  // just yet. On a Mac there are reports of a grey ROLES
  // page. That could be because the R code is not yet finished
  // and some kind of time out. Or the dataset load has a
  // problem. By staying on the OVERVIEW we mightreduce the
  // liklihood?

  // ref.read(pageControllerProvider).animateToPage(
  //       1,
  //       duration: const Duration(milliseconds: 300),
  //       curve: Curves.easeInOut,
  //     );
}