updateState method

Future<void> updateState(
  1. String type,
  2. Map<String, dynamic>? data
)

Implementation

Future<void> updateState(String type, Map<String, dynamic>? data) async {
  try {
    if (!_hasSyncData) {
      // Waiting to sync data from native platform
      await _syncSharedState;
    }

    // Update cached state
    _cachedSharedState[type] = data;
    // Notify state change to registered listeners
    _notifyListeners(type, data);

    // Notify other flutter engine to update state
    await methodChannel.invokeMethod('updateState', {
      'type': type,
      'state': data,
    });
  } on PlatformException catch (e) {
    debugPrint('Error updating shared state: ${e.message}');
  }
}