canonical / workshops

Workshops
GNU General Public License v3.0
51 stars 11 forks source link

showConfigEditorDialog() uses build context across async gap #323

Closed jpnurmi closed 1 year ago

jpnurmi commented 1 year ago

Upgrading to Flutter 3.7 revealed an issue in showConfigEditorDialog():

Don't use 'BuildContext's across async gaps. Try rewriting the code to not reference the 'BuildContext'. dart(use_build_context_synchronously)

Future<void> showConfigEditorDialog(
  BuildContext context, {...}) async {
  final configSchema = await loadConfigSchema(assetName);
  // context is no longer guaranteed to be valid/mounted
  return showDialog(context: context, ...);
}

https://github.com/canonical/workshops/blob/main/lib/config_editor/config_editor_dialog.dart#L11-L29