added controller scope and extension for context
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
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!;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user