Unverified Commit 64327420 authored by Taha Tesser's avatar Taha Tesser Committed by GitHub

Update `AnimatedSlide` example (#112803)

parent 6cdb63da
...@@ -6,66 +6,100 @@ ...@@ -6,66 +6,100 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
void main() => runApp(const MyApp()); void main() => runApp(const AnimatedSlideApp());
class MyApp extends StatelessWidget { class AnimatedSlideApp extends StatelessWidget {
const MyApp({super.key}); const AnimatedSlideApp({super.key});
static const String _title = 'Flutter Code Sample';
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return MaterialApp( return const MaterialApp(
title: _title, home: AnimatedSlideExample(),
home: Scaffold(
appBar: AppBar(title: const Text(_title)),
body: const MyStatefulWidget(),
),
); );
} }
} }
class MyStatefulWidget extends StatefulWidget { class AnimatedSlideExample extends StatefulWidget {
const MyStatefulWidget({super.key}); const AnimatedSlideExample({super.key});
@override @override
State<MyStatefulWidget> createState() => _MyStatefulWidgetState(); State<AnimatedSlideExample> createState() => _AnimatedSlideExampleState();
} }
class _MyStatefulWidgetState extends State<MyStatefulWidget> { class _AnimatedSlideExampleState extends State<AnimatedSlideExample> {
Offset offset = Offset.zero; Offset offset = Offset.zero;
void _slideUp() {
setState(() => offset -= const Offset(0, 1));
}
void _slideDown() {
setState(() => offset += const Offset(0, 1));
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Column( final TextTheme textTheme = Theme.of(context).textTheme;
mainAxisSize: MainAxisSize.min,
children: <Widget>[ return Scaffold(
ElevatedButton( appBar: AppBar(title: const Text('AnimatedSlide Sample')),
onPressed: _slideUp, body: Padding(
child: const Text('Slide up'), padding: const EdgeInsets.all(16.0),
), child: Column(
ElevatedButton( mainAxisSize: MainAxisSize.min,
onPressed: _slideDown, children: <Widget>[
child: const Text('Slide down'), Expanded(
), child: Row(
Padding( children: <Widget>[
padding: const EdgeInsets.all(50), Expanded(
child: AnimatedSlide( child: Container(
offset: offset, alignment: Alignment.center,
duration: const Duration(milliseconds: 500), padding: const EdgeInsets.all(50.0),
curve: Curves.easeInOut, child: AnimatedSlide(
child: const FlutterLogo(), offset: offset,
), duration: const Duration(milliseconds: 500),
curve: Curves.easeInOut,
child: const FlutterLogo(size: 50.0),
),
),
),
Column(
children: <Widget>[
Text('Y', style: textTheme.bodyMedium),
Expanded(
child: RotatedBox(
quarterTurns: 1,
child: Slider(
min: -5.0,
max: 5.0,
value: offset.dy,
onChanged: (double value) {
setState(() {
offset = Offset(offset.dx, value);
});
},
),
),
),
],
),
],
),
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
Text('X', style: textTheme.bodyMedium),
Expanded(
child: Slider(
min: -5.0,
max: 5.0,
value: offset.dx,
onChanged: (double value) {
setState(() {
offset = Offset(value, offset.dy);
});
},
),
),
const SizedBox(width: 48.0),
],
),
],
), ),
], ),
); );
} }
} }
// 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_slide.0.dart' as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('Translate FlutterLogo using AnimatedSlide', (WidgetTester tester) async {
await tester.pumpWidget(
const example.AnimatedSlideApp(),
);
Offset logoOffset = tester.getCenter(find.byType(FlutterLogo));
expect(logoOffset.dx, 376.0);
expect(logoOffset.dy, 304.0);
// Test Y axis slider.
final Offset y = tester.getCenter(find.text('Y'));
await tester.tapAt(Offset(y.dx, y.dy + 100));
await tester.pumpAndSettle();
logoOffset = tester.getCenter(find.byType(FlutterLogo));
expect(logoOffset.dx.roundToDouble(), 376.0);
expect(logoOffset.dy.roundToDouble(), 140.0);
// Test X axis slider.
final Offset x = tester.getCenter(find.text('X'));
await tester.tapAt(Offset(x.dx + 100, x.dy));
await tester.pumpAndSettle();
logoOffset = tester.getCenter(find.byType(FlutterLogo));
expect(logoOffset.dx.roundToDouble(), 178.0);
expect(logoOffset.dy.roundToDouble(), 140.0);
});
}
...@@ -1559,7 +1559,7 @@ class _AnimatedRotationState extends ImplicitlyAnimatedWidgetState<AnimatedRotat ...@@ -1559,7 +1559,7 @@ class _AnimatedRotationState extends ImplicitlyAnimatedWidgetState<AnimatedRotat
/// ///
/// {@tool dartpad} /// {@tool dartpad}
/// This code defines a widget that uses [AnimatedSlide] to translate a [FlutterLogo] /// This code defines a widget that uses [AnimatedSlide] to translate a [FlutterLogo]
/// up or down by the amount of it's height with each press of the corresponding button. /// up or down and right or left by dragging the X and Y axis sliders.
/// ///
/// ** See code in examples/api/lib/widgets/implicit_animations/animated_slide.0.dart ** /// ** See code in examples/api/lib/widgets/implicit_animations/animated_slide.0.dart **
/// {@end-tool} /// {@end-tool}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment