mirror of
https://github.com/flutter/flutter
synced 2024-10-03 23:14:12 +00:00
Add test for animated_fractionally_sized_box.0.dart API example. (#146721)
This PR contributes to https://github.com/flutter/flutter/issues/130459 ### Description - Adds `examples/api/test/widgets/implicit_animations/animated_fractionally_sized_box.0_test.dart` test
This commit is contained in:
parent
a1cb040511
commit
32ea4b3c46
|
@ -466,7 +466,6 @@ final Set<String> _knownMissingTests = <String>{
|
||||||
'examples/api/test/widgets/focus_scope/focus.0_test.dart',
|
'examples/api/test/widgets/focus_scope/focus.0_test.dart',
|
||||||
'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/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,25 +11,43 @@ void main() => runApp(const AnimatedFractionallySizedBoxExampleApp());
|
||||||
class AnimatedFractionallySizedBoxExampleApp extends StatelessWidget {
|
class AnimatedFractionallySizedBoxExampleApp extends StatelessWidget {
|
||||||
const AnimatedFractionallySizedBoxExampleApp({super.key});
|
const AnimatedFractionallySizedBoxExampleApp({super.key});
|
||||||
|
|
||||||
|
static const Duration duration = Duration(seconds: 1);
|
||||||
|
static const Curve curve = Curves.fastOutSlowIn;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return MaterialApp(
|
return MaterialApp(
|
||||||
home: Scaffold(
|
home: Scaffold(
|
||||||
appBar: AppBar(title: const Text('AnimatedFractionallySizedBox Sample')),
|
appBar: AppBar(
|
||||||
body: const AnimatedFractionallySizedBoxExample(),
|
title: const Text('AnimatedFractionallySizedBox Sample'),
|
||||||
|
),
|
||||||
|
body: const AnimatedFractionallySizedBoxExample(
|
||||||
|
duration: duration,
|
||||||
|
curve: curve,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class AnimatedFractionallySizedBoxExample extends StatefulWidget {
|
class AnimatedFractionallySizedBoxExample extends StatefulWidget {
|
||||||
const AnimatedFractionallySizedBoxExample({super.key});
|
const AnimatedFractionallySizedBoxExample({
|
||||||
|
required this.duration,
|
||||||
|
required this.curve,
|
||||||
|
super.key,
|
||||||
|
});
|
||||||
|
|
||||||
|
final Duration duration;
|
||||||
|
|
||||||
|
final Curve curve;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<AnimatedFractionallySizedBoxExample> createState() => _AnimatedFractionallySizedBoxExampleState();
|
State<AnimatedFractionallySizedBoxExample> createState() =>
|
||||||
|
_AnimatedFractionallySizedBoxExampleState();
|
||||||
}
|
}
|
||||||
|
|
||||||
class _AnimatedFractionallySizedBoxExampleState extends State<AnimatedFractionallySizedBoxExample> {
|
class _AnimatedFractionallySizedBoxExampleState
|
||||||
|
extends State<AnimatedFractionallySizedBoxExample> {
|
||||||
bool selected = false;
|
bool selected = false;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -50,8 +68,8 @@ class _AnimatedFractionallySizedBoxExampleState extends State<AnimatedFractional
|
||||||
widthFactor: selected ? 0.25 : 0.75,
|
widthFactor: selected ? 0.25 : 0.75,
|
||||||
heightFactor: selected ? 0.75 : 0.25,
|
heightFactor: selected ? 0.75 : 0.25,
|
||||||
alignment: selected ? Alignment.topLeft : Alignment.bottomRight,
|
alignment: selected ? Alignment.topLeft : Alignment.bottomRight,
|
||||||
duration: const Duration(seconds: 1),
|
duration: widget.duration,
|
||||||
curve: Curves.fastOutSlowIn,
|
curve: widget.curve,
|
||||||
child: const ColoredBox(
|
child: const ColoredBox(
|
||||||
color: Colors.blue,
|
color: Colors.blue,
|
||||||
child: FlutterLogo(size: 75),
|
child: FlutterLogo(size: 75),
|
||||||
|
|
|
@ -0,0 +1,125 @@
|
||||||
|
// 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/animated_fractionally_sized_box.0.dart'
|
||||||
|
as example;
|
||||||
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
testWidgets(
|
||||||
|
'AnimatedFractionallySizedBox animates on tap',
|
||||||
|
(WidgetTester tester) async {
|
||||||
|
await tester.pumpWidget(
|
||||||
|
const example.AnimatedFractionallySizedBoxExampleApp(),
|
||||||
|
);
|
||||||
|
|
||||||
|
final Finder fractionallySizedBoxFinder = find.descendant(
|
||||||
|
of: find.byType(AnimatedFractionallySizedBox),
|
||||||
|
matching: find.byType(FractionallySizedBox),
|
||||||
|
);
|
||||||
|
|
||||||
|
const double beginWidthFactor = 0.75;
|
||||||
|
const double endWidthFactor = 0.25;
|
||||||
|
const double beginHeightFactor = 0.25;
|
||||||
|
const double endHeightFactor = 0.75;
|
||||||
|
const Alignment beginAlignment = Alignment.bottomRight;
|
||||||
|
const Alignment endAlignment = Alignment.topLeft;
|
||||||
|
|
||||||
|
FractionallySizedBox fractionallySizedBox = tester.widget(
|
||||||
|
fractionallySizedBoxFinder,
|
||||||
|
);
|
||||||
|
expect(fractionallySizedBox.widthFactor, beginWidthFactor);
|
||||||
|
expect(fractionallySizedBox.heightFactor, beginHeightFactor);
|
||||||
|
expect(fractionallySizedBox.alignment, beginAlignment);
|
||||||
|
|
||||||
|
// Tap on the AnimatedFractionallySizedBoxExample to start the forward
|
||||||
|
// animation.
|
||||||
|
await tester.tap(
|
||||||
|
find.byType(example.AnimatedFractionallySizedBoxExample),
|
||||||
|
);
|
||||||
|
await tester.pump();
|
||||||
|
|
||||||
|
fractionallySizedBox = tester.widget(fractionallySizedBoxFinder);
|
||||||
|
expect(fractionallySizedBox.widthFactor, beginWidthFactor);
|
||||||
|
expect(fractionallySizedBox.heightFactor, beginHeightFactor);
|
||||||
|
expect(fractionallySizedBox.alignment, beginAlignment);
|
||||||
|
|
||||||
|
// Advance animation to the middle.
|
||||||
|
await tester.pump(
|
||||||
|
example.AnimatedFractionallySizedBoxExampleApp.duration ~/ 2,
|
||||||
|
);
|
||||||
|
|
||||||
|
final double t =
|
||||||
|
example.AnimatedFractionallySizedBoxExampleApp.curve.transform(0.5);
|
||||||
|
|
||||||
|
fractionallySizedBox = tester.widget(fractionallySizedBoxFinder);
|
||||||
|
expect(
|
||||||
|
fractionallySizedBox.widthFactor,
|
||||||
|
lerpDouble(beginWidthFactor, endWidthFactor, t),
|
||||||
|
);
|
||||||
|
expect(
|
||||||
|
fractionallySizedBox.heightFactor,
|
||||||
|
lerpDouble(beginHeightFactor, endHeightFactor, t),
|
||||||
|
);
|
||||||
|
expect(
|
||||||
|
fractionallySizedBox.alignment,
|
||||||
|
Alignment.lerp(beginAlignment, endAlignment, t),
|
||||||
|
);
|
||||||
|
|
||||||
|
// Advance animation to the end.
|
||||||
|
await tester.pump(
|
||||||
|
example.AnimatedFractionallySizedBoxExampleApp.duration ~/ 2,
|
||||||
|
);
|
||||||
|
|
||||||
|
fractionallySizedBox = tester.widget(fractionallySizedBoxFinder);
|
||||||
|
expect(fractionallySizedBox.widthFactor, endWidthFactor);
|
||||||
|
expect(fractionallySizedBox.heightFactor, endHeightFactor);
|
||||||
|
expect(fractionallySizedBox.alignment, endAlignment);
|
||||||
|
|
||||||
|
// Tap on the AnimatedFractionallySizedBoxExample again to start the
|
||||||
|
// reverse animation.
|
||||||
|
await tester.tap(
|
||||||
|
find.byType(example.AnimatedFractionallySizedBoxExample),
|
||||||
|
);
|
||||||
|
await tester.pump();
|
||||||
|
|
||||||
|
fractionallySizedBox = tester.widget(fractionallySizedBoxFinder);
|
||||||
|
expect(fractionallySizedBox.widthFactor, endWidthFactor);
|
||||||
|
expect(fractionallySizedBox.heightFactor, endHeightFactor);
|
||||||
|
expect(fractionallySizedBox.alignment, endAlignment);
|
||||||
|
|
||||||
|
// Advance animation to the middle.
|
||||||
|
await tester.pump(
|
||||||
|
example.AnimatedFractionallySizedBoxExampleApp.duration ~/ 2,
|
||||||
|
);
|
||||||
|
|
||||||
|
fractionallySizedBox = tester.widget(fractionallySizedBoxFinder);
|
||||||
|
expect(
|
||||||
|
fractionallySizedBox.widthFactor,
|
||||||
|
lerpDouble(endWidthFactor, beginWidthFactor, t),
|
||||||
|
);
|
||||||
|
expect(
|
||||||
|
fractionallySizedBox.heightFactor,
|
||||||
|
lerpDouble(endHeightFactor, beginHeightFactor, t),
|
||||||
|
);
|
||||||
|
expect(
|
||||||
|
fractionallySizedBox.alignment,
|
||||||
|
Alignment.lerp(endAlignment, beginAlignment, t),
|
||||||
|
);
|
||||||
|
|
||||||
|
// Advance animation to the end.
|
||||||
|
await tester.pump(
|
||||||
|
example.AnimatedFractionallySizedBoxExampleApp.duration ~/ 2,
|
||||||
|
);
|
||||||
|
|
||||||
|
fractionallySizedBox = tester.widget(fractionallySizedBoxFinder);
|
||||||
|
expect(fractionallySizedBox.widthFactor, beginWidthFactor);
|
||||||
|
expect(fractionallySizedBox.heightFactor, beginHeightFactor);
|
||||||
|
expect(fractionallySizedBox.alignment, beginAlignment);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
Loading…
Reference in a new issue