mirror of
https://github.com/kuhyx/todo-app.git
synced 2026-11-10 19:27:01 +01:00
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
30 lines
1.0 KiB
Dart
30 lines
1.0 KiB
Dart
import 'package:flutter/widgets.dart';
|
|
|
|
import 'package:todo/attachments/image_store_api.dart';
|
|
|
|
/// Makes the app's one [ImageStore] reachable from any widget below it,
|
|
/// without threading it through every screen constructor.
|
|
///
|
|
/// Screens built without a scope (most widget tests) get a shared
|
|
/// [NoImageStore], so they render and simply cannot attach.
|
|
class ImageStoreScope extends InheritedNotifier<ImageStore> {
|
|
/// Provides [store] to [child].
|
|
const ImageStoreScope({
|
|
required ImageStore store,
|
|
required super.child,
|
|
super.key,
|
|
}) : super(notifier: store);
|
|
|
|
static final ImageStore _none = NoImageStore();
|
|
|
|
/// The nearest store, subscribing [context] to its changes.
|
|
static ImageStore of(BuildContext context) =>
|
|
context.dependOnInheritedWidgetOfExactType<ImageStoreScope>()?.notifier ??
|
|
_none;
|
|
|
|
/// The nearest store, without subscribing (for callbacks).
|
|
static ImageStore read(BuildContext context) =>
|
|
context.getInheritedWidgetOfExactType<ImageStoreScope>()?.notifier ??
|
|
_none;
|
|
}
|