datasetSelectPackage function

Future<String> datasetSelectPackage(
  1. BuildContext context,
  2. Map<String, List<String>> packageMap,
  3. WidgetRef ref
)

Implementation

Future<String> datasetSelectPackage(
  BuildContext context,
  Map<String, List<String>> packageMap,
  WidgetRef ref,
) async {
  String path = '';
  await showDialog(
    context: context,
    builder: (context) {
      return AlertDialog(
        title: Text('Available Packages'),
        content: SizedBox(
          width: double.maxFinite,
          child: SingleChildScrollView(
            child: Column(
              mainAxisSize: MainAxisSize.min,
              children: packageMap.entries.expand((entry) {
                // Expand each package into a list of ListTile widgets
                return entry.value.map((dataset) {
                  return ListTile(
                    title: Text(
                      '${entry.key} - $dataset',
                    ),
                    onTap: () {
                      ref.read(pathProvider.notifier).state =
                          '${entry.key}::$dataset';
                      debugPrint(
                        'update path provider to ${ref.read(pathProvider)}',
                      );

                      ref.read(datasetProvider.notifier).state = '$dataset';
                      ref.read(packageProvider.notifier).state = '${entry.key}';

                      path = ref.read(pathProvider);

                      Navigator.of(context).pop();
                      debugPrint(
                        'Selected Package: ${entry.key}, Dataset: $dataset',
                      );
                    },
                  );
                }).toList();
              }).toList(),
            ),
          ),
        ),
        actions: [
          TextButton(
            onPressed: () {
              Navigator.of(context).pop();
            },
            child: Text('Close'),
          ),
        ],
      );
    },
  );

  return path;
}