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
3c12279f
Unverified
Commit
3c12279f
authored
Aug 05, 2020
by
includecmath
Committed by
GitHub
Aug 05, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[widgets] Refactor Overlay insert methods entries assert (#62407)
parent
bef6d154
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
102 additions
and
38 deletions
+102
-38
overlay.dart
packages/flutter/lib/src/widgets/overlay.dart
+21
-38
overlay_test.dart
packages/flutter/test/widgets/overlay_test.dart
+81
-0
No files found.
packages/flutter/lib/src/widgets/overlay.dart
View file @
3c12279f
...
...
@@ -34,7 +34,7 @@ import 'ticker_provider.dart';
/// follows the user's finger across the screen after the drag begins. Using the
/// overlay to display the drag avatar lets the avatar float over the other
/// widgets in the app. As the user's finger moves, draggable calls
/// [markNeedsBuild] on the overlay entry to cause it to rebuild. I
t
its build,
/// [markNeedsBuild] on the overlay entry to cause it to rebuild. I
n
its build,
/// the entry includes a [Positioned] with its top and left property set to
/// position the drag avatar near the user's finger. When the drag is over,
/// [Draggable] removes the entry from the overlay to remove the drag avatar
...
...
@@ -209,7 +209,7 @@ class Overlay extends StatefulWidget {
/// [OverlayState] is initialized.
///
/// Rather than creating an overlay, consider using the overlay that is
/// created by the [
WidgetsApp] or the
[MaterialApp] for the application.
/// created by the [
Navigator] in a [WidgetsApp] or a
[MaterialApp] for the application.
const
Overlay
({
Key
key
,
this
.
initialEntries
=
const
<
OverlayEntry
>[],
...
...
@@ -308,18 +308,7 @@ class OverlayState extends State<Overlay> with TickerProviderStateMixin {
///
/// It is an error to specify both `above` and `below`.
void
insert
(
OverlayEntry
entry
,
{
OverlayEntry
below
,
OverlayEntry
above
})
{
assert
(
above
==
null
||
below
==
null
,
'Only one of `above` and `below` may be specified.'
,
);
assert
(
above
==
null
||
(
above
.
_overlay
==
this
&&
_entries
.
contains
(
above
)),
'The provided entry for `above` is not present in the Overlay.'
,
);
assert
(
below
==
null
||
(
below
.
_overlay
==
this
&&
_entries
.
contains
(
below
)),
'The provided entry for `below` is not present in the Overlay.'
,
);
assert
(
_debugVerifyInsertPosition
(
above
,
below
));
assert
(!
_entries
.
contains
(
entry
),
'The specified entry is already present in the Overlay.'
);
assert
(
entry
.
_overlay
==
null
,
'The specified entry is already present in another Overlay.'
);
entry
.
_overlay
=
this
;
...
...
@@ -336,18 +325,7 @@ class OverlayState extends State<Overlay> with TickerProviderStateMixin {
///
/// It is an error to specify both `above` and `below`.
void
insertAll
(
Iterable
<
OverlayEntry
>
entries
,
{
OverlayEntry
below
,
OverlayEntry
above
})
{
assert
(
above
==
null
||
below
==
null
,
'Only one of `above` and `below` may be specified.'
,
);
assert
(
above
==
null
||
(
above
.
_overlay
==
this
&&
_entries
.
contains
(
above
)),
'The provided entry for `above` is not present in the Overlay.'
,
);
assert
(
below
==
null
||
(
below
.
_overlay
==
this
&&
_entries
.
contains
(
below
)),
'The provided entry for `below` is not present in the Overlay.'
,
);
assert
(
_debugVerifyInsertPosition
(
above
,
below
));
assert
(
entries
.
every
((
OverlayEntry
entry
)
=>
!
_entries
.
contains
(
entry
)),
'One or more of the specified entries are already present in the Overlay.'
...
...
@@ -367,6 +345,22 @@ class OverlayState extends State<Overlay> with TickerProviderStateMixin {
});
}
bool
_debugVerifyInsertPosition
(
OverlayEntry
above
,
OverlayEntry
below
,
{
Iterable
<
OverlayEntry
>
newEntries
})
{
assert
(
above
==
null
||
below
==
null
,
'Only one of `above` and `below` may be specified.'
,
);
assert
(
above
==
null
||
(
above
.
_overlay
==
this
&&
_entries
.
contains
(
above
)
&&
(
newEntries
?.
contains
(
above
)
??
true
)),
'The provided entry used for `above` must be present in the Overlay
${newEntries != null ? ' and in the `newEntriesList`' : ''}
.'
,
);
assert
(
below
==
null
||
(
below
.
_overlay
==
this
&&
_entries
.
contains
(
below
)
&&
(
newEntries
?.
contains
(
below
)
??
true
)),
'The provided entry used for `below` must be present in the Overlay
${newEntries != null ? ' and in the `newEntriesList`' : ''}
.'
,
);
return
true
;
}
/// Remove all the entries listed in the given iterable, then reinsert them
/// into the overlay in the given order.
///
...
...
@@ -386,18 +380,7 @@ class OverlayState extends State<Overlay> with TickerProviderStateMixin {
/// It is an error to specify both `above` and `below`.
void
rearrange
(
Iterable
<
OverlayEntry
>
newEntries
,
{
OverlayEntry
below
,
OverlayEntry
above
})
{
final
List
<
OverlayEntry
>
newEntriesList
=
newEntries
is
List
<
OverlayEntry
>
?
newEntries
:
newEntries
.
toList
(
growable:
false
);
assert
(
above
==
null
||
below
==
null
,
'Only one of `above` and `below` may be specified.'
,
);
assert
(
above
==
null
||
(
above
.
_overlay
==
this
&&
_entries
.
contains
(
above
)
&&
newEntriesList
.
contains
(
above
)),
'The entry used for `above` must be in the Overlay and in the `newEntriesList`.'
);
assert
(
below
==
null
||
(
below
.
_overlay
==
this
&&
_entries
.
contains
(
below
)
&&
newEntriesList
.
contains
(
below
)),
'The entry used for `below` must be in the Overlay and in the `newEntriesList`.'
);
assert
(
_debugVerifyInsertPosition
(
above
,
below
,
newEntries:
newEntriesList
));
assert
(
newEntriesList
.
every
((
OverlayEntry
entry
)
=>
entry
.
_overlay
==
null
||
entry
.
_overlay
==
this
),
'One or more of the specified entries are already present in another Overlay.'
...
...
packages/flutter/test/widgets/overlay_test.dart
View file @
3c12279f
...
...
@@ -619,6 +619,87 @@ void main() {
expect
(
buildOrder
,
<
int
>[
3
,
4
,
1
,
2
,
0
]);
});
testWidgets
(
'debugVerifyInsertPosition'
,
(
WidgetTester
tester
)
async
{
final
GlobalKey
overlayKey
=
GlobalKey
();
OverlayEntry
base
;
await
tester
.
pumpWidget
(
Directionality
(
textDirection:
TextDirection
.
ltr
,
child:
Overlay
(
key:
overlayKey
,
initialEntries:
<
OverlayEntry
>[
base
=
OverlayEntry
(
builder:
(
BuildContext
context
)
{
return
Container
();
},
),
],
),
),
);
final
OverlayState
overlay
=
overlayKey
.
currentState
as
OverlayState
;
try
{
overlay
.
insert
(
OverlayEntry
(
builder:
(
BuildContext
context
)
{
return
Container
();
}),
above:
OverlayEntry
(
builder:
(
BuildContext
context
)
{
return
Container
();
},
),
below:
OverlayEntry
(
builder:
(
BuildContext
context
)
{
return
Container
();
},
),
);
}
catch
(
e
)
{
expect
(
e
,
isAssertionError
);
expect
(
e
.
message
,
'Only one of `above` and `below` may be specified.'
);
}
expect
(()
=>
overlay
.
insert
(
OverlayEntry
(
builder:
(
BuildContext
context
)
{
return
Container
();
}),
above:
base
,
),
isNot
(
throwsAssertionError
));
try
{
overlay
.
insert
(
OverlayEntry
(
builder:
(
BuildContext
context
)
{
return
Container
();
}),
above:
OverlayEntry
(
builder:
(
BuildContext
context
)
{
return
Container
();
},
),
);
}
catch
(
e
)
{
expect
(
e
,
isAssertionError
);
expect
(
e
.
message
,
'The provided entry used for `above` must be present in the Overlay.'
);
}
try
{
overlay
.
rearrange
(<
OverlayEntry
>[
base
],
above:
OverlayEntry
(
builder:
(
BuildContext
context
)
{
return
Container
();
},
));
}
catch
(
e
)
{
expect
(
e
,
isAssertionError
);
expect
(
e
.
message
,
'The provided entry used for `above` must be present in the Overlay and in the `newEntriesList`.'
);
}
await
tester
.
pump
();
});
testWidgets
(
'OverlayState.of() called without Overlay being exist'
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
Directionality
(
...
...
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