Mark State.setState as protected (#4295)

This required refactoring some cases where we weren't following the rules for
the protected annotation.
This commit is contained in:
Adam Barth
2016-06-02 10:46:12 -07:00
parent 88d47d5705
commit 1ff7109b02
11 changed files with 67 additions and 58 deletions

View File

@@ -35,6 +35,12 @@ class ComplexLayoutAppState extends State<ComplexLayoutApp> {
_lightTheme = value;
});
}
void toggleAnimationSpeed() {
setState(() {
timeDilation = (timeDilation != 1.0) ? 1.0 : 5.0;
});
}
}
class ComplexLayout extends StatefulWidget {
@@ -566,12 +572,6 @@ class GalleryDrawer extends StatelessWidget {
ComplexLayoutApp.of(context).lightTheme = value;
}
void _toggleAnimationSpeed(BuildContext context) {
ComplexLayoutApp.of(context).setState(() {
timeDilation = (timeDilation != 1.0) ? 1.0 : 5.0;
});
}
@override
Widget build(BuildContext context) {
return new Drawer(
@@ -612,13 +612,13 @@ class GalleryDrawer extends StatelessWidget {
new DrawerItem(
icon: Icons.hourglass_empty,
selected: timeDilation != 1.0,
onPressed: () { _toggleAnimationSpeed(context); },
onPressed: () { ComplexLayoutApp.of(context).toggleAnimationSpeed(); },
child: new Row(
children: <Widget>[
new Flexible(child: new Text('Animate Slowly')),
new Checkbox(
value: timeDilation != 1.0,
onChanged: (bool value) { _toggleAnimationSpeed(context); }
onChanged: (bool value) { ComplexLayoutApp.of(context).toggleAnimationSpeed(); }
)
]
)

View File

@@ -8,8 +8,6 @@ import 'package:stocks/stock_data.dart' as stock_data;
const Duration kBenchmarkTime = const Duration(seconds: 15);
void _doNothing() { }
Future<Null> main() async {
assert(false); // don't run this in checked mode! Use --release.
stock_data.StockDataFetcher.actuallyFetchData = false;
@@ -26,12 +24,12 @@ Future<Null> main() async {
await tester.pump(const Duration(seconds: 1)); // Complete drawer animation
final stocks.StocksAppState appState = tester.state(find.byType(stocks.StocksApp));
final BuildableElement appState = tester.element(find.byType(stocks.StocksApp));
final BuildOwner buildOwner = WidgetsBinding.instance.buildOwner;
watch.start();
while (watch.elapsed < kBenchmarkTime) {
appState.setState(_doNothing);
appState.markNeedsBuild();
buildOwner.buildDirtyElements();
iterations += 1;
}