7ff012880b
Provide composable shown/current visibility for retained surfaces and migrate visibility readers away from TickerMode. This keeps ticker muting separate from painted and current-surface state.
43 lines
1.3 KiB
Dart
43 lines
1.3 KiB
Dart
import 'package:flutter/widgets.dart';
|
|
|
|
/// Describes whether a surface is painted and whether it is the surface the
|
|
/// user is currently working on.
|
|
///
|
|
/// Unlike [TickerMode], this signal describes visibility independently from
|
|
/// whether animations are allowed to run. Nested surfaces can only make their
|
|
/// descendants less visible.
|
|
class SurfaceVisibility extends InheritedWidget {
|
|
const SurfaceVisibility({
|
|
super.key,
|
|
required this.shown,
|
|
required this.current,
|
|
required super.child,
|
|
});
|
|
|
|
final bool shown;
|
|
final bool current;
|
|
|
|
static bool shownOf(BuildContext context) => _valuesOf(context).shown;
|
|
|
|
static bool currentOf(BuildContext context) => _valuesOf(context).current;
|
|
|
|
static ({bool shown, bool current}) _valuesOf(BuildContext context) {
|
|
var shown = true;
|
|
var current = true;
|
|
context.visitAncestorElements((element) {
|
|
final widget = element.widget;
|
|
if (element is InheritedElement && widget is SurfaceVisibility) {
|
|
context.dependOnInheritedElement(element);
|
|
shown = shown && widget.shown;
|
|
current = current && widget.current;
|
|
}
|
|
return true;
|
|
});
|
|
return (shown: shown, current: current && shown);
|
|
}
|
|
|
|
@override
|
|
bool updateShouldNotify(SurfaceVisibility oldWidget) =>
|
|
shown != oldWidget.shown || current != oldWidget.current;
|
|
}
|