Skip to content

Commit 0ba8e4f

Browse files
committed
fix #10
1 parent c1602ea commit 0ba8e4f

File tree

8 files changed

+107
-9
lines changed

8 files changed

+107
-9
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## 0.2.1
2+
* Fix #10 `StatefulWidget.createState must return a subtype of State<AutomaticKeepAliveVariableSizeBox>`.
3+
14
## 0.2.0
25
* Add a way to let the tile's content to define the tile's extent in the main axis.
36
* Add `fit` constructor to `StaggeredTile`.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ In the `pubspec.yaml` of your flutter project, add the following dependency:
2828
```yaml
2929
dependencies:
3030
...
31-
flutter_staggered_grid_view: "^0.2.0"
31+
flutter_staggered_grid_view: "^0.2.1"
3232
```
3333
3434
In your library add the following import:

example/lib/example_8.dart

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,6 @@ class Example08 extends StatelessWidget {
9696
itemBuilder: (context, index) => new _Tile(index, _sizes[index]),
9797
staggeredTileBuilder: (index) => new StaggeredTile.fit(2),
9898
),
99-
// body: new ListView.builder(
100-
// primary: false,
101-
// addAutomaticKeepAlives: false,
102-
// itemBuilder: (context, index) => new _Tile(index, _sizes[index]),
103-
// ),
10499
);
105100
}
106101
}

example/lib/example_tests.dart

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
import 'dart:math';
2+
import 'dart:typed_data';
3+
4+
import 'package:flutter/material.dart';
5+
import 'package:flutter_staggered_grid_view/flutter_staggered_grid_view.dart';
6+
7+
class ExampleTests extends StatelessWidget {
8+
ExampleTests() : products = List.generate(50, (i)=> Product('test $i'));
9+
10+
final List<Product> products;
11+
12+
@override
13+
Widget build(BuildContext context) {
14+
return new Scaffold(
15+
appBar: new AppBar(
16+
title: new Text('random dynamic tile sizes'),
17+
),
18+
body: CustomScrollView(
19+
slivers: <Widget>[
20+
SliverStaggeredGrid.countBuilder(
21+
crossAxisCount: 2,
22+
staggeredTileBuilder: (_) => StaggeredTile.fit(1),
23+
itemBuilder: (context, index) => ProductGridItem(products[index],),
24+
itemCount: products.length,
25+
),
26+
],
27+
)
28+
);
29+
}
30+
}
31+
32+
class Leaf extends StatefulWidget {
33+
const Leaf({ Key key, this.child }) : super(key: key);
34+
final Widget child;
35+
@override
36+
_LeafState createState() => new _LeafState();
37+
}
38+
39+
class _LeafState extends State<Leaf> {
40+
bool _keepAlive = false;
41+
KeepAliveHandle _handle;
42+
43+
@override
44+
void deactivate() {
45+
_handle?.release();
46+
_handle = null;
47+
super.deactivate();
48+
}
49+
50+
void setKeepAlive(bool value) {
51+
_keepAlive = value;
52+
if (_keepAlive) {
53+
if (_handle == null) {
54+
_handle = new KeepAliveHandle();
55+
new KeepAliveNotification(_handle).dispatch(context);
56+
}
57+
} else {
58+
_handle?.release();
59+
_handle = null;
60+
}
61+
}
62+
63+
@override
64+
Widget build(BuildContext context) {
65+
if (_keepAlive && _handle == null) {
66+
_handle = new KeepAliveHandle();
67+
new KeepAliveNotification(_handle).dispatch(context);
68+
}
69+
return widget.child;
70+
}
71+
}
72+
73+
class Product {
74+
const Product(this.name);
75+
final String name;
76+
}
77+
78+
class ProductGridItem extends StatelessWidget {
79+
const ProductGridItem(this.product);
80+
81+
final Product product;
82+
83+
@override
84+
Widget build(BuildContext context) {
85+
return new Card(
86+
child: Container(
87+
color: Colors.blue,
88+
height: 80.0,
89+
child: Center(
90+
child: Text(product.name),
91+
),
92+
)
93+
);
94+
}
95+
}

example/lib/home.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ const List<StaggeredTile> _tiles = const <StaggeredTile>[
2323
const StaggeredTile.count(1, 1),
2424
const StaggeredTile.count(1, 1),
2525
const StaggeredTile.count(1, 1),
26+
//const StaggeredTile.count(1, 1),
2627
];
2728

2829
List<Widget> _children = <Widget>[
@@ -53,6 +54,7 @@ List<Widget> _children = <Widget>[
5354
const HomeTile('dynamic resizing', Colors.pink, example06),
5455
const HomeTile('dynamic tile sizes', Colors.pink, example07),
5556
const HomeTile('random dynamic tile sizes', Colors.pink, example08),
57+
//const HomeTile('test', Colors.pink, exampleTests),
5658
];
5759

5860
class Home extends StatelessWidget {

example/lib/routes.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import 'example_5.dart';
88
import 'example_6.dart';
99
import 'example_7.dart';
1010
import 'example_8.dart';
11+
import 'example_tests.dart';
1112
import 'home.dart';
1213
import 'spannable_count_extent_page.dart';
1314
import 'spannable_count_count_page.dart';
@@ -38,6 +39,7 @@ const String example05 = '/example_05';
3839
const String example06 = '/example_06';
3940
const String example07 = '/example_07';
4041
const String example08 = '/example_08';
42+
const String exampleTests = '/example_tests';
4143

4244
Map<String, WidgetBuilder> routes = <String, WidgetBuilder>{
4345
homeRoute: (BuildContext context) => new Home(),
@@ -65,4 +67,5 @@ Map<String, WidgetBuilder> routes = <String, WidgetBuilder>{
6567
example06: (BuildContext context) => new Example06(),
6668
example07: (BuildContext context) => new Example07(),
6769
example08: (BuildContext context) => new Example08(),
70+
exampleTests: (BuildContext context) => new ExampleTests(),
6871
};

lib/src/widgets/automatic_keep_alive_variable_size_box.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class AutomaticKeepAliveVariableSizeBox extends StatefulWidget {
3737
_AutomaticKeepAliveState createState() => new _AutomaticKeepAliveState();
3838
}
3939

40-
class _AutomaticKeepAliveState extends State<AutomaticKeepAlive> {
40+
class _AutomaticKeepAliveState extends State<AutomaticKeepAliveVariableSizeBox> {
4141
Map<Listenable, VoidCallback> _handles;
4242
Widget _child;
4343
bool _keepingAlive = false;
@@ -49,7 +49,7 @@ class _AutomaticKeepAliveState extends State<AutomaticKeepAlive> {
4949
}
5050

5151
@override
52-
void didUpdateWidget(AutomaticKeepAlive oldWidget) {
52+
void didUpdateWidget(AutomaticKeepAliveVariableSizeBox oldWidget) {
5353
super.didUpdateWidget(oldWidget);
5454
_updateChild();
5555
}

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: flutter_staggered_grid_view
22
description: A Flutter staggered grid view
3-
version: 0.2.0
3+
version: 0.2.1
44
author: Romain Rastel <lets4r@gmail.com>
55
homepage: https://github.com/letsar/flutter_staggered_grid_view
66
dependencies:

0 commit comments

Comments
 (0)