19 lines
514 B
Dart
19 lines
514 B
Dart
import 'package:flutter/widgets.dart';
|
|
|
|
class ControllerScope<T extends ChangeNotifier> extends InheritedNotifier<T> {
|
|
const ControllerScope({
|
|
super.key,
|
|
required T controller,
|
|
required super.child,
|
|
}) : super(notifier: controller);
|
|
|
|
static T of<T extends ChangeNotifier>(BuildContext context) {
|
|
final scope = context
|
|
.dependOnInheritedWidgetOfExactType<ControllerScope<T>>();
|
|
|
|
assert(scope != null, 'No ControllerScope<$T> found in context');
|
|
|
|
return scope!.notifier!;
|
|
}
|
|
}
|