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
91b5079f
Unverified
Commit
91b5079f
authored
Oct 07, 2022
by
Bruno Leroux
Committed by
GitHub
Oct 07, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix TabBar with padding is not centered (#113091)
parent
bd4376ca
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
57 additions
and
1 deletion
+57
-1
tabs.dart
packages/flutter/lib/src/material/tabs.dart
+5
-1
tabs_test.dart
packages/flutter/test/material/tabs_test.dart
+52
-0
No files found.
packages/flutter/lib/src/material/tabs.dart
View file @
91b5079f
...
...
@@ -1062,14 +1062,18 @@ class _TabBarState extends State<TabBar> {
return
0.0
;
}
double
tabCenter
=
_indicatorPainter
!.
centerOf
(
index
);
double
paddingStart
;
switch
(
Directionality
.
of
(
context
))
{
case
TextDirection
.
rtl
:
paddingStart
=
widget
.
padding
?.
resolve
(
TextDirection
.
rtl
).
right
??
0
;
tabCenter
=
_tabStripWidth
-
tabCenter
;
break
;
case
TextDirection
.
ltr
:
paddingStart
=
widget
.
padding
?.
resolve
(
TextDirection
.
ltr
).
left
??
0
;
break
;
}
return
clampDouble
(
tabCenter
-
viewportWidth
/
2.0
,
minExtent
,
maxExtent
);
return
clampDouble
(
tabCenter
+
paddingStart
-
viewportWidth
/
2.0
,
minExtent
,
maxExtent
);
}
double
_tabCenteredScrollOffset
(
int
index
)
{
...
...
packages/flutter/test/material/tabs_test.dart
View file @
91b5079f
...
...
@@ -110,8 +110,11 @@ Widget buildFrame({
bool
isScrollable
=
false
,
Color
?
indicatorColor
,
Duration
?
animationDuration
,
EdgeInsetsGeometry
?
padding
,
TextDirection
textDirection
=
TextDirection
.
ltr
,
})
{
return
boilerplate
(
textDirection:
textDirection
,
child:
DefaultTabController
(
animationDuration:
animationDuration
,
initialIndex:
tabs
.
indexOf
(
value
),
...
...
@@ -121,6 +124,7 @@ Widget buildFrame({
tabs:
tabs
.
map
<
Widget
>((
String
tab
)
=>
Tab
(
text:
tab
)).
toList
(),
isScrollable:
isScrollable
,
indicatorColor:
indicatorColor
,
padding:
padding
,
),
),
);
...
...
@@ -432,6 +436,54 @@ void main() {
expect
(
tester
.
getCenter
(
find
.
text
(
'FFFFFF'
)).
dx
,
moreOrLessEquals
(
400.0
,
epsilon:
1.0
));
});
testWidgets
(
'Scrollable TabBar, with padding, tap centers selected tab'
,
(
WidgetTester
tester
)
async
{
// Regression test for https://github.com/flutter/flutter/issues/112776
final
List
<
String
>
tabs
=
<
String
>[
'AAAAAA'
,
'BBBBBB'
,
'CCCCCC'
,
'DDDDDD'
,
'EEEEEE'
,
'FFFFFF'
,
'GGGGGG'
,
'HHHHHH'
,
'IIIIII'
,
'JJJJJJ'
,
'KKKKKK'
,
'LLLLLL'
];
const
Key
tabBarKey
=
Key
(
'TabBar'
);
const
EdgeInsetsGeometry
padding
=
EdgeInsets
.
only
(
right:
30
,
left:
60
);
await
tester
.
pumpWidget
(
buildFrame
(
tabs:
tabs
,
value:
'AAAAAA'
,
isScrollable:
true
,
tabBarKey:
tabBarKey
,
padding:
padding
));
final
TabController
controller
=
DefaultTabController
.
of
(
tester
.
element
(
find
.
text
(
'AAAAAA'
)))!;
expect
(
controller
,
isNotNull
);
expect
(
controller
.
index
,
0
);
expect
(
tester
.
getSize
(
find
.
byKey
(
tabBarKey
)).
width
,
equals
(
800.0
));
// The center of the FFFFFF item is to the right of the TabBar's center
expect
(
tester
.
getCenter
(
find
.
text
(
'FFFFFF'
)).
dx
,
greaterThan
(
401.0
));
await
tester
.
tap
(
find
.
text
(
'FFFFFF'
));
await
tester
.
pumpAndSettle
();
expect
(
controller
.
index
,
5
);
// The center of the FFFFFF item is now at the TabBar's center
expect
(
tester
.
getCenter
(
find
.
text
(
'FFFFFF'
)).
dx
,
moreOrLessEquals
(
400.0
,
epsilon:
1.0
));
});
testWidgets
(
'Scrollable TabBar, with padding and TextDirection.rtl, tap centers selected tab'
,
(
WidgetTester
tester
)
async
{
// Regression test for https://github.com/flutter/flutter/issues/112776
final
List
<
String
>
tabs
=
<
String
>[
'AAAAAA'
,
'BBBBBB'
,
'CCCCCC'
,
'DDDDDD'
,
'EEEEEE'
,
'FFFFFF'
,
'GGGGGG'
,
'HHHHHH'
,
'IIIIII'
,
'JJJJJJ'
,
'KKKKKK'
,
'LLLLLL'
];
const
Key
tabBarKey
=
Key
(
'TabBar'
);
const
EdgeInsetsGeometry
padding
=
EdgeInsets
.
only
(
right:
30
,
left:
60
);
await
tester
.
pumpWidget
(
buildFrame
(
tabs:
tabs
,
value:
'AAAAAA'
,
isScrollable:
true
,
tabBarKey:
tabBarKey
,
padding:
padding
,
textDirection:
TextDirection
.
rtl
,
));
final
TabController
controller
=
DefaultTabController
.
of
(
tester
.
element
(
find
.
text
(
'AAAAAA'
)))!;
expect
(
controller
,
isNotNull
);
expect
(
controller
.
index
,
0
);
expect
(
tester
.
getSize
(
find
.
byKey
(
tabBarKey
)).
width
,
equals
(
800.0
));
// The center of the FFFFFF item is to the left of the TabBar's center
expect
(
tester
.
getCenter
(
find
.
text
(
'FFFFFF'
)).
dx
,
lessThan
(
401.0
));
await
tester
.
tap
(
find
.
text
(
'FFFFFF'
));
await
tester
.
pumpAndSettle
();
expect
(
controller
.
index
,
5
);
// The center of the FFFFFF item is now at the TabBar's center
expect
(
tester
.
getCenter
(
find
.
text
(
'FFFFFF'
)).
dx
,
moreOrLessEquals
(
400.0
,
epsilon:
1.0
));
});
testWidgets
(
'TabBar can be scrolled independent of the selection'
,
(
WidgetTester
tester
)
async
{
final
List
<
String
>
tabs
=
<
String
>[
'AAAA'
,
'BBBB'
,
'CCCC'
,
'DDDD'
,
'EEEE'
,
'FFFF'
,
'GGGG'
,
'HHHH'
,
'IIII'
,
'JJJJ'
,
'KKKK'
,
'LLLL'
];
...
...
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