change<T> static method

void change<T>(
  1. BuildContext context,
  2. Symbol key,
  3. T data
)

Change the data of the model with the given key. Throws an assertion error if the model is read-only.

  • T The type of the data.
  • context The build context.
  • key The data key.
  • data The new data.

Implementation

static void change<T>(BuildContext context, Symbol key, T data) {
  final widget = context.findAncestorWidgetOfExactType<_InheritedModel>();
  assert(widget != null, 'No Model<$T>($key) found in context');
  for (final model in widget!.data) {
    if (model.dataKey == key) {
      model.value = data;
      return;
    }
  }
  assert(false, 'No Model<$T>($key) found in context');
}