added controller scope and extension for context

This commit is contained in:
2026-06-12 12:22:46 +02:00
parent b5f6370fdf
commit 453e106cd5
2 changed files with 27 additions and 0 deletions
+18
View File
@@ -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!;
}
}