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
27a12efa
Unverified
Commit
27a12efa
authored
Oct 02, 2019
by
Shi-Hao Hong
Committed by
GitHub
Oct 02, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update DefaultTabController to allow for zero tabs (#41625)
* Update DefaultTabController to allow for zero tabs
parent
913aca22
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
74 additions
and
1 deletion
+74
-1
tab_controller.dart
packages/flutter/lib/src/material/tab_controller.dart
+1
-1
tabs_test.dart
packages/flutter/test/material/tabs_test.dart
+73
-0
No files found.
packages/flutter/lib/src/material/tab_controller.dart
View file @
27a12efa
...
...
@@ -313,7 +313,7 @@ class DefaultTabController extends StatefulWidget {
@required
this
.
child
,
})
:
assert
(
initialIndex
!=
null
),
assert
(
length
>=
0
),
assert
(
initialIndex
>=
0
&&
initialIndex
<
length
),
assert
(
length
==
0
||
(
initialIndex
>=
0
&&
initialIndex
<
length
)
),
super
(
key:
key
);
/// The total number of tabs.
...
...
packages/flutter/test/material/tabs_test.dart
View file @
27a12efa
...
...
@@ -2350,4 +2350,77 @@ void main() {
expect
(
find
.
text
(
'Tab1'
),
findsOneWidget
);
expect
(
find
.
text
(
'Tab2'
),
findsOneWidget
);
});
testWidgets
(
'DefaultTabController should allow for a length of zero'
,
(
WidgetTester
tester
)
async
{
// Regression test for https://github.com/flutter/flutter/issues/20292.
List
<
String
>
tabTextContent
=
<
String
>[];
await
tester
.
pumpWidget
(
MaterialApp
(
home:
StatefulBuilder
(
builder:
(
BuildContext
context
,
StateSetter
setState
)
{
return
DefaultTabController
(
length:
tabTextContent
.
length
,
child:
Scaffold
(
appBar:
AppBar
(
title:
const
Text
(
'Default TabBar Preview'
),
bottom:
tabTextContent
.
isNotEmpty
?
TabBar
(
isScrollable:
true
,
tabs:
tabTextContent
.
map
((
String
textContent
)
=>
Tab
(
text:
textContent
)).
toList
(),
)
:
null
,
),
body:
tabTextContent
.
isNotEmpty
?
TabBarView
(
children:
tabTextContent
.
map
((
String
textContent
)
=>
Tab
(
text:
'
$textContent
\'
s view'
)).
toList
()
)
:
const
Center
(
child:
Text
(
'No tabs'
)),
bottomNavigationBar:
BottomAppBar
(
child:
Row
(
mainAxisSize:
MainAxisSize
.
max
,
mainAxisAlignment:
MainAxisAlignment
.
spaceBetween
,
children:
<
Widget
>[
IconButton
(
key:
const
Key
(
'Add tab'
),
icon:
const
Icon
(
Icons
.
add
),
onPressed:
()
{
setState
(()
{
tabTextContent
=
List
<
String
>.
from
(
tabTextContent
)
..
add
(
'Tab
${tabTextContent.length + 1}
'
);
});
},
),
IconButton
(
key:
const
Key
(
'Delete tab'
),
icon:
const
Icon
(
Icons
.
delete
),
onPressed:
()
{
setState
(()
{
tabTextContent
=
List
<
String
>.
from
(
tabTextContent
)
..
removeLast
();
});
},
),
],
),
),
),
);
},
),
),
);
// Initializes with zero tabs properly
expect
(
find
.
text
(
'No tabs'
),
findsOneWidget
);
await
tester
.
tap
(
find
.
byKey
(
const
Key
(
'Add tab'
)));
await
tester
.
pumpAndSettle
();
expect
(
find
.
text
(
'Tab 1'
),
findsOneWidget
);
expect
(
find
.
text
(
'Tab 1
\'
s view'
),
findsOneWidget
);
// Dynamically updates to zero tabs properly
await
tester
.
tap
(
find
.
byKey
(
const
Key
(
'Delete tab'
)));
await
tester
.
pumpAndSettle
();
expect
(
find
.
text
(
'No tabs'
),
findsOneWidget
);
});
}
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