Add more debugging options to the stocks app.

- Add an option to enable debugPaintSizeEnabled.
- Add an option to enable the StatisticsOverlay.
- Add support for the StatisticsOverlay in MaterialApp.
- Change the layout behaviour of RenderStatisticsBox:
   - Give it a zero intrinsic width.
   - Give it an accurate intrinsic height that depends on the flags
     set. (Also, move the enum to the rendering/ layer from the
     widgets/ layer to enable this.)
   - Make the box automatically size itself full-width and the correct
     height, so that you can actually embed it (though most of the
     time you'd just put it in a Stack so this doesn't matter as
     much, really).
- Some style nit fixes in statistics_box.dart.
This commit is contained in:
Ian Hickson
2016-01-10 15:43:23 -08:00
parent c4545da2f2
commit 48e1350e73
7 changed files with 129 additions and 64 deletions

View File

@@ -6,12 +6,14 @@ material-design-icons:
- name: action/assessment
- name: action/backup
- name: action/help
- name: action/picture_in_picture
- name: action/search
- name: action/settings
- name: action/thumb_down
- name: action/thumb_up
- name: content/add
- name: device/dvr
- name: editor/border_all
- name: editor/border_clear
- name: navigation/arrow_back
- name: navigation/menu

View File

@@ -40,7 +40,9 @@ class StocksAppState extends State<StocksApp> {
StockConfiguration _configuration = new StockConfiguration(
stockMode: StockMode.optimistic,
backupMode: BackupMode.enabled,
showGrid: false
debugShowGrid: false,
debugShowSizes: false,
showRenderingStatistics: false
);
void initState() {
@@ -98,10 +100,15 @@ class StocksAppState extends State<StocksApp> {
}
Widget build(BuildContext context) {
assert(() {
debugPaintSizeEnabled = _configuration.debugShowSizes;
return true;
});
return new MaterialApp(
title: 'Stocks',
theme: theme,
debugShowMaterialGrid: _configuration.showGrid,
debugShowMaterialGrid: _configuration.debugShowGrid,
showRenderingPerformanceOverlay: _configuration.showRenderingStatistics,
routes: <String, RouteBuilder>{
'/': (RouteArguments args) => new StockHome(_stocks, _symbols, _configuration, configurationUpdater),
'/settings': (RouteArguments args) => new StockSettings(_configuration, configurationUpdater)

View File

@@ -24,7 +24,15 @@ class StockSettingsState extends State<StockSettings> {
}
void _handleShowGridChanged(bool value) {
sendUpdates(config.configuration.copyWith(showGrid: value));
sendUpdates(config.configuration.copyWith(debugShowGrid: value));
}
void _handleShowSizesChanged(bool value) {
sendUpdates(config.configuration.copyWith(debugShowSizes: value));
}
void _handleShowRenderingStatisticsChanged(bool value) {
sendUpdates(config.configuration.copyWith(showRenderingStatistics: value));
}
void _confirmOptimismChange() {
@@ -93,22 +101,44 @@ class StockSettingsState extends State<StockSettings> {
),
])
),
new DrawerItem(
icon: 'action/picture_in_picture',
onPressed: () { _handleShowRenderingStatisticsChanged(!config.configuration.showRenderingStatistics); },
child: new Row(<Widget>[
new Flexible(child: new Text('Show rendering performance overlay')),
new Switch(
value: config.configuration.showRenderingStatistics,
onChanged: _handleShowRenderingStatisticsChanged
),
])
),
];
assert(() {
// material grid is only available in checked mode
rows.add(
// material grid and size construction lines are only available in checked mode
rows.addAll([
new DrawerItem(
icon: 'editor/border_clear',
onPressed: () { _handleShowGridChanged(!config.configuration.showGrid); },
onPressed: () { _handleShowGridChanged(!config.configuration.debugShowGrid); },
child: new Row(<Widget>[
new Flexible(child: new Text('Show material grid (for debugging)')),
new Switch(
value: config.configuration.showGrid,
value: config.configuration.debugShowGrid,
onChanged: _handleShowGridChanged
),
])
),
new DrawerItem(
icon: 'editor/border_all',
onPressed: () { _handleShowSizesChanged(!config.configuration.debugShowSizes); },
child: new Row(<Widget>[
new Flexible(child: new Text('Show construction lines (for debugging)')),
new Switch(
value: config.configuration.debugShowSizes,
onChanged: _handleShowSizesChanged
),
])
)
);
]);
return true;
});
return new Block(

View File

@@ -11,26 +11,36 @@ class StockConfiguration {
StockConfiguration({
this.stockMode,
this.backupMode,
this.showGrid
this.debugShowGrid,
this.debugShowSizes,
this.showRenderingStatistics
}) {
assert(stockMode != null);
assert(backupMode != null);
assert(showGrid != null);
assert(debugShowGrid != null);
assert(debugShowSizes != null);
assert(showRenderingStatistics != null);
}
final StockMode stockMode;
final BackupMode backupMode;
final bool showGrid;
final bool debugShowGrid;
final bool debugShowSizes;
final bool showRenderingStatistics;
StockConfiguration copyWith({
StockMode stockMode,
BackupMode backupMode,
bool showGrid
bool debugShowGrid,
bool debugShowSizes,
bool showRenderingStatistics
}) {
return new StockConfiguration(
stockMode: stockMode ?? this.stockMode,
backupMode: backupMode ?? this.backupMode,
showGrid: showGrid ?? this.showGrid
debugShowGrid: debugShowGrid ?? this.debugShowGrid,
debugShowSizes: debugShowSizes ?? this.debugShowSizes,
showRenderingStatistics: showRenderingStatistics ?? this.showRenderingStatistics
);
}
}