Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
64327420
Unverified
Commit
64327420
authored
Oct 03, 2022
by
Taha Tesser
Committed by
GitHub
Oct 03, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update `AnimatedSlide` example (#112803)
parent
6cdb63da
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
115 additions
and
44 deletions
+115
-44
animated_slide.0.dart
...api/lib/widgets/implicit_animations/animated_slide.0.dart
+77
-43
animated_slide.0_test.dart
...st/widgets/implicit_animations/animated_slide.0_test.dart
+37
-0
implicit_animations.dart
packages/flutter/lib/src/widgets/implicit_animations.dart
+1
-1
No files found.
examples/api/lib/widgets/implicit_animations/animated_slide.0.dart
View file @
64327420
...
...
@@ -6,66 +6,100 @@
import
'package:flutter/material.dart'
;
void
main
(
)
=>
runApp
(
const
My
App
());
void
main
(
)
=>
runApp
(
const
AnimatedSlide
App
());
class
MyApp
extends
StatelessWidget
{
const
MyApp
({
super
.
key
});
static
const
String
_title
=
'Flutter Code Sample'
;
class
AnimatedSlideApp
extends
StatelessWidget
{
const
AnimatedSlideApp
({
super
.
key
});
@override
Widget
build
(
BuildContext
context
)
{
return
MaterialApp
(
title:
_title
,
home:
Scaffold
(
appBar:
AppBar
(
title:
const
Text
(
_title
)),
body:
const
MyStatefulWidget
(),
),
return
const
MaterialApp
(
home:
AnimatedSlideExample
(),
);
}
}
class
MyStatefulWidget
extends
StatefulWidget
{
const
MyStatefulWidget
({
super
.
key
});
class
AnimatedSlideExample
extends
StatefulWidget
{
const
AnimatedSlideExample
({
super
.
key
});
@override
State
<
MyStatefulWidget
>
createState
()
=>
_MyStatefulWidget
State
();
State
<
AnimatedSlideExample
>
createState
()
=>
_AnimatedSlideExample
State
();
}
class
_
MyStatefulWidgetState
extends
State
<
MyStatefulWidget
>
{
class
_
AnimatedSlideExampleState
extends
State
<
AnimatedSlideExample
>
{
Offset
offset
=
Offset
.
zero
;
void
_slideUp
()
{
setState
(()
=>
offset
-=
const
Offset
(
0
,
1
));
}
void
_slideDown
()
{
setState
(()
=>
offset
+=
const
Offset
(
0
,
1
));
}
@override
Widget
build
(
BuildContext
context
)
{
return
Column
(
mainAxisSize:
MainAxisSize
.
min
,
children:
<
Widget
>[
ElevatedButton
(
onPressed:
_slideUp
,
child:
const
Text
(
'Slide up'
),
),
ElevatedButton
(
onPressed:
_slideDown
,
child:
const
Text
(
'Slide down'
),
),
Padding
(
padding:
const
EdgeInsets
.
all
(
50
),
child:
AnimatedSlide
(
offset:
offset
,
duration:
const
Duration
(
milliseconds:
500
),
curve:
Curves
.
easeInOut
,
child:
const
FlutterLogo
(),
),
final
TextTheme
textTheme
=
Theme
.
of
(
context
).
textTheme
;
return
Scaffold
(
appBar:
AppBar
(
title:
const
Text
(
'AnimatedSlide Sample'
)),
body:
Padding
(
padding:
const
EdgeInsets
.
all
(
16.0
),
child:
Column
(
mainAxisSize:
MainAxisSize
.
min
,
children:
<
Widget
>[
Expanded
(
child:
Row
(
children:
<
Widget
>[
Expanded
(
child:
Container
(
alignment:
Alignment
.
center
,
padding:
const
EdgeInsets
.
all
(
50.0
),
child:
AnimatedSlide
(
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
),
],
),
],
),
]
,
)
,
);
}
}
examples/api/test/widgets/implicit_animations/animated_slide.0_test.dart
0 → 100644
View file @
64327420
// 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
);
});
}
packages/flutter/lib/src/widgets/implicit_animations.dart
View file @
64327420
...
...
@@ -1559,7 +1559,7 @@ class _AnimatedRotationState extends ImplicitlyAnimatedWidgetState<AnimatedRotat
///
/// {@tool dartpad}
/// 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 **
/// {@end-tool}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment