mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00
Add test for sliver_animated_opacity.0.dart API example. (#146722)
This PR contributes to https://github.com/flutter/flutter/issues/130459 ### Description - Adds `examples/api/test/widgets/implicit_animations/sliver_animated_opacity.0_test.dart` test
This commit is contained in:
parent
790ce64f0b
commit
9ebf80a80a
@ -470,7 +470,6 @@ final Set<String> _knownMissingTests = <String>{
|
|||||||
'examples/api/test/widgets/focus_scope/focus.1_test.dart',
|
'examples/api/test/widgets/focus_scope/focus.1_test.dart',
|
||||||
'examples/api/test/widgets/focus_scope/focus_scope.0_test.dart',
|
'examples/api/test/widgets/focus_scope/focus_scope.0_test.dart',
|
||||||
'examples/api/test/widgets/implicit_animations/animated_fractionally_sized_box.0_test.dart',
|
'examples/api/test/widgets/implicit_animations/animated_fractionally_sized_box.0_test.dart',
|
||||||
'examples/api/test/widgets/implicit_animations/sliver_animated_opacity.0_test.dart',
|
|
||||||
'examples/api/test/widgets/scroll_view/custom_scroll_view.1_test.dart',
|
'examples/api/test/widgets/scroll_view/custom_scroll_view.1_test.dart',
|
||||||
'examples/api/test/widgets/inherited_notifier/inherited_notifier.0_test.dart',
|
'examples/api/test/widgets/inherited_notifier/inherited_notifier.0_test.dart',
|
||||||
'examples/api/test/animation/curves/curve2_d.0_test.dart',
|
'examples/api/test/animation/curves/curve2_d.0_test.dart',
|
||||||
|
@ -11,13 +11,19 @@ void main() => runApp(const SliverAnimatedOpacityExampleApp());
|
|||||||
class SliverAnimatedOpacityExampleApp extends StatelessWidget {
|
class SliverAnimatedOpacityExampleApp extends StatelessWidget {
|
||||||
const SliverAnimatedOpacityExampleApp({super.key});
|
const SliverAnimatedOpacityExampleApp({super.key});
|
||||||
|
|
||||||
|
static const Duration duration = Duration(milliseconds: 500);
|
||||||
|
static const Curve curve = Curves.easeInOut;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return MaterialApp(
|
return MaterialApp(
|
||||||
home: Scaffold(
|
home: Scaffold(
|
||||||
appBar: AppBar(title: const Text('SliverAnimatedOpacity Sample')),
|
appBar: AppBar(title: const Text('SliverAnimatedOpacity Sample')),
|
||||||
body: const Center(
|
body: const Center(
|
||||||
child: SliverAnimatedOpacityExample(),
|
child: SliverAnimatedOpacityExample(
|
||||||
|
duration: duration,
|
||||||
|
curve: curve,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
@ -25,13 +31,23 @@ class SliverAnimatedOpacityExampleApp extends StatelessWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class SliverAnimatedOpacityExample extends StatefulWidget {
|
class SliverAnimatedOpacityExample extends StatefulWidget {
|
||||||
const SliverAnimatedOpacityExample({super.key});
|
const SliverAnimatedOpacityExample({
|
||||||
|
required this.duration,
|
||||||
|
required this.curve,
|
||||||
|
super.key,
|
||||||
|
});
|
||||||
|
|
||||||
|
final Duration duration;
|
||||||
|
|
||||||
|
final Curve curve;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<SliverAnimatedOpacityExample> createState() => _SliverAnimatedOpacityExampleState();
|
State<SliverAnimatedOpacityExample> createState() =>
|
||||||
|
_SliverAnimatedOpacityExampleState();
|
||||||
}
|
}
|
||||||
|
|
||||||
class _SliverAnimatedOpacityExampleState extends State<SliverAnimatedOpacityExample>
|
class _SliverAnimatedOpacityExampleState
|
||||||
|
extends State<SliverAnimatedOpacityExample>
|
||||||
with SingleTickerProviderStateMixin {
|
with SingleTickerProviderStateMixin {
|
||||||
bool _visible = true;
|
bool _visible = true;
|
||||||
|
|
||||||
@ -40,7 +56,8 @@ class _SliverAnimatedOpacityExampleState extends State<SliverAnimatedOpacityExam
|
|||||||
return CustomScrollView(slivers: <Widget>[
|
return CustomScrollView(slivers: <Widget>[
|
||||||
SliverAnimatedOpacity(
|
SliverAnimatedOpacity(
|
||||||
opacity: _visible ? 1.0 : 0.0,
|
opacity: _visible ? 1.0 : 0.0,
|
||||||
duration: const Duration(milliseconds: 500),
|
duration: widget.duration,
|
||||||
|
curve: widget.curve,
|
||||||
sliver: SliverFixedExtentList(
|
sliver: SliverFixedExtentList(
|
||||||
itemExtent: 100.0,
|
itemExtent: 100.0,
|
||||||
delegate: SliverChildBuilderDelegate(
|
delegate: SliverChildBuilderDelegate(
|
||||||
|
@ -0,0 +1,84 @@
|
|||||||
|
// Copyright 2014 The Flutter Authors. All rights reserved.
|
||||||
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
|
// found in the LICENSE file.
|
||||||
|
|
||||||
|
import 'dart:ui';
|
||||||
|
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_api_samples/widgets/implicit_animations/sliver_animated_opacity.0.dart'
|
||||||
|
as example;
|
||||||
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
testWidgets(
|
||||||
|
'SilverAnimatedOpacity animates on FloatingActionButton tap',
|
||||||
|
(WidgetTester tester) async {
|
||||||
|
await tester.pumpWidget(
|
||||||
|
const example.SliverAnimatedOpacityExampleApp(),
|
||||||
|
);
|
||||||
|
|
||||||
|
final Finder fadeTransitionFinder = find.descendant(
|
||||||
|
of: find.byType(SliverAnimatedOpacity),
|
||||||
|
matching: find.byType(SliverFadeTransition),
|
||||||
|
);
|
||||||
|
|
||||||
|
const double beginOpacity = 1.0;
|
||||||
|
const double endOpacity = 0.0;
|
||||||
|
|
||||||
|
SliverFadeTransition fadeTransition = tester.widget(fadeTransitionFinder);
|
||||||
|
expect(fadeTransition.opacity.value, beginOpacity);
|
||||||
|
|
||||||
|
// Tap on the FloatingActionButton to start the forward animation.
|
||||||
|
await tester.tap(find.byType(FloatingActionButton));
|
||||||
|
await tester.pump();
|
||||||
|
|
||||||
|
fadeTransition = tester.widget(fadeTransitionFinder);
|
||||||
|
expect(fadeTransition.opacity.value, beginOpacity);
|
||||||
|
|
||||||
|
// Advance animation to the middle.
|
||||||
|
await tester.pump(example.SliverAnimatedOpacityExampleApp.duration ~/ 2);
|
||||||
|
|
||||||
|
fadeTransition = tester.widget(fadeTransitionFinder);
|
||||||
|
expect(
|
||||||
|
fadeTransition.opacity.value,
|
||||||
|
lerpDouble(
|
||||||
|
beginOpacity,
|
||||||
|
endOpacity,
|
||||||
|
example.SliverAnimatedOpacityExampleApp.curve.transform(0.5),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
// Advance animation to the end.
|
||||||
|
await tester.pump(example.SliverAnimatedOpacityExampleApp.duration ~/ 2);
|
||||||
|
|
||||||
|
fadeTransition = tester.widget(fadeTransitionFinder);
|
||||||
|
expect(fadeTransition.opacity.value, endOpacity);
|
||||||
|
|
||||||
|
// Tap on the FloatingActionButton again to start the reverse animation.
|
||||||
|
await tester.tap(find.byType(FloatingActionButton));
|
||||||
|
await tester.pump();
|
||||||
|
|
||||||
|
fadeTransition = tester.widget(fadeTransitionFinder);
|
||||||
|
expect(fadeTransition.opacity.value, endOpacity);
|
||||||
|
|
||||||
|
// Advance animation to the middle.
|
||||||
|
await tester.pump(example.SliverAnimatedOpacityExampleApp.duration ~/ 2);
|
||||||
|
|
||||||
|
fadeTransition = tester.widget(fadeTransitionFinder);
|
||||||
|
expect(
|
||||||
|
fadeTransition.opacity.value,
|
||||||
|
lerpDouble(
|
||||||
|
endOpacity,
|
||||||
|
beginOpacity,
|
||||||
|
example.SliverAnimatedOpacityExampleApp.curve.transform(0.5),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
// Advance animation to the end.
|
||||||
|
await tester.pump(example.SliverAnimatedOpacityExampleApp.duration ~/ 2);
|
||||||
|
|
||||||
|
fadeTransition = tester.widget(fadeTransitionFinder);
|
||||||
|
expect(fadeTransition.opacity.value, beginOpacity);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user