Add explicit surface visibility signal

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.
This commit is contained in:
2026-11-10 20:28:09 +00:00
parent e0e8ca68f3
commit 7ff012880b
13 changed files with 179 additions and 25 deletions
+17 -12
View File
@@ -2,6 +2,7 @@ import 'package:flutter/scheduler.dart';
import 'package:flutter/widgets.dart';
import 'motion.dart';
import 'surface_visibility.dart';
/// Keeps every child mounted while fading between two indexed pages.
///
@@ -155,19 +156,23 @@ class _FadeThroughStackState extends State<FadeThroughStack>
offstage: !shown,
child: TickerMode(
enabled: active,
child: IgnorePointer(
ignoring: !active,
child: ExcludeFocus(
excluding: !active,
child: ExcludeSemantics(
child: SurfaceVisibility(
shown: shown,
current: active,
child: IgnorePointer(
ignoring: !active,
child: ExcludeFocus(
excluding: !active,
child: Transform.scale(
scale: scale,
child: Opacity(
opacity: opacity,
child: !widget.lazy || _visited.contains(index)
? widget.children[index]
: const SizedBox.shrink(),
child: ExcludeSemantics(
excluding: !active,
child: Transform.scale(
scale: scale,
child: Opacity(
opacity: opacity,
child: !widget.lazy || _visited.contains(index)
? widget.children[index]
: const SizedBox.shrink(),
),
),
),
),
+42
View File
@@ -0,0 +1,42 @@
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;
}
+2 -1
View File
@@ -1,6 +1,7 @@
import 'package:flutter/widgets.dart';
import 'elapsed_clock.dart';
import '../motion/surface_visibility.dart';
/// Builds a running item's elapsed-time text from the [ElapsedClock], and
/// rebuilds only itself as that duration advances.
@@ -39,7 +40,7 @@ class _LiveElapsedBuilderState extends State<LiveElapsedBuilder> {
_unwatch();
_clock = clock;
}
_shown = TickerMode.valuesOf(context).enabled;
_shown = SurfaceVisibility.shownOf(context);
_sync();
}
+2 -1
View File
@@ -2,6 +2,7 @@ import 'package:flutter/widgets.dart';
import 'relative_time.dart';
import 'relative_time_clock.dart';
import '../motion/surface_visibility.dart';
/// A relative-time label that rebuilds only itself, and only when its text
/// changes. Every label follows one shared minute [RelativeTimeClock] rather
@@ -53,7 +54,7 @@ class _RelativeTimeLabelState extends State<RelativeTimeLabel> {
@override
void didChangeDependencies() {
super.didChangeDependencies();
_shown = TickerMode.valuesOf(context).enabled;
_shown = SurfaceVisibility.shownOf(context);
if (_shown && _stale) _advance();
}