提交 aecdef8a 编写于 作者: H Hans Muller

Add a TabNavigator to the Stocks demo

Changed FixedHeightScrollable so that if the list shrinks past the current scrollOffset, the scrollOffset is adjusted so that the last/only page of the list remains visible.

R=abarth@chromium.org

Review URL: https://codereview.chromium.org/1216323002.
上级 c227179b
...@@ -17,6 +17,7 @@ import 'package:sky/widgets/navigator.dart'; ...@@ -17,6 +17,7 @@ import 'package:sky/widgets/navigator.dart';
import 'package:sky/widgets/popup_menu.dart'; import 'package:sky/widgets/popup_menu.dart';
import 'package:sky/widgets/radio.dart'; import 'package:sky/widgets/radio.dart';
import 'package:sky/widgets/scaffold.dart'; import 'package:sky/widgets/scaffold.dart';
import 'package:sky/widgets/tabs.dart';
import 'package:sky/widgets/tool_bar.dart'; import 'package:sky/widgets/tool_bar.dart';
import 'package:sky/widgets/widget.dart'; import 'package:sky/widgets/widget.dart';
...@@ -160,7 +161,7 @@ class StockHome extends Component { ...@@ -160,7 +161,7 @@ class StockHome extends Component {
_drawerController.close(); _drawerController.close();
}); });
} }
Widget buildToolBar() { Widget buildToolBar() {
return new ToolBar( return new ToolBar(
left: new IconButton( left: new IconButton(
...@@ -178,6 +179,36 @@ class StockHome extends Component { ...@@ -178,6 +179,36 @@ class StockHome extends Component {
); );
} }
int selectedTabIndex = 0;
List<String> portfolioSymbols = ["AAPL","FIZZ", "FIVE", "FLAT", "ZINC", "ZNGA"];
Widget buildPortfolioStocklist() {
return new Stocklist(
stocks: stocks.where((s) => portfolioSymbols.contains(s.symbol)).toList(),
query: _searchQuery
);
}
Widget buildTabNavigator() {
List<TabNavigatorView> views = <TabNavigatorView>[
new TabNavigatorView(
label: const TabLabel(text: 'MARKET'),
builder: () => new Stocklist(stocks: stocks, query: _searchQuery)
),
new TabNavigatorView(
label: const TabLabel(text: 'PORTFOLIO'),
builder: buildPortfolioStocklist
)
];
return new TabNavigator(
views: views,
selectedIndex: selectedTabIndex,
onChanged: (tabIndex) {
setState(() { selectedTabIndex = tabIndex; } );
}
);
}
// TODO(abarth): Should we factor this into a SearchBar in the framework? // TODO(abarth): Should we factor this into a SearchBar in the framework?
Widget buildSearchBar() { Widget buildSearchBar() {
return new ToolBar( return new ToolBar(
...@@ -208,7 +239,7 @@ class StockHome extends Component { ...@@ -208,7 +239,7 @@ class StockHome extends Component {
List<Widget> overlays = [ List<Widget> overlays = [
new Scaffold( new Scaffold(
toolbar: _isSearching ? buildSearchBar() : buildToolBar(), toolbar: _isSearching ? buildSearchBar() : buildToolBar(),
body: new Stocklist(stocks: stocks, query: _searchQuery), body: buildTabNavigator(),
floatingActionButton: new FloatingActionButton( floatingActionButton: new FloatingActionButton(
child: new Icon(type: 'content/add_white', size: 24) child: new Icon(type: 'content/add_white', size: 24)
), ),
......
...@@ -67,7 +67,6 @@ class EditableText extends Component { ...@@ -67,7 +67,6 @@ class EditableText extends Component {
if (!_showCursor) if (!_showCursor)
return; return;
print("Draw cursor");
Rect cursorRect = new Rect.fromLTWH( Rect cursorRect = new Rect.fromLTWH(
_kCursorGap, _kCursorGap,
-_kCursorHeightOffset, -_kCursorHeightOffset,
......
...@@ -49,6 +49,14 @@ abstract class FixedHeightScrollable extends Scrollable { ...@@ -49,6 +49,14 @@ abstract class FixedHeightScrollable extends Scrollable {
}); });
} }
bool scrollTo(double newScrollOffset) {
if (_height != null && _height > 0.0) {
double maxScrollOffset = math.max(0.0, itemCount * itemHeight - _height);
newScrollOffset = math.min(newScrollOffset, maxScrollOffset);
}
return super.scrollTo(newScrollOffset);
}
Widget buildContent() { Widget buildContent() {
var itemShowIndex = 0; var itemShowIndex = 0;
var itemShowCount = 0; var itemShowCount = 0;
......
...@@ -10,16 +10,36 @@ PAINT FOR FRAME #2 ---------------------------------------------- ...@@ -10,16 +10,36 @@ PAINT FOR FRAME #2 ----------------------------------------------
2 | | TestPaintingCanvas() constructor: 800.0 x 600.0 2 | | TestPaintingCanvas() constructor: 800.0 x 600.0
2 | | paintChild RenderScaffold at Point(0.0, 0.0) 2 | | paintChild RenderScaffold at Point(0.0, 0.0)
2 | | | TestPaintingCanvas() constructor: 800.0 x 600.0 2 | | | TestPaintingCanvas() constructor: 800.0 x 600.0
2 | | | paintChild RenderDecoratedBox at Point(0.0, 81.0) 2 | | | paintChild RenderFlex at Point(0.0, 81.0)
2 | | | | TestPaintingCanvas() constructor: 800.0 x 600.0 2 | | | | TestPaintingCanvas() constructor: 800.0 x 600.0
2 | | | | drawRect(Rect.fromLTRB(0.0, 81.0, 800.0, 600.0), Paint(color:Color(0xfffafafa))) 2 | | | | paintChild RenderTabBar at Point(0.0, 81.0)
2 | | | | save 2 | | | | | TestPaintingCanvas() constructor: 800.0 x 600.0
2 | | | | clipRect(Rect.fromLTRB(0.0, 81.0, 800.0, 600.0)) 2 | | | | | drawRect(Rect.fromLTRB(0.0, 81.0, 800.0, 129.0), Paint(color:Color(0xff9c27b0)))
2 | | | | save 2 | | | | | paintChild RenderInkWell at Point(0.0, 81.0)
2 | | | | translate(0.0, 81.0) 2 | | | | | | TestPaintingCanvas() constructor: 800.0 x 600.0
2 | | | | concat([1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0]) 2 | | | | | | paintChild RenderOpacity at Point(174.5, 97.0)
2 | | | | restore 2 | | | | | | | TestPaintingCanvas() constructor: 800.0 x 600.0
2 | | | | restore 2 | | | | | | | translate(174.5, 97.0)
2 | | | | | | | translate(-174.5, -97.0)
2 | | | | | drawRect(Rect.fromLTRB(0.0, 127.0, 400.0, 129.0), Paint(color:Color(0xffff5252)))
2 | | | | | paintChild RenderInkWell at Point(400.0, 81.0)
2 | | | | | | TestPaintingCanvas() constructor: 800.0 x 600.0
2 | | | | | | paintChild RenderOpacity at Point(562.0, 97.0)
2 | | | | | | | TestPaintingCanvas() constructor: 800.0 x 600.0
2 | | | | | | | saveLayer(null, Paint(color:Color(0xb3000000)))
2 | | | | | | | translate(562.0, 97.0)
2 | | | | | | | translate(-562.0, -97.0)
2 | | | | | | | restore
2 | | | | paintChild RenderDecoratedBox at Point(0.0, 129.0)
2 | | | | | TestPaintingCanvas() constructor: 800.0 x 600.0
2 | | | | | drawRect(Rect.fromLTRB(0.0, 129.0, 800.0, 600.0), Paint(color:Color(0xfffafafa)))
2 | | | | | save
2 | | | | | clipRect(Rect.fromLTRB(0.0, 129.0, 800.0, 600.0))
2 | | | | | save
2 | | | | | translate(0.0, 129.0)
2 | | | | | concat([1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0])
2 | | | | | restore
2 | | | | | restore
2 | | | paintChild RenderDecoratedBox at Point(0.0, 0.0) 2 | | | paintChild RenderDecoratedBox at Point(0.0, 0.0)
2 | | | | TestPaintingCanvas() constructor: 800.0 x 600.0 2 | | | | TestPaintingCanvas() constructor: 800.0 x 600.0
2 | | | | drawRect(Rect.fromLTRB(0.0, 0.0, 800.0, 81.0), Paint(color:Color(0xff9c27b0), drawLooper:true)) 2 | | | | drawRect(Rect.fromLTRB(0.0, 0.0, 800.0, 81.0), Paint(color:Color(0xff9c27b0), drawLooper:true))
...@@ -61,16 +81,36 @@ PAINT FOR FRAME #3 ---------------------------------------------- ...@@ -61,16 +81,36 @@ PAINT FOR FRAME #3 ----------------------------------------------
3 | | TestPaintingCanvas() constructor: 800.0 x 600.0 3 | | TestPaintingCanvas() constructor: 800.0 x 600.0
3 | | paintChild RenderScaffold at Point(0.0, 0.0) 3 | | paintChild RenderScaffold at Point(0.0, 0.0)
3 | | | TestPaintingCanvas() constructor: 800.0 x 600.0 3 | | | TestPaintingCanvas() constructor: 800.0 x 600.0
3 | | | paintChild RenderDecoratedBox at Point(0.0, 81.0) 3 | | | paintChild RenderFlex at Point(0.0, 81.0)
3 | | | | TestPaintingCanvas() constructor: 800.0 x 600.0 3 | | | | TestPaintingCanvas() constructor: 800.0 x 600.0
3 | | | | drawRect(Rect.fromLTRB(0.0, 81.0, 800.0, 600.0), Paint(color:Color(0xfffafafa))) 3 | | | | paintChild RenderTabBar at Point(0.0, 81.0)
3 | | | | save 3 | | | | | TestPaintingCanvas() constructor: 800.0 x 600.0
3 | | | | clipRect(Rect.fromLTRB(0.0, 81.0, 800.0, 600.0)) 3 | | | | | drawRect(Rect.fromLTRB(0.0, 81.0, 800.0, 129.0), Paint(color:Color(0xff9c27b0)))
3 | | | | save 3 | | | | | paintChild RenderInkWell at Point(0.0, 81.0)
3 | | | | translate(0.0, 81.0) 3 | | | | | | TestPaintingCanvas() constructor: 800.0 x 600.0
3 | | | | concat([1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0]) 3 | | | | | | paintChild RenderOpacity at Point(174.5, 97.0)
3 | | | | restore 3 | | | | | | | TestPaintingCanvas() constructor: 800.0 x 600.0
3 | | | | restore 3 | | | | | | | translate(174.5, 97.0)
3 | | | | | | | translate(-174.5, -97.0)
3 | | | | | drawRect(Rect.fromLTRB(0.0, 127.0, 400.0, 129.0), Paint(color:Color(0xffff5252)))
3 | | | | | paintChild RenderInkWell at Point(400.0, 81.0)
3 | | | | | | TestPaintingCanvas() constructor: 800.0 x 600.0
3 | | | | | | paintChild RenderOpacity at Point(562.0, 97.0)
3 | | | | | | | TestPaintingCanvas() constructor: 800.0 x 600.0
3 | | | | | | | saveLayer(null, Paint(color:Color(0xb3000000)))
3 | | | | | | | translate(562.0, 97.0)
3 | | | | | | | translate(-562.0, -97.0)
3 | | | | | | | restore
3 | | | | paintChild RenderDecoratedBox at Point(0.0, 129.0)
3 | | | | | TestPaintingCanvas() constructor: 800.0 x 600.0
3 | | | | | drawRect(Rect.fromLTRB(0.0, 129.0, 800.0, 600.0), Paint(color:Color(0xfffafafa)))
3 | | | | | save
3 | | | | | clipRect(Rect.fromLTRB(0.0, 129.0, 800.0, 600.0))
3 | | | | | save
3 | | | | | translate(0.0, 129.0)
3 | | | | | concat([1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0])
3 | | | | | restore
3 | | | | | restore
3 | | | paintChild RenderDecoratedBox at Point(0.0, 0.0) 3 | | | paintChild RenderDecoratedBox at Point(0.0, 0.0)
3 | | | | TestPaintingCanvas() constructor: 800.0 x 600.0 3 | | | | TestPaintingCanvas() constructor: 800.0 x 600.0
3 | | | | drawRect(Rect.fromLTRB(0.0, 0.0, 800.0, 81.0), Paint(color:Color(0xff9c27b0), drawLooper:true)) 3 | | | | drawRect(Rect.fromLTRB(0.0, 0.0, 800.0, 81.0), Paint(color:Color(0xff9c27b0), drawLooper:true))
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册