Commit dc907830 authored by Ian Hickson's avatar Ian Hickson

Merge pull request #718 from Hixie/core-basics

Introduce some basic utility classes.
parents 1d4693fc c5a26615
......@@ -9,6 +9,7 @@ enum _MenuItems { autorefresh, autorefreshCheckbox, refresh, speedUp, speedDown
const double _kMenuMargin = 16.0; // 24.0 on tablet
Future showStockMenu({BuildContext context, bool autorefresh, ValueChanged<bool> onAutorefreshChanged }) async {
StateSetter autorefreshStateSetter;
switch (await showMenu(
context: context,
position: new ModalPosition(
......@@ -20,12 +21,18 @@ Future showStockMenu({BuildContext context, bool autorefresh, ValueChanged<bool>
value: _MenuItems.autorefresh,
child: new Row(<Widget>[
new Flexible(child: new Text('Autorefresh')),
new Checkbox(
value: autorefresh,
onChanged: (bool value) {
// TODO(ianh): https://github.com/flutter/flutter/issues/187
autorefresh = value;
Navigator.pop(context, _MenuItems.autorefreshCheckbox);
new StatefulBuilder(
builder: (BuildContext context, StateSetter setState) {
autorefreshStateSetter = setState;
return new Checkbox(
value: autorefresh,
onChanged: (bool value) {
setState(() {
autorefresh = value;
});
Navigator.pop(context, _MenuItems.autorefreshCheckbox);
}
);
}
)
]
......@@ -46,8 +53,9 @@ Future showStockMenu({BuildContext context, bool autorefresh, ValueChanged<bool>
]
)) {
case _MenuItems.autorefresh:
// TODO(ianh): https://github.com/flutter/flutter/issues/187
autorefresh = !autorefresh;
autorefreshStateSetter(() {
autorefresh = !autorefresh;
});
continue autorefreshNotify;
autorefreshNotify:
case _MenuItems.autorefreshCheckbox:
......
......@@ -1367,3 +1367,19 @@ class KeyedSubtree extends StatelessComponent {
Widget build(BuildContext context) => child;
}
class Builder extends StatelessComponent {
Builder({ Key key, this.builder }) : super(key: key);
final WidgetBuilder builder;
Widget build(BuildContext context) => builder(context);
}
typedef Widget StatefulWidgetBuilder(BuildContext context, StateSetter setState);
class StatefulBuilder extends StatefulComponent {
StatefulBuilder({ Key key, this.builder }) : super(key: key);
final StatefulWidgetBuilder builder;
_StatefulBuilderState createState() => new _StatefulBuilderState();
}
class _StatefulBuilderState extends State<StatefulBuilder> {
Widget build(BuildContext context) => config.builder(context, setState);
}
\ No newline at end of file
......@@ -7,8 +7,6 @@ import 'package:flutter/animation.dart';
import 'package:flutter/material.dart';
import 'package:test/test.dart';
import 'test_widgets.dart';
class TestTransition extends TransitionComponent {
TestTransition({
Key key,
......
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter_test/flutter_test.dart';
import 'package:flutter/widgets.dart';
import 'package:test/test.dart';
void main() {
test('setState() overbuild test', () {
testWidgets((WidgetTester tester) {
List<String> log = <String>[];
Builder inner = new Builder(
builder: (BuildContext context) {
log.add('inner');
return new Text('inner');
}
);
int value = 0;
tester.pumpWidget(new Builder(
builder: (BuildContext context) {
log.add('outer');
return new StatefulBuilder(
builder: (BuildContext context, StateSetter setState) {
log.add('stateful');
return new GestureDetector(
onTap: () {
setState(() {
value += 1;
});
},
child: new Builder(
builder: (BuildContext context) {
log.add('middle $value');
return inner;
}
)
);
}
);
}
));
log.add('---');
tester.tap(tester.findText('inner'));;
tester.pump();
log.add('---');
expect(log, equals(<String>[
'outer',
'stateful',
'middle 0',
'inner',
'---',
'stateful',
'middle 1',
'---',
]));
});
});
}
......@@ -6,8 +6,6 @@ import 'package:flutter_test/flutter_test.dart';
import 'package:flutter/material.dart';
import 'package:test/test.dart';
import 'test_widgets.dart';
void main() {
test('SnackBar control test', () {
testWidgets((WidgetTester tester) {
......
......@@ -59,10 +59,3 @@ void flipStatefulComponent(WidgetTester tester) {
FlipComponentState state = stateElement.state;
state.flip();
}
class Builder extends StatelessComponent {
Builder({ Key key, this.builder }) : super(key: key);
final WidgetBuilder builder;
Widget build(BuildContext context) => builder(context);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment