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
5b1a7712
Unverified
Commit
5b1a7712
authored
Jan 22, 2021
by
xubaolin
Committed by
GitHub
Jan 22, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
MaterialBanner alignment fixes and improvements (#74309)
parent
74798029
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
51 additions
and
1 deletion
+51
-1
banner.dart
packages/flutter/lib/src/material/banner.dart
+13
-0
banner_test.dart
packages/flutter/test/material/banner_test.dart
+38
-1
No files found.
packages/flutter/lib/src/material/banner.dart
View file @
5b1a7712
...
...
@@ -50,6 +50,10 @@ import 'theme.dart';
/// Otherwise, the [actions] will be placed below the [content]. Use
/// [forceActionsBelow] to override this behavior.
///
/// If the [actions] placed below the [content], they will be laid out in a row.
/// If there isn't sufficient room to display everything, they are laid out
/// in a column instead.
///
/// The [actions] and [content] must be provided. An optional leading widget
/// (typically an [Image]) can also be provided. The [contentTextStyle] and
/// [backgroundColor] can be provided to customize the banner.
...
...
@@ -70,6 +74,7 @@ class MaterialBanner extends StatelessWidget {
this
.
padding
,
this
.
leadingPadding
,
this
.
forceActionsBelow
=
false
,
this
.
overflowAlignment
=
OverflowBarAlignment
.
end
,
})
:
assert
(
content
!=
null
),
assert
(
actions
!=
null
),
assert
(
forceActionsBelow
!=
null
),
...
...
@@ -124,8 +129,15 @@ class MaterialBanner extends StatelessWidget {
/// this is false, the [actions] will be placed on the trailing side of the
/// [content] if [actions]'s length is 1 and below the [content] if greater
/// than 1.
///
/// Defaults to false.
final
bool
forceActionsBelow
;
/// The horizontal alignment of the [actions] when the [actions] laid out in a column.
///
/// Defaults to [OverflowBarAlignment.end].
final
OverflowBarAlignment
overflowAlignment
;
@override
Widget
build
(
BuildContext
context
)
{
assert
(
actions
.
isNotEmpty
);
...
...
@@ -146,6 +158,7 @@ class MaterialBanner extends StatelessWidget {
constraints:
const
BoxConstraints
(
minHeight:
52.0
),
padding:
const
EdgeInsets
.
symmetric
(
horizontal:
8
),
child:
OverflowBar
(
overflowAlignment:
overflowAlignment
,
spacing:
8
,
children:
actions
,
),
...
...
packages/flutter/test/material/banner_test.dart
View file @
5b1a7712
...
...
@@ -243,10 +243,47 @@ void main() {
await
tester
.
pumpWidget
(
buildFrame
(
TextDirection
.
ltr
));
for
(
int
index
=
0
;
index
<
actionCount
;
index
+=
1
)
{
expect
(
tester
.
getTopLeft
(
find
.
byKey
(
ValueKey
<
int
>(
index
))),
Offset
(
8
,
134.0
+
index
*
10
));
expect
(
tester
.
getTopLeft
(
find
.
byKey
(
ValueKey
<
int
>(
index
))),
Offset
(
592
,
134.0
+
index
*
10
));
}
await
tester
.
pumpWidget
(
buildFrame
(
TextDirection
.
rtl
));
for
(
int
index
=
0
;
index
<
actionCount
;
index
+=
1
)
{
expect
(
tester
.
getTopLeft
(
find
.
byKey
(
ValueKey
<
int
>(
index
))),
Offset
(
8
,
134.0
+
index
*
10
));
}
});
testWidgets
(
'[overflowAlignment] test'
,
(
WidgetTester
tester
)
async
{
const
int
actionCount
=
4
;
Widget
buildFrame
(
TextDirection
textDirection
,
OverflowBarAlignment
overflowAlignment
)
{
return
MaterialApp
(
home:
Directionality
(
textDirection:
textDirection
,
child:
MaterialBanner
(
overflowAlignment:
overflowAlignment
,
content:
const
SizedBox
(
width:
100
,
height:
100
),
actions:
List
<
Widget
>.
generate
(
actionCount
,
(
int
index
)
{
return
SizedBox
(
width:
200
,
height:
10
,
key:
ValueKey
<
int
>(
index
),
);
}),
),
),
);
}
await
tester
.
pumpWidget
(
buildFrame
(
TextDirection
.
ltr
,
OverflowBarAlignment
.
start
));
for
(
int
index
=
0
;
index
<
actionCount
;
index
+=
1
)
{
expect
(
tester
.
getTopLeft
(
find
.
byKey
(
ValueKey
<
int
>(
index
))),
Offset
(
8
,
134.0
+
index
*
10
));
}
await
tester
.
pumpWidget
(
buildFrame
(
TextDirection
.
ltr
,
OverflowBarAlignment
.
center
));
for
(
int
index
=
0
;
index
<
actionCount
;
index
+=
1
)
{
expect
(
tester
.
getTopLeft
(
find
.
byKey
(
ValueKey
<
int
>(
index
))),
Offset
(
300
,
134.0
+
index
*
10
));
}
await
tester
.
pumpWidget
(
buildFrame
(
TextDirection
.
ltr
,
OverflowBarAlignment
.
end
));
for
(
int
index
=
0
;
index
<
actionCount
;
index
+=
1
)
{
expect
(
tester
.
getTopLeft
(
find
.
byKey
(
ValueKey
<
int
>(
index
))),
Offset
(
592
,
134.0
+
index
*
10
));
}
...
...
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