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
7c76dee7
Unverified
Commit
7c76dee7
authored
Apr 02, 2019
by
Michael Goderbauer
Committed by
GitHub
Apr 02, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make heroes fly on pushReplacement (#30228)
parent
d4c4f563
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
96 additions
and
0 deletions
+96
-0
heroes.dart
packages/flutter/lib/src/widgets/heroes.dart
+9
-0
heroes_test.dart
packages/flutter/test/widgets/heroes_test.dart
+87
-0
No files found.
packages/flutter/lib/src/widgets/heroes.dart
View file @
7c76dee7
...
...
@@ -621,6 +621,15 @@ class HeroController extends NavigatorObserver {
_maybeStartHeroTransition
(
route
,
previousRoute
,
HeroFlightDirection
.
pop
,
false
);
}
@override
void
didReplace
({
Route
<
dynamic
>
newRoute
,
Route
<
dynamic
>
oldRoute
})
{
assert
(
navigator
!=
null
);
if
(
newRoute
?.
isCurrent
==
true
)
{
// Only run hero animations if the top-most route got replaced.
_maybeStartHeroTransition
(
oldRoute
,
newRoute
,
HeroFlightDirection
.
push
,
false
);
}
}
@override
void
didStartUserGesture
(
Route
<
dynamic
>
route
,
Route
<
dynamic
>
previousRoute
)
{
assert
(
navigator
!=
null
);
...
...
packages/flutter/test/widgets/heroes_test.dart
View file @
7c76dee7
...
...
@@ -1692,4 +1692,91 @@ void main() {
expect
(
tester
.
takeException
(),
isAssertionError
);
});
testWidgets
(
'Heroes fly on pushReplacement'
,
(
WidgetTester
tester
)
async
{
// Regression test for https://github.com/flutter/flutter/issues/28041.
const
String
heroTag
=
'foo'
;
final
GlobalKey
<
NavigatorState
>
navigator
=
GlobalKey
();
final
Key
smallContainer
=
UniqueKey
();
final
Key
largeContainer
=
UniqueKey
();
await
tester
.
pumpWidget
(
MaterialApp
(
navigatorKey:
navigator
,
home:
Center
(
child:
Card
(
child:
Hero
(
tag:
heroTag
,
child:
Container
(
key:
largeContainer
,
color:
Colors
.
red
,
height:
200.0
,
width:
200.0
,
),
),
),
),
),
);
// The initial setup.
expect
(
find
.
byKey
(
largeContainer
),
isOnstage
);
expect
(
find
.
byKey
(
largeContainer
),
isInCard
);
expect
(
find
.
byKey
(
smallContainer
,
skipOffstage:
false
),
findsNothing
);
navigator
.
currentState
.
pushReplacement
(
MaterialPageRoute
<
void
>(
builder:
(
BuildContext
context
)
{
return
Center
(
child:
Card
(
child:
Hero
(
tag:
heroTag
,
child:
Container
(
key:
smallContainer
,
color:
Colors
.
red
,
height:
100.0
,
width:
100.0
,
),
),
),
);
}
),
);
await
tester
.
pump
();
// The second route exists offstage.
expect
(
find
.
byKey
(
largeContainer
),
isOnstage
);
expect
(
find
.
byKey
(
largeContainer
),
isInCard
);
expect
(
find
.
byKey
(
smallContainer
,
skipOffstage:
false
),
isOffstage
);
expect
(
find
.
byKey
(
smallContainer
,
skipOffstage:
false
),
isInCard
);
await
tester
.
pump
();
// The hero started flying.
expect
(
find
.
byKey
(
largeContainer
),
findsNothing
);
expect
(
find
.
byKey
(
smallContainer
),
isOnstage
);
expect
(
find
.
byKey
(
smallContainer
),
isNotInCard
);
await
tester
.
pump
(
const
Duration
(
milliseconds:
100
));
// The hero is in-flight.
expect
(
find
.
byKey
(
largeContainer
),
findsNothing
);
expect
(
find
.
byKey
(
smallContainer
),
isOnstage
);
expect
(
find
.
byKey
(
smallContainer
),
isNotInCard
);
final
Size
size
=
tester
.
getSize
(
find
.
byKey
(
smallContainer
));
expect
(
size
.
height
,
greaterThan
(
100
));
expect
(
size
.
width
,
greaterThan
(
100
));
expect
(
size
.
height
,
lessThan
(
200
));
expect
(
size
.
width
,
lessThan
(
200
));
await
tester
.
pumpAndSettle
();
// The transition has ended.
expect
(
find
.
byKey
(
largeContainer
),
findsNothing
);
expect
(
find
.
byKey
(
smallContainer
),
isOnstage
);
expect
(
find
.
byKey
(
smallContainer
),
isInCard
);
expect
(
tester
.
getSize
(
find
.
byKey
(
smallContainer
)),
const
Size
(
100
,
100
));
});
}
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