readCurrentStatus function

dynamic readCurrentStatus(
  1. ChangeNotifierProvider<ChangeNotifier?> provider
)

Reads a provider of type ChangeNotifierProvider from the current context tied to the global snackBarGlobalKey.

Logs an error and returns null if the context is not yet available.

Make sure the snackBarGlobalKey is attached to your MaterialApp or ScaffoldMessenger to have a valid context.

Example:

final status = readCurrentStatus(MyStatusProvider);
  • provider: The provider type to read from the context.

Returns the provider instance or null if context is unavailable.

Implementation

dynamic readCurrentStatus(ChangeNotifierProvider provider) {
  if (snackBarGlobalKey.currentContext == null) {
    logFile(
      message: 'add snack bar key to material app',
      name: "read current status",
    );
    return null;
  }
  return snackBarGlobalKey.currentContext!.read(provider);
}