Add test for animated_align.0.dart API example. (#146719)
This PR contributes to https://github.com/flutter/flutter/issues/130459 ### Description - Adds `examples/api/test/widgets/implicit_animations/animated_align.0_test.dart` test
This commit is contained in:
committed by
GitHub
parent
47ce800c14
commit
ff5e2d5922
@@ -471,7 +471,6 @@ final Set<String> _knownMissingTests = <String>{
|
||||
'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/implicit_animations/animated_fractionally_sized_box.0_test.dart',
|
||||
'examples/api/test/widgets/implicit_animations/animated_align.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/inherited_notifier/inherited_notifier.0_test.dart',
|
||||
|
||||
@@ -11,19 +11,33 @@ void main() => runApp(const AnimatedAlignExampleApp());
|
||||
class AnimatedAlignExampleApp extends StatelessWidget {
|
||||
const AnimatedAlignExampleApp({super.key});
|
||||
|
||||
static const Duration duration = Duration(seconds: 1);
|
||||
static const Curve curve = Curves.fastOutSlowIn;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return MaterialApp(
|
||||
home: Scaffold(
|
||||
appBar: AppBar(title: const Text('AnimatedAlign Sample')),
|
||||
body: const AnimatedAlignExample(),
|
||||
body: const AnimatedAlignExample(
|
||||
duration: duration,
|
||||
curve: curve,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class AnimatedAlignExample extends StatefulWidget {
|
||||
const AnimatedAlignExample({super.key});
|
||||
const AnimatedAlignExample({
|
||||
required this.duration,
|
||||
required this.curve,
|
||||
super.key,
|
||||
});
|
||||
|
||||
final Duration duration;
|
||||
|
||||
final Curve curve;
|
||||
|
||||
@override
|
||||
State<AnimatedAlignExample> createState() => _AnimatedAlignExampleState();
|
||||
@@ -47,8 +61,8 @@ class _AnimatedAlignExampleState extends State<AnimatedAlignExample> {
|
||||
color: Colors.red,
|
||||
child: AnimatedAlign(
|
||||
alignment: selected ? Alignment.topRight : Alignment.bottomLeft,
|
||||
duration: const Duration(seconds: 1),
|
||||
curve: Curves.fastOutSlowIn,
|
||||
duration: widget.duration,
|
||||
curve: widget.curve,
|
||||
child: const FlutterLogo(size: 50.0),
|
||||
),
|
||||
),
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
// 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 'package:flutter/material.dart';
|
||||
import 'package:flutter_api_samples/widgets/implicit_animations/animated_align.0.dart'
|
||||
as example;
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('AnimatedAlign animates on tap', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(
|
||||
const example.AnimatedAlignExampleApp(),
|
||||
);
|
||||
|
||||
final Finder alignFinder = find.descendant(
|
||||
of: find.byType(AnimatedAlign),
|
||||
matching: find.byType(Align),
|
||||
);
|
||||
|
||||
const Alignment beginAlignment = Alignment.bottomLeft;
|
||||
const Alignment endAlignment = Alignment.topRight;
|
||||
|
||||
Align align = tester.widget(alignFinder);
|
||||
expect(align.alignment, beginAlignment);
|
||||
|
||||
// Tap on the AnimatedAlignExample to start the forward animation.
|
||||
await tester.tap(find.byType(example.AnimatedAlignExample));
|
||||
await tester.pump();
|
||||
|
||||
align = tester.widget(alignFinder);
|
||||
expect(align.alignment, beginAlignment);
|
||||
|
||||
// Advance animation to the middle.
|
||||
await tester.pump(example.AnimatedAlignExampleApp.duration ~/ 2);
|
||||
|
||||
align = tester.widget(alignFinder);
|
||||
expect(
|
||||
align.alignment,
|
||||
Alignment.lerp(
|
||||
beginAlignment,
|
||||
endAlignment,
|
||||
example.AnimatedAlignExampleApp.curve.transform(0.5),
|
||||
),
|
||||
);
|
||||
|
||||
// Advance animation to the end.
|
||||
await tester.pump(example.AnimatedAlignExampleApp.duration ~/ 2);
|
||||
|
||||
align = tester.widget(alignFinder);
|
||||
expect(align.alignment, endAlignment);
|
||||
|
||||
// Tap on the AnimatedAlignExample again to start the reverse animation.
|
||||
await tester.tap(find.byType(example.AnimatedAlignExample));
|
||||
await tester.pump();
|
||||
|
||||
align = tester.widget(alignFinder);
|
||||
expect(align.alignment, endAlignment);
|
||||
|
||||
// Advance animation to the middle.
|
||||
await tester.pump(example.AnimatedAlignExampleApp.duration ~/ 2);
|
||||
|
||||
align = tester.widget(alignFinder);
|
||||
expect(
|
||||
align.alignment,
|
||||
Alignment.lerp(
|
||||
endAlignment,
|
||||
beginAlignment,
|
||||
example.AnimatedAlignExampleApp.curve.transform(0.5),
|
||||
),
|
||||
);
|
||||
|
||||
// Advance animation to the end.
|
||||
await tester.pump(example.AnimatedAlignExampleApp.duration ~/ 2);
|
||||
|
||||
align = tester.widget(alignFinder);
|
||||
expect(align.alignment, beginAlignment);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user