Commit c4545da2 authored by Adam Barth's avatar Adam Barth

Merge pull request #1172 from abarth/simplify_tabview

Simplify TabView API
parents f757211f dd08bf79
......@@ -85,9 +85,8 @@ class TabViewDemo extends StatelessComponent {
)
),
new Flexible(
child: new TabBarView<String>(
items: _iconNames,
itemBuilder: _buildTabView
child: new TabBarView(
children: _iconNames.map(_buildTabView).toList()
)
)
]);
......
......@@ -27,9 +27,8 @@ class TabsDemo extends StatefulComponent {
class _TabsDemoState extends State<TabsDemo> {
Widget build(_) {
return new TabBarView<String>(
items: _iconNames,
itemBuilder: (String iconName) {
return new TabBarView(
children: _iconNames.map((String iconName) {
return new Container(
key: new ValueKey<String>(iconName),
padding: const EdgeDims.all(12.0),
......@@ -37,7 +36,7 @@ class _TabsDemoState extends State<TabsDemo> {
child: new Center(child: new Icon(icon: "action/$iconName", size:IconSize.s48))
)
);
}
}).toList()
);
}
}
......
......@@ -267,18 +267,11 @@ class StockHomeState extends State<StockHome> {
toolBar: _isSearching ? buildSearchBar() : buildToolBar(),
floatingActionButton: buildFloatingActionButton(),
drawer: _buildDrawer(context),
body: new TabBarView<StockHomeTab>(
items: <StockHomeTab>[StockHomeTab.market, StockHomeTab.portfolio],
itemBuilder: (StockHomeTab tab) {
switch (tab) {
case StockHomeTab.market:
return _buildStockTab(context, tab, config.symbols);
case StockHomeTab.portfolio:
return _buildStockTab(context, tab, portfolioSymbols);
default:
assert(false);
}
}
body: new TabBarView(
children: <Widget>[
_buildStockTab(context, StockHomeTab.market, config.symbols),
_buildStockTab(context, StockHomeTab.portfolio, portfolioSymbols),
]
)
)
);
......
......@@ -764,36 +764,29 @@ class _TabBarState<T> extends ScrollableState<TabBar<T>> implements TabBarSelect
}
}
typedef Widget TabItemBuilder<T>(T item);
class TabBarView<T> extends PageableList {
class TabBarView extends PageableList {
TabBarView({
Key key,
List<T> items,
TabItemBuilder<T> itemBuilder
}) : items = items, itemBuilder = itemBuilder, super(
List<Widget> children
}) : super(
key: key,
scrollDirection: ScrollDirection.horizontal,
children: items.map((T item) => itemBuilder(item)).toList(),
itemsWrap: false
children: children
) {
assert(items != null);
assert(items.length > 1);
assert(children != null);
assert(children.length > 1);
}
final List<T> items;
final TabItemBuilder<T> itemBuilder;
_TabBarViewState createState() => new _TabBarViewState<T>();
_TabBarViewState createState() => new _TabBarViewState();
}
class _TabBarViewState<T> extends PageableListState<TabBarView<T>> implements TabBarSelectionPerformanceListener {
class _TabBarViewState extends PageableListState<TabBarView> implements TabBarSelectionPerformanceListener {
TabBarSelectionState _selection;
List<Widget> _items;
AnimationDirection _scrollDirection = AnimationDirection.forward;
int get _tabCount => config.items.length;
int get _tabCount => config.children.length;
BoundedBehavior _boundedBehavior;
......@@ -802,7 +795,7 @@ class _TabBarViewState<T> extends PageableListState<TabBarView<T>> implements Ta
return _boundedBehavior;
}
void _initSelection(TabBarSelectionState<T> selection) {
void _initSelection(TabBarSelectionState selection) {
_selection = selection;
if (_selection != null) {
_selection.registerPerformanceListener(this);
......@@ -919,7 +912,7 @@ class _TabBarViewState<T> extends PageableListState<TabBarView<T>> implements Ta
}
Widget buildContent(BuildContext context) {
TabBarSelectionState<T> newSelection = TabBarSelection.of(context);
TabBarSelectionState newSelection = TabBarSelection.of(context);
if (_selection != newSelection)
_initSelection(newSelection);
return new PageViewport(
......
......@@ -41,10 +41,10 @@ class ScrollableList extends Scrollable {
final ScrollableListPainter scrollableListPainter;
final Iterable<Widget> children;
ScrollableState createState() => new _ScrollableList2State();
ScrollableState createState() => new _ScrollableListState();
}
class _ScrollableList2State extends ScrollableState<ScrollableList> {
class _ScrollableListState extends ScrollableState<ScrollableList> {
ScrollBehavior createScrollBehavior() => new OverscrollBehavior();
ExtentScrollBehavior get scrollBehavior => super.scrollBehavior;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment