updateMetaData function

void updateMetaData(
  1. WidgetRef ref
)

Implementation

void updateMetaData(WidgetRef ref) {
  String stdout = ref.read(stdoutProvider);

  String content = rExtract(stdout, '> meta_data(ds)');

  // Only update the meta data if we find meta data in the CONSOLE. Otherwise we
  // get an unexpected character exception. 20241017 gjw Also need to check that
  // the content is finished being populated. On Windows I was noticing that the
  // jsonDecode was raising an Exception because the content was not a properly
  // formed JSON. It was being truncated. So for now, and this might need to be
  // revisited, lets catch the JSON FormatException, wait 1s, and try
  // again. This seems to fix the Windows problem for now! And on Linux it
  // remains snappy.

  Map<String, dynamic> jsonObject = {};

  if (content.isNotEmpty) {
    try {
      jsonObject = jsonDecode(content);
    } on FormatException {
      sleep(Duration(seconds: 1));
      stdout = ref.read(stdoutProvider);
      content = rExtract(stdout, '> meta_data(ds)');
    }

    // 20240815 gjw Iterate through each key-value pair and add to the
    // provider. Simply assigning the object to the provider raises an exception
    // about updating a provide inside a widget build.

    for (var col in jsonObject.entries) {
      ref.read(metaDataProvider.notifier).state[col.key] = col.value;
    }
  }
}