В основном я обновляю значение списка, которое используется в gridview, когда я нажимаю на карту gridview, я меняю цвет этой карты. когда я печатаю значение цвета, оно изменилось, но в gridview не имеет никакого эффекта. Плз подскажите что мне делать? мой логический подход неверен?
class FilterDialog extends ModalRoute<void> {
List<Grades> mGradeList = [];
List<Styles> mStyleList = [];
List<Types> mTypeList = [];
List<Specials> mSpecialList = [];
FilterDialog(this.mGradeList, this.mStyleList, this.mTypeList, this.mSpecialList);
@override
Widget buildPage(
BuildContext context,
Animation<double> animation,
Animation<double> secondaryAnimation,
) {
// This makes sure that text and other content follows the material style
return Material(
type: MaterialType.transparency,
// make sure that the overlay content is not cut off
child: SafeArea(
child: _buildOverlayContent(context),
),
);
}
Widget _buildOverlayContent(BuildContext context) {
return new Container(
padding: EdgeInsets.only(left: 15, right: 15),
child: Column(
children: <Widget>[
titleWidget("Grade"),
gridViewWidget(mGradeList, 3, 2.2),
spaceWidget(),
titleWidget("Style"),
gridViewWidget(mStyleList, 2, 3.5),
spaceWidget(),
titleWidget("Type"),
gridViewWidget(mTypeList, 2, 3.5),
spaceWidget(),
titleWidget("Special"),
gridViewWidget(mSpecialList, 2, 3.5),
],
)
);
}
Widget gridViewWidget(list, int count, double ratio) {
return GridView.count(
shrinkWrap: true,
crossAxisCount: count,
mainAxisSpacing: 2.0,
crossAxisSpacing: 1.0,
childAspectRatio: ratio,
physics: new NeverScrollableScrollPhysics(),
children: _getTiles(list)
);
}
void _onTileClicked(int index, value, list){
assert(index != null);
assert(value != null);
setState(() {
list[index].setSelected(!value);
});
debugPrint("You tapped on item $index with $value");
}
// Get grid tiles
List<Widget> _getTiles(list) {
final List<Widget> tiles = <Widget>[];
for (int i = 0; i < list.length; i++) {
tiles.add(new GridTile(
child: new Center(
child: Container(
height: 35.0,
child: new RaisedButton(
onPressed: () => _onTileClicked(i, list[i]["selected"], list),
color: list[i]["selected"] ? backgroundColor : white, //here value not changing
shape: new RoundedRectangleBorder(
borderRadius:
new BorderRadius.circular(30.0)),
child: new Text(
list[i]["label"],
textAlign: TextAlign.center,
style: new TextStyle(
fontSize: 14.0,
color: Colors.grey,
),
),
),
),
),
));
}
return tiles;
}
модель класса:
class Grades {
String label;
bool selected;
Grades(this.label, this.selected);
void setSelected(bool val) {
this.selected = val;
}
}
некоторые данные:
var typeList = [{"label": "Crack", "selected": false}, {"label": "Face", "selected": false},
{"label": "Slab", "selected": false}, {"label": "Multi-pitch", "selected": false} ];