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
8f866ab5
Unverified
Commit
8f866ab5
authored
Jun 02, 2021
by
Gian
Committed by
GitHub
Jun 02, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix to the tab height (Issue #81500) (#81505)
parent
2bc12917
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
81 additions
and
6 deletions
+81
-6
tabs.dart
packages/flutter/lib/src/material/tabs.dart
+16
-6
tabs_test.dart
packages/flutter/test/material/tabs_test.dart
+65
-0
No files found.
packages/flutter/lib/src/material/tabs.dart
View file @
8f866ab5
...
...
@@ -70,6 +70,7 @@ class Tab extends StatelessWidget implements PreferredSizeWidget{
this
.
text
,
this
.
icon
,
this
.
iconMargin
=
const
EdgeInsets
.
only
(
bottom:
10.0
),
this
.
height
,
this
.
child
,
})
:
assert
(
text
!=
null
||
child
!=
null
||
icon
!=
null
),
assert
(
text
==
null
||
child
==
null
),
...
...
@@ -96,6 +97,13 @@ class Tab extends StatelessWidget implements PreferredSizeWidget{
/// [text] or [child] is non-null.
final
EdgeInsetsGeometry
iconMargin
;
/// The height of the [Tab].
///
/// If null, the height will be calculated based on the content of the [Tab]. When `icon` is not
/// null along with `child` or `text`, the default height is 72.0 pixels. Without an `icon`, the
/// height is 46.0 pixels.
final
double
?
height
;
Widget
_buildLabelText
()
{
return
child
??
Text
(
text
!,
softWrap:
false
,
overflow:
TextOverflow
.
fade
);
}
...
...
@@ -104,16 +112,16 @@ class Tab extends StatelessWidget implements PreferredSizeWidget{
Widget
build
(
BuildContext
context
)
{
assert
(
debugCheckHasMaterial
(
context
));
final
double
h
eight
;
final
double
calculatedH
eight
;
final
Widget
label
;
if
(
icon
==
null
)
{
h
eight
=
_kTabHeight
;
calculatedH
eight
=
_kTabHeight
;
label
=
_buildLabelText
();
}
else
if
(
text
==
null
&&
child
==
null
)
{
h
eight
=
_kTabHeight
;
calculatedH
eight
=
_kTabHeight
;
label
=
icon
!;
}
else
{
h
eight
=
_kTextAndIconTabHeight
;
calculatedH
eight
=
_kTextAndIconTabHeight
;
label
=
Column
(
mainAxisAlignment:
MainAxisAlignment
.
center
,
crossAxisAlignment:
CrossAxisAlignment
.
center
,
...
...
@@ -128,7 +136,7 @@ class Tab extends StatelessWidget implements PreferredSizeWidget{
}
return
SizedBox
(
height:
height
,
height:
height
??
calculatedHeight
,
child:
Center
(
widthFactor:
1.0
,
child:
label
,
...
...
@@ -145,7 +153,9 @@ class Tab extends StatelessWidget implements PreferredSizeWidget{
@override
Size
get
preferredSize
{
if
((
text
!=
null
||
child
!=
null
)
&&
icon
!=
null
)
if
(
height
!=
null
)
return
Size
.
fromHeight
(
height
!);
else
if
((
text
!=
null
||
child
!=
null
)
&&
icon
!=
null
)
return
const
Size
.
fromHeight
(
_kTextAndIconTabHeight
);
else
return
const
Size
.
fromHeight
(
_kTabHeight
);
...
...
packages/flutter/test/material/tabs_test.dart
View file @
8f866ab5
...
...
@@ -3747,6 +3747,71 @@ void main() {
expect
(
tabTwo
.
padding
,
expectedPaddingAdjusted
);
expect
(
tabThree
.
padding
,
expectedPaddingAdjusted
);
});
testWidgets
(
'Change tab bar height'
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
MaterialApp
(
home:
DefaultTabController
(
length:
4
,
child:
Scaffold
(
appBar:
AppBar
(
bottom:
const
TabBar
(
tabs:
<
Widget
>[
Tab
(
icon:
Icon
(
Icons
.
check
,
size:
40
),
child:
Text
(
'1 - OK'
,
style:
TextStyle
(
fontSize:
25
),),
height:
85
,
),
// icon and child
Tab
(
child:
Text
(
'2 - OK'
,
style:
TextStyle
(
fontSize:
25
),),
height:
85
,
),
// child
Tab
(
icon:
Icon
(
Icons
.
done
,
size:
40
),
height:
85
,
),
// icon
Tab
(
text:
'4 - OK'
,
height:
85
,
),
// text
],
),
),
),
),
));
final
Tab
firstTab
=
tester
.
widget
(
find
.
widgetWithIcon
(
Tab
,
Icons
.
check
));
final
Tab
secTab
=
tester
.
widget
(
find
.
widgetWithText
(
Tab
,
'2 - OK'
));
final
Tab
thirdTab
=
tester
.
widget
(
find
.
widgetWithIcon
(
Tab
,
Icons
.
done
));
final
Tab
fourthTab
=
tester
.
widget
(
find
.
widgetWithText
(
Tab
,
'4 - OK'
));
expect
(
firstTab
.
preferredSize
.
height
,
85
);
expect
(
firstTab
.
height
,
85
);
expect
(
secTab
.
height
,
85
);
expect
(
thirdTab
.
height
,
85
);
expect
(
fourthTab
.
height
,
85
);
});
testWidgets
(
'Change tab bar height 2'
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
MaterialApp
(
home:
DefaultTabController
(
length:
1
,
child:
Scaffold
(
appBar:
AppBar
(
bottom:
const
TabBar
(
tabs:
<
Widget
>[
Tab
(
icon:
Icon
(
Icons
.
check
,
size:
40
),
text:
'1 - OK'
,
height:
85
,
),
// icon and text
],
),
),
),
),
));
final
Tab
firstTab
=
tester
.
widget
(
find
.
widgetWithIcon
(
Tab
,
Icons
.
check
));
expect
(
firstTab
.
height
,
85
);
});
}
class
KeepAliveInk
extends
StatefulWidget
{
...
...
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