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
511020ac
Unverified
Commit
511020ac
authored
Jan 07, 2022
by
Viren Khatri
Committed by
GitHub
Jan 07, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixes `RangeError` bug when length of `TabBar.tabs` is changed (#94623)
parent
2a529bc5
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
85 additions
and
19 deletions
+85
-19
tabs.dart
packages/flutter/lib/src/material/tabs.dart
+4
-4
tabs_test.dart
packages/flutter/test/material/tabs_test.dart
+81
-15
No files found.
packages/flutter/lib/src/material/tabs.dart
View file @
511020ac
...
@@ -982,11 +982,11 @@ class _TabBarState extends State<TabBar> {
...
@@ -982,11 +982,11 @@ class _TabBarState extends State<TabBar> {
_initIndicatorPainter
();
_initIndicatorPainter
();
}
}
if
(
widget
.
tabs
.
length
>
oldWidget
.
tab
s
.
length
)
{
if
(
widget
.
tabs
.
length
>
_tabKey
s
.
length
)
{
final
int
delta
=
widget
.
tabs
.
length
-
oldWidget
.
tab
s
.
length
;
final
int
delta
=
widget
.
tabs
.
length
-
_tabKey
s
.
length
;
_tabKeys
.
addAll
(
List
<
GlobalKey
>.
generate
(
delta
,
(
int
n
)
=>
GlobalKey
()));
_tabKeys
.
addAll
(
List
<
GlobalKey
>.
generate
(
delta
,
(
int
n
)
=>
GlobalKey
()));
}
else
if
(
widget
.
tabs
.
length
<
oldWidget
.
tab
s
.
length
)
{
}
else
if
(
widget
.
tabs
.
length
<
_tabKey
s
.
length
)
{
_tabKeys
.
removeRange
(
widget
.
tabs
.
length
,
oldWidget
.
tab
s
.
length
);
_tabKeys
.
removeRange
(
widget
.
tabs
.
length
,
_tabKey
s
.
length
);
}
}
}
}
...
...
packages/flutter/test/material/tabs_test.dart
View file @
511020ac
...
@@ -3136,6 +3136,7 @@ void main() {
...
@@ -3136,6 +3136,7 @@ void main() {
},
},
);
);
});
});
testWidgets
(
'Skipping tabs with global key does not crash'
,
(
WidgetTester
tester
)
async
{
testWidgets
(
'Skipping tabs with global key does not crash'
,
(
WidgetTester
tester
)
async
{
// Regression test for https://github.com/flutter/flutter/issues/24660
// Regression test for https://github.com/flutter/flutter/issues/24660
final
List
<
String
>
tabs
=
<
String
>[
final
List
<
String
>
tabs
=
<
String
>[
...
@@ -3433,9 +3434,9 @@ void main() {
...
@@ -3433,9 +3434,9 @@ void main() {
title:
const
Text
(
'Default TabBar Preview'
),
title:
const
Text
(
'Default TabBar Preview'
),
bottom:
tabTextContent
.
isNotEmpty
bottom:
tabTextContent
.
isNotEmpty
?
TabBar
(
?
TabBar
(
isScrollable:
true
,
isScrollable:
true
,
tabs:
tabTextContent
.
map
((
String
textContent
)
=>
Tab
(
text:
textContent
)).
toList
(),
tabs:
tabTextContent
.
map
((
String
textContent
)
=>
Tab
(
text:
textContent
)).
toList
(),
)
)
:
null
,
:
null
,
),
),
body:
tabTextContent
.
isNotEmpty
body:
tabTextContent
.
isNotEmpty
...
@@ -3490,31 +3491,96 @@ void main() {
...
@@ -3490,31 +3491,96 @@ void main() {
expect
(
find
.
text
(
'No tabs'
),
findsOneWidget
);
expect
(
find
.
text
(
'No tabs'
),
findsOneWidget
);
});
});
testWidgets
(
'DefaultTabController should allow dynamic length of tabs'
,
(
WidgetTester
tester
)
async
{
// Regression test for https://github.com/flutter/flutter/issues/94504.
final
List
<
String
>
tabTitles
=
<
String
>[];
void
_onTabAdd
(
StateSetter
setState
)
{
setState
(()
{
tabTitles
.
add
(
'Tab
${tabTitles.length + 1}
'
);
});
}
void
_onTabRemove
(
StateSetter
setState
)
{
setState
(()
{
tabTitles
.
removeLast
();
});
}
await
tester
.
pumpWidget
(
MaterialApp
(
home:
StatefulBuilder
(
builder:
(
BuildContext
context
,
StateSetter
setState
)
{
return
DefaultTabController
(
length:
tabTitles
.
length
,
child:
Scaffold
(
appBar:
AppBar
(
actions:
<
Widget
>[
TextButton
(
key:
const
Key
(
'Add tab'
),
child:
const
Text
(
'Add tab'
),
onPressed:
()
=>
_onTabAdd
(
setState
),
),
TextButton
(
key:
const
Key
(
'Remove tab'
),
child:
const
Text
(
'Remove tab'
),
onPressed:
()
=>
_onTabRemove
(
setState
),
),
],
bottom:
PreferredSize
(
preferredSize:
const
Size
.
fromHeight
(
40.0
),
child:
Expanded
(
child:
TabBar
(
tabs:
tabTitles
.
map
((
String
title
)
=>
Tab
(
text:
title
))
.
toList
(),
),
),
),
),
),
);
},
),
),
);
expect
(
find
.
text
(
'Tab 1'
),
findsNothing
);
expect
(
find
.
text
(
'Tab 2'
),
findsNothing
);
await
tester
.
tap
(
find
.
byKey
(
const
Key
(
'Add tab'
)));
// +1
await
tester
.
pumpAndSettle
();
expect
(
find
.
text
(
'Tab 1'
),
findsOneWidget
);
expect
(
find
.
text
(
'Tab 2'
),
findsNothing
);
await
tester
.
tap
(
find
.
byKey
(
const
Key
(
'Add tab'
)));
// +2
await
tester
.
pumpAndSettle
();
expect
(
find
.
text
(
'Tab 1'
),
findsOneWidget
);
expect
(
find
.
text
(
'Tab 2'
),
findsOneWidget
);
await
tester
.
tap
(
find
.
byKey
(
const
Key
(
'Remove tab'
)));
// -2
await
tester
.
tap
(
find
.
byKey
(
const
Key
(
'Remove tab'
)));
// -1
await
tester
.
pumpAndSettle
();
expect
(
find
.
text
(
'Tab 1'
),
findsNothing
);
expect
(
find
.
text
(
'Tab 2'
),
findsNothing
);
});
testWidgets
(
'TabBar - updating to and from zero tabs'
,
(
WidgetTester
tester
)
async
{
testWidgets
(
'TabBar - updating to and from zero tabs'
,
(
WidgetTester
tester
)
async
{
// Regression test for https://github.com/flutter/flutter/issues/68962.
// Regression test for https://github.com/flutter/flutter/issues/68962.
final
List
<
String
>
tabTitles
=
<
String
>[];
final
List
<
String
>
tabTitles
=
<
String
>[];
final
List
<
Widget
>
tabContents
=
<
Widget
>[];
TabController
_tabController
=
TabController
(
length:
tabTitles
.
length
,
vsync:
const
TestVSync
());
TabController
_tabController
=
TabController
(
length:
tabContents
.
length
,
vsync:
const
TestVSync
());
void
_onTabAdd
(
StateSetter
setState
)
{
void
_onTabAdd
(
StateSetter
setState
)
{
setState
(()
{
setState
(()
{
tabTitles
.
add
(
'Tab
${tabTitles.length + 1}
'
);
tabTitles
.
add
(
'Tab
${tabTitles.length + 1}
'
);
tabContents
.
add
(
_tabController
=
TabController
(
length:
tabTitles
.
length
,
vsync:
const
TestVSync
());
Container
(
color:
Colors
.
red
,
height:
200
,
width:
200
,
),
);
_tabController
=
TabController
(
length:
tabContents
.
length
,
vsync:
const
TestVSync
());
});
});
}
}
void
_onTabRemove
(
StateSetter
setState
)
{
void
_onTabRemove
(
StateSetter
setState
)
{
setState
(()
{
setState
(()
{
tabTitles
.
removeLast
();
tabTitles
.
removeLast
();
tabContents
.
removeLast
();
_tabController
=
TabController
(
length:
tabTitles
.
length
,
vsync:
const
TestVSync
());
_tabController
=
TabController
(
length:
tabContents
.
length
,
vsync:
const
TestVSync
());
});
});
}
}
...
...
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