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 @@
...
@@ -6,66 +6,100 @@
import
'package:flutter/material.dart'
;
import
'package:flutter/material.dart'
;
void
main
(
)
=>
runApp
(
const
My
App
());
void
main
(
)
=>
runApp
(
const
AnimatedSlide
App
());
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
()
=>
_MyStatefulWidget
State
();
State
<
AnimatedSlideExample
>
createState
()
=>
_AnimatedSlideExample
State
();
}
}
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
),
],
),
],
),
),
]
,
)
,
);
);
}
}
}
}
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
...
@@ -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}
...
...
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