Fix crash when removing a card in card_collection

MixedViewport didn't use the building:true flag when locking itself, so
when it caused a rebuild of its children, we assumed that nobody was
allowed to mark things dirty below the list, and things crashed when
Inherited people did in fact rebuild.

Also:
 - default offset for MixedViewport
 - don't bother rebuilding if the underlying RenderObject is going to
   rebuild anyway for some reason
 - better docs for the "items must have keys" assert
 - keep the FlipComponent stuff together in test_widgets.dart
This commit is contained in:
Hixie
2015-10-27 16:54:02 -07:00
parent af790303c2
commit a8a32a972a
5 changed files with 77 additions and 17 deletions

View File

@@ -0,0 +1,47 @@
import 'package:flutter/widgets.dart';
import 'package:test/test.dart';
import 'widget_tester.dart';
List<int> items = <int>[0, 1, 2, 3, 4, 5];
Widget buildCard(BuildContext context, int index) {
if (index >= items.length)
return null;
return new Container(
key: new ValueKey<int>(items[index]),
height: 100.0,
child: new DefaultTextStyle(
style: new TextStyle(fontSize: 2.0 + items.length.toDouble()),
child: new Text('${items[index]}')
)
);
}
InvalidatorCallback invalidator;
Widget buildFrame() {
return new ScrollableMixedWidgetList(
builder: buildCard,
token: items.length,
onInvalidatorAvailable: (InvalidatorCallback callback) { invalidator = callback; }
);
}
void main() {
test('MixedViewport is a build function (smoketest)', () {
testWidgets((WidgetTester tester) {
tester.pumpWidget(buildFrame());
expect(tester.findText('0'), isNotNull);
expect(tester.findText('1'), isNotNull);
expect(tester.findText('2'), isNotNull);
expect(tester.findText('3'), isNotNull);
items.removeAt(2);
tester.pumpWidget(buildFrame());
expect(tester.findText('0'), isNotNull);
expect(tester.findText('1'), isNotNull);
expect(tester.findText('2'), isNull);
expect(tester.findText('3'), isNotNull);
});
});
}

View File

@@ -15,6 +15,16 @@ final BoxDecoration kBoxDecorationC = new BoxDecoration(
backgroundColor: const Color(0xFF0000FF)
);
class TestBuildCounter extends StatelessComponent {
static int buildCount = 0;
Widget build(BuildContext context) {
++buildCount;
return new DecoratedBox(decoration: kBoxDecorationA);
}
}
class FlipComponent extends StatefulComponent {
FlipComponent({ Key key, this.left, this.right }) : super(key: key);
@@ -38,15 +48,6 @@ class FlipComponentState extends State<FlipComponent> {
}
}
class TestBuildCounter extends StatelessComponent {
static int buildCount = 0;
Widget build(BuildContext context) {
++buildCount;
return new DecoratedBox(decoration: kBoxDecorationA);
}
}
void flipStatefulComponent(WidgetTester tester) {
StatefulComponentElement stateElement =
tester.findElement((Element element) => element is StatefulComponentElement);