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
321aa452
Unverified
Commit
321aa452
authored
Apr 23, 2021
by
Chinmoy
Committed by
GitHub
Apr 23, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Modified TabBar.preferredSize to remove hardcoded (#80792)
parent
59fc9216
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
91 additions
and
6 deletions
+91
-6
tabs.dart
packages/flutter/lib/src/material/tabs.dart
+15
-6
tabs_test.dart
packages/flutter/test/material/tabs_test.dart
+76
-0
No files found.
packages/flutter/lib/src/material/tabs.dart
View file @
321aa452
...
...
@@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import
'dart:math'
as
math
;
import
'dart:ui'
show
lerpDouble
;
import
'package:flutter/foundation.dart'
;
...
...
@@ -57,7 +58,7 @@ enum TabBarIndicatorSize {
/// * [TabBarView], which displays a widget for the currently selected tab.
/// * [TabController], which coordinates tab selection between a [TabBar] and a [TabBarView].
/// * <https://material.io/design/components/tabs.html>
class
Tab
extends
StatelessWidget
{
class
Tab
extends
StatelessWidget
implements
PreferredSizeWidget
{
/// Creates a material design [TabBar] tab.
///
/// At least one of [text], [icon], and [child] must be non-null. The [text]
...
...
@@ -141,6 +142,14 @@ class Tab extends StatelessWidget {
properties
.
add
(
StringProperty
(
'text'
,
text
,
defaultValue:
null
));
properties
.
add
(
DiagnosticsProperty
<
Widget
>(
'icon'
,
icon
,
defaultValue:
null
));
}
@override
Size
get
preferredSize
{
if
((
text
!=
null
||
child
!=
null
)
&&
icon
!=
null
)
return
const
Size
.
fromHeight
(
_kTextAndIconTabHeight
);
else
return
const
Size
.
fromHeight
(
_kTabHeight
);
}
}
class
_TabStyle
extends
AnimatedWidget
{
...
...
@@ -891,14 +900,14 @@ class TabBar extends StatefulWidget implements PreferredSizeWidget {
/// [AppBar] uses this size to compute its own preferred size.
@override
Size
get
preferredSize
{
double
maxHeight
=
_kTabHeight
;
for
(
final
Widget
item
in
tabs
)
{
if
(
item
is
Tab
)
{
final
Tab
tab
=
item
;
if
((
tab
.
text
!=
null
||
tab
.
child
!=
null
)
&&
tab
.
icon
!=
null
)
return
Size
.
fromHeight
(
_kTextAndIconTabHeight
+
indicatorWeight
);
if
(
item
is
PreferredSizeWidget
)
{
final
double
itemHeight
=
item
.
preferredSize
.
height
;
maxHeight
=
math
.
max
(
itemHeight
,
maxHeight
);
}
}
return
Size
.
fromHeight
(
_kTab
Height
+
indicatorWeight
);
return
Size
.
fromHeight
(
max
Height
+
indicatorWeight
);
}
@override
...
...
packages/flutter/test/material/tabs_test.dart
View file @
321aa452
...
...
@@ -3457,6 +3457,82 @@ void main() {
expect
(
controller
.
index
,
1
);
expect
(
controller
.
animation
!.
value
,
1
);
});
testWidgets
(
'Tab preferredSize gives correct value'
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
MaterialApp
(
home:
Material
(
child:
Row
(
children:
const
<
Tab
>[
Tab
(
icon:
Icon
(
Icons
.
message
)),
Tab
(
text:
'Two'
),
Tab
(
text:
'Three'
,
icon:
Icon
(
Icons
.
chat
)),
],
),
),
),
);
final
Tab
firstTab
=
tester
.
widget
(
find
.
widgetWithIcon
(
Tab
,
Icons
.
message
));
final
Tab
secondTab
=
tester
.
widget
(
find
.
widgetWithText
(
Tab
,
'Two'
));
final
Tab
thirdTab
=
tester
.
widget
(
find
.
widgetWithText
(
Tab
,
'Three'
));
expect
(
firstTab
.
preferredSize
,
const
Size
.
fromHeight
(
46.0
));
expect
(
secondTab
.
preferredSize
,
const
Size
.
fromHeight
(
46.0
));
expect
(
thirdTab
.
preferredSize
,
const
Size
.
fromHeight
(
72.0
));
});
testWidgets
(
'TabBar preferredSize gives correct value when there are both icon and text in tabs'
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
MaterialApp
(
home:
DefaultTabController
(
length:
5
,
child:
Scaffold
(
appBar:
AppBar
(
bottom:
const
TabBar
(
tabs:
<
Widget
>[
Tab
(
text:
'car'
),
Tab
(
text:
'transit'
),
Tab
(
text:
'bike'
),
Tab
(
text:
'boat'
,
icon:
Icon
(
Icons
.
message
)),
Tab
(
text:
'bus'
),
],
),
title:
const
Text
(
'Tabs Test'
),
),
),
),
));
final
TabBar
tabBar
=
tester
.
widget
(
find
.
widgetWithText
(
TabBar
,
'car'
));
expect
(
tabBar
.
preferredSize
,
const
Size
.
fromHeight
(
74.0
));
});
testWidgets
(
'TabBar preferredSize gives correct value when there is only icon or text in tabs'
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
MaterialApp
(
home:
DefaultTabController
(
length:
5
,
child:
Scaffold
(
appBar:
AppBar
(
bottom:
const
TabBar
(
tabs:
<
Widget
>[
Tab
(
text:
'car'
),
Tab
(
icon:
Icon
(
Icons
.
message
)),
Tab
(
text:
'bike'
),
Tab
(
icon:
Icon
(
Icons
.
chat
)),
Tab
(
text:
'bus'
),
],
),
title:
const
Text
(
'Tabs Test'
),
),
),
),
));
final
TabBar
tabBar
=
tester
.
widget
(
find
.
widgetWithText
(
TabBar
,
'car'
));
expect
(
tabBar
.
preferredSize
,
const
Size
.
fromHeight
(
48.0
));
});
}
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