50 lines
1.5 KiB
Dart
50 lines
1.5 KiB
Dart
import 'package:flutter/widgets.dart';
|
|
|
|
import '../config/settings.dart';
|
|
import '../export/csv_exporter.dart';
|
|
import '../layout/layout_controller.dart';
|
|
import '../session/session_controller.dart';
|
|
|
|
/// Inherited widget that exposes the app's controllers to descendants.
|
|
///
|
|
/// Plain InheritedWidget rather than Provider/Riverpod, per the design
|
|
/// decision to avoid a state-management dependency.
|
|
class AppScope extends InheritedWidget {
|
|
const AppScope({
|
|
super.key,
|
|
required this.session,
|
|
required this.layout,
|
|
required this.settings,
|
|
required this.exporter,
|
|
required super.child,
|
|
});
|
|
|
|
final SessionController session;
|
|
final LayoutController layout;
|
|
final Settings settings;
|
|
final CsvExporter exporter;
|
|
|
|
static AppScope of(BuildContext context) {
|
|
final scope = context.dependOnInheritedWidgetOfExactType<AppScope>();
|
|
assert(scope != null, 'AppScope.of() called with no AppScope ancestor');
|
|
return scope!;
|
|
}
|
|
|
|
/// Republish this scope above [child]. Used when opening dialogs, because
|
|
/// `showDialog` mounts the dialog in the root Navigator's overlay, which
|
|
/// sits above the AppScope in the widget tree.
|
|
Widget wrap(Widget child) => AppScope(
|
|
session: session,
|
|
layout: layout,
|
|
settings: settings,
|
|
exporter: exporter,
|
|
child: child,
|
|
);
|
|
|
|
@override
|
|
bool updateShouldNotify(AppScope old) =>
|
|
session != old.session ||
|
|
layout != old.layout ||
|
|
settings != old.settings ||
|
|
exporter != old.exporter;
|
|
} |