mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
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.
This commit is contained in:
parent
c227179b56
commit
aecdef8ac2
@ -17,6 +17,7 @@ import 'package:sky/widgets/navigator.dart';
|
||||
import 'package:sky/widgets/popup_menu.dart';
|
||||
import 'package:sky/widgets/radio.dart';
|
||||
import 'package:sky/widgets/scaffold.dart';
|
||||
import 'package:sky/widgets/tabs.dart';
|
||||
import 'package:sky/widgets/tool_bar.dart';
|
||||
import 'package:sky/widgets/widget.dart';
|
||||
|
||||
@ -160,7 +161,7 @@ class StockHome extends Component {
|
||||
_drawerController.close();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Widget buildToolBar() {
|
||||
return new ToolBar(
|
||||
left: new IconButton(
|
||||
@ -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?
|
||||
Widget buildSearchBar() {
|
||||
return new ToolBar(
|
||||
@ -208,7 +239,7 @@ class StockHome extends Component {
|
||||
List<Widget> overlays = [
|
||||
new Scaffold(
|
||||
toolbar: _isSearching ? buildSearchBar() : buildToolBar(),
|
||||
body: new Stocklist(stocks: stocks, query: _searchQuery),
|
||||
body: buildTabNavigator(),
|
||||
floatingActionButton: new FloatingActionButton(
|
||||
child: new Icon(type: 'content/add_white', size: 24)
|
||||
),
|
||||
|
||||
@ -67,7 +67,6 @@ class EditableText extends Component {
|
||||
if (!_showCursor)
|
||||
return;
|
||||
|
||||
print("Draw cursor");
|
||||
Rect cursorRect = new Rect.fromLTWH(
|
||||
_kCursorGap,
|
||||
-_kCursorHeightOffset,
|
||||
|
||||
@ -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() {
|
||||
var itemShowIndex = 0;
|
||||
var itemShowCount = 0;
|
||||
|
||||
@ -10,16 +10,36 @@ PAINT FOR FRAME #2 ----------------------------------------------
|
||||
2 | | TestPaintingCanvas() constructor: 800.0 x 600.0
|
||||
2 | | paintChild RenderScaffold at Point(0.0, 0.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 | | | | drawRect(Rect.fromLTRB(0.0, 81.0, 800.0, 600.0), Paint(color:Color(0xfffafafa)))
|
||||
2 | | | | save
|
||||
2 | | | | clipRect(Rect.fromLTRB(0.0, 81.0, 800.0, 600.0))
|
||||
2 | | | | save
|
||||
2 | | | | translate(0.0, 81.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 RenderTabBar at Point(0.0, 81.0)
|
||||
2 | | | | | TestPaintingCanvas() constructor: 800.0 x 600.0
|
||||
2 | | | | | drawRect(Rect.fromLTRB(0.0, 81.0, 800.0, 129.0), Paint(color:Color(0xff9c27b0)))
|
||||
2 | | | | | paintChild RenderInkWell at Point(0.0, 81.0)
|
||||
2 | | | | | | TestPaintingCanvas() constructor: 800.0 x 600.0
|
||||
2 | | | | | | paintChild RenderOpacity at Point(174.5, 97.0)
|
||||
2 | | | | | | | TestPaintingCanvas() constructor: 800.0 x 600.0
|
||||
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 | | | | 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))
|
||||
@ -61,16 +81,36 @@ PAINT FOR FRAME #3 ----------------------------------------------
|
||||
3 | | TestPaintingCanvas() constructor: 800.0 x 600.0
|
||||
3 | | paintChild RenderScaffold at Point(0.0, 0.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 | | | | drawRect(Rect.fromLTRB(0.0, 81.0, 800.0, 600.0), Paint(color:Color(0xfffafafa)))
|
||||
3 | | | | save
|
||||
3 | | | | clipRect(Rect.fromLTRB(0.0, 81.0, 800.0, 600.0))
|
||||
3 | | | | save
|
||||
3 | | | | translate(0.0, 81.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 RenderTabBar at Point(0.0, 81.0)
|
||||
3 | | | | | TestPaintingCanvas() constructor: 800.0 x 600.0
|
||||
3 | | | | | drawRect(Rect.fromLTRB(0.0, 81.0, 800.0, 129.0), Paint(color:Color(0xff9c27b0)))
|
||||
3 | | | | | paintChild RenderInkWell at Point(0.0, 81.0)
|
||||
3 | | | | | | TestPaintingCanvas() constructor: 800.0 x 600.0
|
||||
3 | | | | | | paintChild RenderOpacity at Point(174.5, 97.0)
|
||||
3 | | | | | | | TestPaintingCanvas() constructor: 800.0 x 600.0
|
||||
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 | | | | 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))
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user