Chromium Code Reviews

Unified Diff: sky/examples/stocks2/lib/stock_home.dart

Issue 1197333002: Make the checkbox in settings control the radio buttons in the drawer, to demonstrate how to link s… (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Index: sky/examples/stocks2/lib/stock_home.dart
diff --git a/sky/examples/stocks2/lib/stock_home.dart b/sky/examples/stocks2/lib/stock_home.dart
index 720530b8dea709699c7c456bcf31df5f1c6be56a..3ea040992deb61cf615750aa1b2825c9e7e9b03d 100644
--- a/sky/examples/stocks2/lib/stock_home.dart
+++ b/sky/examples/stocks2/lib/stock_home.dart
@@ -25,23 +25,28 @@ import 'stock_list.dart';
import 'stock_menu.dart';
enum StockMode { optimistic, pessimistic }
+typedef void ModeUpdater(StockMode mode);
class StockHome extends Component {
- StockHome(this.navigator, RouteBase route, this.stocks) : super(stateful: true) {
+ StockHome(this.navigator, this.stocks, this.stockMode, this.modeUpdater) : super(stateful: true) {
// if (debug)
// new Timer(new Duration(seconds: 1), dumpState);
_drawerController = new DrawerController(_handleDrawerStatusChanged);
}
+ Navigator navigator;
+ List<Stock> stocks;
+ StockMode stockMode;
+ ModeUpdater modeUpdater;
+
void syncFields(StockHome source) {
navigator = source.navigator;
stocks = source.stocks;
+ stockMode = source.stockMode;
+ modeUpdater = source.modeUpdater;
}
- Navigator navigator;
- List<Stock> stocks;
-
bool _isSearching = false;
String _searchQuery;
@@ -102,11 +107,12 @@ class StockHome extends Component {
});
}
- StockMode _stockMode = StockMode.optimistic;
void _handleStockModeChange(StockMode value) {
setState(() {
- _stockMode = value;
+ stockMode = value;
});
+ if (modeUpdater != null)
+ modeUpdater(value);
}
Drawer buildDrawer() {
@@ -127,14 +133,14 @@ class StockHome extends Component {
onPressed: () => _handleStockModeChange(StockMode.optimistic),
children: [
new Flexible(child: new Text('Optimistic')),
- new Radio(value: StockMode.optimistic, groupValue: _stockMode, onChanged: _handleStockModeChange)
+ new Radio(value: StockMode.optimistic, groupValue: stockMode, onChanged: _handleStockModeChange)
]),
new MenuItem(
icon: 'action/thumb_down',
onPressed: () => _handleStockModeChange(StockMode.pessimistic),
children: [
new Flexible(child: new Text('Pessimistic')),
- new Radio(value: StockMode.pessimistic, groupValue: _stockMode, onChanged: _handleStockModeChange)
+ new Radio(value: StockMode.pessimistic, groupValue: stockMode, onChanged: _handleStockModeChange)
]),
new MenuDivider(),
new MenuItem(

Powered by Google App Engine