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
5a00d54e
Unverified
Commit
5a00d54e
authored
Jul 09, 2020
by
Ayush Bherwani
Committed by
GitHub
Jul 09, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[AppBar] adds leadingWidth property to customize width of leading widget (#60915)
parent
93eac884
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
54 additions
and
3 deletions
+54
-3
app_bar.dart
packages/flutter/lib/src/material/app_bar.dart
+20
-3
app_bar_test.dart
packages/flutter/test/material/app_bar_test.dart
+34
-0
No files found.
packages/flutter/lib/src/material/app_bar.dart
View file @
5a00d54e
...
...
@@ -208,6 +208,7 @@ class AppBar extends StatefulWidget implements PreferredSizeWidget {
this
.
toolbarOpacity
=
1.0
,
this
.
bottomOpacity
=
1.0
,
this
.
toolbarHeight
,
this
.
leadingWidth
,
})
:
assert
(
automaticallyImplyLeading
!=
null
),
assert
(
elevation
==
null
||
elevation
>=
0.0
),
assert
(
primary
!=
null
),
...
...
@@ -223,7 +224,7 @@ class AppBar extends StatefulWidget implements PreferredSizeWidget {
///
/// Becomes the leading component of the [NavigationToolBar] built
/// by this widget. The [leading] widget's width and height are constrained to
/// be no bigger than [
kToolbarHeight
] and [toolbarHeight] respectively.
/// be no bigger than [
leadingWidth
] and [toolbarHeight] respectively.
///
/// If this is null and [automaticallyImplyLeading] is set to true, the
/// [AppBar] will imply an appropriate widget. For example, if the [AppBar] is
...
...
@@ -450,6 +451,11 @@ class AppBar extends StatefulWidget implements PreferredSizeWidget {
/// By default, the value of `toolbarHeight` is [kToolbarHeight].
final
double
toolbarHeight
;
/// Defines the width of [leading] widget.
///
/// By default, the value of `leadingWidth` is 56.0.
final
double
leadingWidth
;
bool
_getEffectiveCenterTitle
(
ThemeData
theme
)
{
if
(
centerTitle
!=
null
)
return
centerTitle
;
...
...
@@ -543,7 +549,7 @@ class _AppBarState extends State<AppBar> {
}
if
(
leading
!=
null
)
{
leading
=
ConstrainedBox
(
constraints:
const
BoxConstraints
.
tightFor
(
width:
_kLeadingWidth
),
constraints:
BoxConstraints
.
tightFor
(
width:
widget
.
leadingWidth
??
_kLeadingWidth
),
child:
leading
,
);
}
...
...
@@ -803,6 +809,7 @@ class _SliverAppBarDelegate extends SliverPersistentHeaderDelegate {
@required
this
.
stretchConfiguration
,
@required
this
.
shape
,
@required
this
.
toolbarHeight
,
@required
this
.
leadingWidth
,
})
:
assert
(
primary
||
topPadding
==
0.0
),
_bottomHeight
=
bottom
?.
preferredSize
?.
height
??
0.0
;
...
...
@@ -831,6 +838,7 @@ class _SliverAppBarDelegate extends SliverPersistentHeaderDelegate {
final
bool
pinned
;
final
ShapeBorder
shape
;
final
double
toolbarHeight
;
final
double
leadingWidth
;
final
double
_bottomHeight
;
...
...
@@ -886,6 +894,7 @@ class _SliverAppBarDelegate extends SliverPersistentHeaderDelegate {
toolbarOpacity:
toolbarOpacity
,
bottomOpacity:
pinned
?
1.0
:
((
visibleMainHeight
/
_bottomHeight
).
clamp
(
0.0
,
1.0
)
as
double
),
toolbarHeight:
toolbarHeight
,
leadingWidth:
leadingWidth
,
),
);
return
floating
?
_FloatingAppBar
(
child:
appBar
)
:
appBar
;
...
...
@@ -917,7 +926,8 @@ class _SliverAppBarDelegate extends SliverPersistentHeaderDelegate {
||
snapConfiguration
!=
oldDelegate
.
snapConfiguration
||
stretchConfiguration
!=
oldDelegate
.
stretchConfiguration
||
forceElevated
!=
oldDelegate
.
forceElevated
||
toolbarHeight
!=
oldDelegate
.
toolbarHeight
;
||
toolbarHeight
!=
oldDelegate
.
toolbarHeight
||
leadingWidth
!=
leadingWidth
;
}
@override
...
...
@@ -1039,6 +1049,7 @@ class SliverAppBar extends StatefulWidget {
this
.
onStretchTrigger
,
this
.
shape
,
this
.
toolbarHeight
=
kToolbarHeight
,
this
.
leadingWidth
,
})
:
assert
(
automaticallyImplyLeading
!=
null
),
assert
(
forceElevated
!=
null
),
assert
(
primary
!=
null
),
...
...
@@ -1337,6 +1348,11 @@ class SliverAppBar extends StatefulWidget {
/// By default, the value of `toolbarHeight` is [kToolbarHeight].
final
double
toolbarHeight
;
/// Defines the width of [leading] widget.
///
/// By default, the value of `leadingWidth` is 56.0.
final
double
leadingWidth
;
@override
_SliverAppBarState
createState
()
=>
_SliverAppBarState
();
}
...
...
@@ -1429,6 +1445,7 @@ class _SliverAppBarState extends State<SliverAppBar> with TickerProviderStateMix
snapConfiguration:
_snapConfiguration
,
stretchConfiguration:
_stretchConfiguration
,
toolbarHeight:
widget
.
toolbarHeight
,
leadingWidth:
widget
.
leadingWidth
,
),
),
);
...
...
packages/flutter/test/material/app_bar_test.dart
View file @
5a00d54e
...
...
@@ -2045,4 +2045,38 @@ void main() {
expect
(
error
.
toString
(),
contains
(
'is not true'
));
}
});
testWidgets
(
'AppBar respects leadingWidth'
,
(
WidgetTester
tester
)
async
{
const
Key
key
=
Key
(
'leading'
);
await
tester
.
pumpWidget
(
MaterialApp
(
home:
Scaffold
(
appBar:
AppBar
(
leading:
const
Placeholder
(
key:
key
),
leadingWidth:
100
,
title:
const
Text
(
'Title'
),
),
),
));
// By default toolbarHeight is 56.0.
expect
(
tester
.
getRect
(
find
.
byKey
(
key
)),
const
Rect
.
fromLTRB
(
0
,
0
,
100
,
56
));
});
testWidgets
(
'SliverAppBar respects leadingWidth'
,
(
WidgetTester
tester
)
async
{
const
Key
key
=
Key
(
'leading'
);
await
tester
.
pumpWidget
(
const
MaterialApp
(
home:
CustomScrollView
(
slivers:
<
Widget
>[
SliverAppBar
(
leading:
Placeholder
(
key:
key
),
leadingWidth:
100
,
title:
Text
(
'Title'
),
),
],
)
));
// By default toolbarHeight is 56.0.
expect
(
tester
.
getRect
(
find
.
byKey
(
key
)),
const
Rect
.
fromLTRB
(
0
,
0
,
100
,
56
));
});
}
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