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.
69 lines
1.9 KiB
Dart
69 lines
1.9 KiB
Dart
import 'package:flutter/widgets.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:pipelines_app/ui/motion/fade_through_stack.dart';
|
|
import 'package:pipelines_app/ui/motion/surface_visibility.dart';
|
|
|
|
class _Values extends StatelessWidget {
|
|
const _Values({this.onBuild});
|
|
|
|
final VoidCallback? onBuild;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
onBuild?.call();
|
|
return Directionality(
|
|
textDirection: TextDirection.ltr,
|
|
child: Text(
|
|
'${SurfaceVisibility.shownOf(context)}:${SurfaceVisibility.currentOf(context)}',
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
void main() {
|
|
testWidgets('defaults to shown and current', (tester) async {
|
|
await tester.pumpWidget(const _Values());
|
|
expect(find.text('true:true'), findsOneWidget);
|
|
});
|
|
|
|
testWidgets('nested visibility combines', (tester) async {
|
|
await tester.pumpWidget(
|
|
const SurfaceVisibility(
|
|
shown: false,
|
|
current: true,
|
|
child: SurfaceVisibility(shown: true, current: true, child: _Values()),
|
|
),
|
|
);
|
|
expect(find.text('false:false'), findsOneWidget);
|
|
});
|
|
|
|
testWidgets('dependents rebuild when visibility changes', (tester) async {
|
|
var builds = 0;
|
|
Widget app(bool shown) => SurfaceVisibility(
|
|
shown: shown,
|
|
current: shown,
|
|
child: _Values(onBuild: () => builds++),
|
|
);
|
|
|
|
await tester.pumpWidget(app(true));
|
|
expect(builds, 1);
|
|
await tester.pumpWidget(app(false));
|
|
expect(builds, 2);
|
|
expect(find.text('false:false'), findsOneWidget);
|
|
});
|
|
|
|
testWidgets('FadeThroughStack marks only the active page current', (
|
|
tester,
|
|
) async {
|
|
await tester.pumpWidget(
|
|
const Directionality(
|
|
textDirection: TextDirection.ltr,
|
|
child: FadeThroughStack(index: 0, children: [_Values(), _Values()]),
|
|
),
|
|
);
|
|
|
|
expect(find.text('true:true'), findsOneWidget);
|
|
expect(find.text('false:false', skipOffstage: false), findsOneWidget);
|
|
});
|
|
}
|