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
3df0f931
Unverified
Commit
3df0f931
authored
Apr 27, 2021
by
Hans Muller
Committed by
GitHub
Apr 27, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Support notched BottomAppbar when Scaffold.bottomNavigationBar == null (#81228)
parent
3533321b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
51 additions
and
8 deletions
+51
-8
bottom_app_bar.dart
packages/flutter/lib/src/material/bottom_app_bar.dart
+17
-8
bottom_app_bar_test.dart
packages/flutter/test/material/bottom_app_bar_test.dart
+34
-0
No files found.
packages/flutter/lib/src/material/bottom_app_bar.dart
View file @
3df0f931
...
...
@@ -3,6 +3,7 @@
// found in the LICENSE file.
import
'package:flutter/foundation.dart'
;
import
'package:flutter/rendering.dart'
;
import
'package:flutter/widgets.dart'
;
import
'bottom_app_bar_theme.dart'
;
...
...
@@ -271,6 +272,7 @@ class BottomAppBar extends StatefulWidget {
class
_BottomAppBarState
extends
State
<
BottomAppBar
>
{
late
ValueListenable
<
ScaffoldGeometry
>
geometryListenable
;
final
GlobalKey
materialKey
=
GlobalKey
();
static
const
double
_defaultElevation
=
8.0
;
@override
...
...
@@ -285,10 +287,11 @@ class _BottomAppBarState extends State<BottomAppBar> {
final
NotchedShape
?
notchedShape
=
widget
.
shape
??
babTheme
.
shape
;
final
CustomClipper
<
Path
>
clipper
=
notchedShape
!=
null
?
_BottomAppBarClipper
(
geometry:
geometryListenable
,
shape:
notchedShape
,
notchMargin:
widget
.
notchMargin
,
)
geometry:
geometryListenable
,
shape:
notchedShape
,
materialKey:
materialKey
,
notchMargin:
widget
.
notchMargin
,
)
:
const
ShapeBorderClipper
(
shape:
RoundedRectangleBorder
());
final
double
elevation
=
widget
.
elevation
??
babTheme
.
elevation
??
_defaultElevation
;
final
Color
color
=
widget
.
color
??
babTheme
.
color
??
Theme
.
of
(
context
).
bottomAppBarColor
;
...
...
@@ -299,6 +302,7 @@ class _BottomAppBarState extends State<BottomAppBar> {
color:
effectiveColor
,
clipBehavior:
widget
.
clipBehavior
,
child:
Material
(
key:
materialKey
,
type:
MaterialType
.
transparency
,
child:
widget
.
child
==
null
?
null
...
...
@@ -312,6 +316,7 @@ class _BottomAppBarClipper extends CustomClipper<Path> {
const
_BottomAppBarClipper
({
required
this
.
geometry
,
required
this
.
shape
,
required
this
.
materialKey
,
required
this
.
notchMargin
,
})
:
assert
(
geometry
!=
null
),
assert
(
shape
!=
null
),
...
...
@@ -320,17 +325,21 @@ class _BottomAppBarClipper extends CustomClipper<Path> {
final
ValueListenable
<
ScaffoldGeometry
>
geometry
;
final
NotchedShape
shape
;
final
GlobalKey
materialKey
;
final
double
notchMargin
;
// Returns the top of the BottomAppBar in global coordinates.
double
get
bottomNavigationBarTop
{
final
RenderBox
?
box
=
materialKey
.
currentContext
?.
findRenderObject
()
as
RenderBox
?;
return
box
?.
localToGlobal
(
Offset
.
zero
).
dy
??
0
;
}
@override
Path
getClip
(
Size
size
)
{
// button is the floating action button's bounding rectangle in the
// coordinate system whose origin is at the appBar's top left corner,
// or null if there is no floating action button.
final
Rect
?
button
=
geometry
.
value
.
floatingActionButtonArea
?.
translate
(
0.0
,
geometry
.
value
.
bottomNavigationBarTop
!
*
-
1.0
,
);
final
Rect
?
button
=
geometry
.
value
.
floatingActionButtonArea
?.
translate
(
0.0
,
bottomNavigationBarTop
*
-
1.0
);
return
shape
.
getOuterPath
(
Offset
.
zero
&
size
,
button
?.
inflate
(
notchMargin
));
}
...
...
packages/flutter/test/material/bottom_app_bar_test.dart
View file @
3df0f931
...
...
@@ -381,6 +381,40 @@ void main() {
physicalShape
=
tester
.
widget
(
find
.
byType
(
PhysicalShape
));
expect
(
physicalShape
.
clipBehavior
,
Clip
.
antiAliasWithSaveLayer
);
});
testWidgets
(
'BottomAppBar with shape when Scaffold.bottomNavigationBar == null'
,
(
WidgetTester
tester
)
async
{
// Regression test for https://github.com/flutter/flutter/issues/80878
await
tester
.
pumpWidget
(
MaterialApp
(
home:
Scaffold
(
floatingActionButtonLocation:
FloatingActionButtonLocation
.
centerFloat
,
floatingActionButton:
FloatingActionButton
(
backgroundColor:
Colors
.
green
,
child:
const
Icon
(
Icons
.
home
),
onPressed:
()
{},
),
body:
Stack
(
children:
<
Widget
>[
Container
(
color:
Colors
.
amber
,
),
Container
(
alignment:
Alignment
.
bottomCenter
,
child:
BottomAppBar
(
color:
Colors
.
green
,
shape:
const
CircularNotchedRectangle
(),
child:
Container
(
height:
50
),
),
),
],
),
),
),
);
expect
(
tester
.
getRect
(
find
.
byType
(
FloatingActionButton
)),
const
Rect
.
fromLTRB
(
372
,
528
,
428
,
584
));
expect
(
tester
.
getSize
(
find
.
byType
(
BottomAppBar
)),
const
Size
(
800
,
50
));
});
}
// The bottom app bar clip path computation is only available at paint time.
...
...
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