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
6494cd1f
Commit
6494cd1f
authored
Jan 05, 2016
by
Hans Muller
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make TabBarSelection a parameterized type
parent
81b70675
Changes
4
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
167 additions
and
124 deletions
+167
-124
tabs_demo.dart
examples/material_gallery/lib/demo/tabs_demo.dart
+5
-6
stock_home.dart
examples/stocks/lib/stock_home.dart
+7
-9
tabs.dart
packages/flutter/lib/src/material/tabs.dart
+115
-89
tabs_test.dart
packages/flutter/test/widget/tabs_test.dart
+40
-20
No files found.
examples/material_gallery/lib/demo/tabs_demo.dart
View file @
6494cd1f
...
...
@@ -9,16 +9,15 @@ import 'widget_demo.dart';
final
List
<
String
>
_iconNames
=
<
String
>[
"event"
,
"home"
,
"android"
,
"alarm"
,
"face"
,
"language"
];
Widget
_buildTabBarSelection
(
_
,
Widget
child
)
{
return
new
TabBarSelection
(
maxIndex:
_iconNames
.
length
-
1
,
child:
child
);
return
new
TabBarSelection
<
String
>(
values:
_iconNames
,
child:
child
);
}
Widget
_buildTabBar
(
_
)
{
return
new
TabBar
(
return
new
TabBar
<
String
>
(
isScrollable:
true
,
labels:
_iconNames
.
map
((
String
iconName
)
=>
new
TabLabel
(
text:
iconName
,
icon:
"action/
$iconName
"
)).
toList
()
labels:
new
Map
.
fromIterable
(
_iconNames
,
value:
(
String
iconName
)
=>
new
TabLabel
(
text:
iconName
,
icon:
"action/
$iconName
"
))
);
}
...
...
examples/stocks/lib/stock_home.dart
View file @
6494cd1f
...
...
@@ -161,17 +161,15 @@ class StockHomeState extends State<StockHome> {
onPressed:
_handleMenuShow
)
],
tabBar:
new
TabBar
(
labels:
<
TabLabel
>[
new
TabLabel
(
text:
StockStrings
.
of
(
context
).
market
()),
new
TabLabel
(
text:
StockStrings
.
of
(
context
).
portfolio
())
]
tabBar:
new
TabBar
<
StockHomeTab
>
(
labels:
<
StockHomeTab
,
TabLabel
>{
StockHomeTab
.
market
:
new
TabLabel
(
text:
StockStrings
.
of
(
context
).
market
()),
StockHomeTab
.
portfolio
:
new
TabLabel
(
text:
StockStrings
.
of
(
context
).
portfolio
())
}
)
);
}
int
selectedTabIndex
=
0
;
Iterable
<
Stock
>
_getStockList
(
Iterable
<
String
>
symbols
)
{
return
symbols
.
map
((
String
symbol
)
=>
config
.
stocks
[
symbol
])
.
where
((
Stock
stock
)
=>
stock
!=
null
);
...
...
@@ -266,8 +264,8 @@ class StockHomeState extends State<StockHome> {
}
Widget
build
(
BuildContext
context
)
{
return
new
TabBarSelection
(
maxIndex:
1
,
return
new
TabBarSelection
<
StockHomeTab
>
(
values:
<
StockHomeTab
>[
StockHomeTab
.
market
,
StockHomeTab
.
portfolio
]
,
child:
new
Scaffold
(
key:
_scaffoldKey
,
toolBar:
_isSearching
?
buildSearchBar
()
:
buildToolBar
(),
...
...
packages/flutter/lib/src/material/tabs.dart
View file @
6494cd1f
This diff is collapsed.
Click to expand it.
packages/flutter/test/widget/tabs_test.dart
View file @
6494cd1f
...
...
@@ -7,13 +7,13 @@ import 'package:flutter/material.dart';
import
'package:flutter/widgets.dart'
;
import
'package:test/test.dart'
;
Widget
buildFrame
(
{
List
<
String
>
tabs
,
bool
isScrollable:
false
})
{
Widget
buildFrame
(
{
List
<
String
>
tabs
,
String
value
,
bool
isScrollable:
false
})
{
return
new
Material
(
child:
new
TabBarSelection
(
index:
2
,
maxIndex:
tabs
.
length
-
1
,
child:
new
TabBar
(
labels:
tabs
.
map
((
String
tab
)
=>
new
TabLabel
(
text:
tab
)).
toList
(
),
child:
new
TabBarSelection
<
String
>
(
value:
value
,
values:
tabs
,
child:
new
TabBar
<
String
>
(
labels:
new
Map
<
String
,
TabLabel
>.
fromIterable
(
tabs
,
value:
(
String
tab
)
=>
new
TabLabel
(
text:
tab
)
),
isScrollable:
isScrollable
)
)
...
...
@@ -25,28 +25,48 @@ void main() {
testWidgets
((
WidgetTester
tester
)
{
List
<
String
>
tabs
=
<
String
>[
'A'
,
'B'
,
'C'
];
tester
.
pumpWidget
(
buildFrame
(
tabs:
tabs
,
isScrollable:
false
));
TabBarSelectionState
selection
=
tester
.
findStateOfType
(
TabBarSelectionState
);
tester
.
pumpWidget
(
buildFrame
(
tabs:
tabs
,
value:
'C'
,
isScrollable:
false
));
TabBarSelectionState
<
String
>
selection
=
TabBarSelection
.
of
(
tester
.
findText
(
'A'
)
);
expect
(
selection
,
isNotNull
);
expect
(
selection
.
indexOf
(
'A'
),
equals
(
0
));
expect
(
selection
.
indexOf
(
'B'
),
equals
(
1
));
expect
(
selection
.
indexOf
(
'C'
),
equals
(
2
));
expect
(
tester
.
findText
(
'A'
),
isNotNull
);
expect
(
tester
.
findText
(
'B'
),
isNotNull
);
expect
(
tester
.
findText
(
'C'
),
isNotNull
);
expect
(
selection
.
index
,
equals
(
2
));
expect
(
selection
.
previousIndex
,
equals
(
2
));
expect
(
selection
.
value
,
equals
(
'C'
));
expect
(
selection
.
previousValue
,
equals
(
'C'
));
tester
.
pumpWidget
(
buildFrame
(
tabs:
tabs
,
isScrollable:
false
));
tester
.
pumpWidget
(
buildFrame
(
tabs:
tabs
,
value:
'C'
,
isScrollable:
false
));
tester
.
tap
(
tester
.
findText
(
'B'
));
tester
.
pump
();
expect
(
selection
.
valueIsChanging
,
true
);
tester
.
pump
(
const
Duration
(
seconds:
1
));
// finish the animation
expect
(
selection
.
valueIsChanging
,
false
);
expect
(
selection
.
value
,
equals
(
'B'
));
expect
(
selection
.
previousValue
,
equals
(
'C'
));
expect
(
selection
.
index
,
equals
(
1
));
expect
(
selection
.
previousIndex
,
equals
(
2
));
tester
.
pumpWidget
(
buildFrame
(
tabs:
tabs
,
isScrollable:
false
));
tester
.
pumpWidget
(
buildFrame
(
tabs:
tabs
,
value:
'C'
,
isScrollable:
false
));
tester
.
tap
(
tester
.
findText
(
'C'
));
tester
.
pump
();
tester
.
pump
(
const
Duration
(
seconds:
1
));
expect
(
selection
.
value
,
equals
(
'C'
));
expect
(
selection
.
previousValue
,
equals
(
'B'
));
expect
(
selection
.
index
,
equals
(
2
));
expect
(
selection
.
previousIndex
,
equals
(
1
));
tester
.
pumpWidget
(
buildFrame
(
tabs:
tabs
,
isScrollable:
false
));
tester
.
pumpWidget
(
buildFrame
(
tabs:
tabs
,
value:
'C'
,
isScrollable:
false
));
tester
.
tap
(
tester
.
findText
(
'A'
));
tester
.
pump
();
tester
.
pump
(
const
Duration
(
seconds:
1
));
expect
(
selection
.
value
,
equals
(
'A'
));
expect
(
selection
.
previousValue
,
equals
(
'C'
));
expect
(
selection
.
index
,
equals
(
0
));
expect
(
selection
.
previousIndex
,
equals
(
2
));
});
});
...
...
@@ -54,28 +74,28 @@ void main() {
testWidgets
((
WidgetTester
tester
)
{
List
<
String
>
tabs
=
<
String
>[
'A'
,
'B'
,
'C'
];
tester
.
pumpWidget
(
buildFrame
(
tabs:
tabs
,
isScrollable:
true
));
TabBarSelectionState
selection
=
tester
.
findStateOfType
(
TabBarSelectionState
);
tester
.
pumpWidget
(
buildFrame
(
tabs:
tabs
,
value:
'C'
,
isScrollable:
true
));
TabBarSelectionState
<
String
>
selection
=
TabBarSelection
.
of
(
tester
.
findText
(
'A'
)
);
expect
(
selection
,
isNotNull
);
expect
(
tester
.
findText
(
'A'
),
isNotNull
);
expect
(
tester
.
findText
(
'B'
),
isNotNull
);
expect
(
tester
.
findText
(
'C'
),
isNotNull
);
expect
(
selection
.
index
,
equals
(
2
));
expect
(
selection
.
value
,
equals
(
'C'
));
tester
.
pumpWidget
(
buildFrame
(
tabs:
tabs
,
isScrollable:
true
));
tester
.
pumpWidget
(
buildFrame
(
tabs:
tabs
,
value:
'C'
,
isScrollable:
true
));
tester
.
tap
(
tester
.
findText
(
'B'
));
tester
.
pump
();
expect
(
selection
.
index
,
equals
(
1
));
expect
(
selection
.
value
,
equals
(
'B'
));
tester
.
pumpWidget
(
buildFrame
(
tabs:
tabs
,
isScrollable:
true
));
tester
.
pumpWidget
(
buildFrame
(
tabs:
tabs
,
value:
'C'
,
isScrollable:
true
));
tester
.
tap
(
tester
.
findText
(
'C'
));
tester
.
pump
();
expect
(
selection
.
index
,
equals
(
2
));
expect
(
selection
.
value
,
equals
(
'C'
));
tester
.
pumpWidget
(
buildFrame
(
tabs:
tabs
,
isScrollable:
true
));
tester
.
pumpWidget
(
buildFrame
(
tabs:
tabs
,
value:
'C'
,
isScrollable:
true
));
tester
.
tap
(
tester
.
findText
(
'A'
));
tester
.
pump
();
expect
(
selection
.
index
,
equals
(
0
));
expect
(
selection
.
value
,
equals
(
'A'
));
});
});
}
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