--
You received this message because you are subscribed to the Google Groups "Flutter Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to flutter-dev...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
setState(() {
_selectedUser = new User(
name: snapshot.data.contacts[index].name,
times: snapshot.data.contacts[index].times,
lastActive: snapshot
.data.contacts[index].lastActive,
isSelected: true);
if (_selectedUser.isSelected) {
_defaultColor = Colors.redAccent;
} else {
_defaultColor=Colors.transparent;
}
});Enter code here...
new GridView.builder(
scrollDirection: Axis.vertical,
itemCount: snapshot.data.contacts.length,
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 4),
itemBuilder: (context, index) {
return new GestureDetector(
onTap: () async {
setState(() {
_selectedUser = new User(
name: snapshot.data.contacts[index].name,
times: snapshot.data.contacts[index].times,
lastActive: snapshot
.data.contacts[index].lastActive,
isSelected: true);
_isButtonDisabled = true;
if (_selectedUser.isSelected) {
_defaultColor = Colors.redAccent;
} else {
_defaultColor=Colors.transparent;
}
});
},
child: new Container(
decoration: new BoxDecoration(
border: new Border.all(color: _defaultColor),
shape: BoxShape.rectangle),
padding: const EdgeInsets.all(5.0),
child: new Column(
children: <Widget>[
new CircleAvatar(
backgroundColor: Colors.white,
backgroundImage: new AssetImage(
'assets/images/avtar1.png'),
radius: 30.0,
),
new Text(
snapshot.data.contacts[index].name,
style: new TextStyle(fontSize: 12.0),
)
],
),
),
);
},
);
--
Hi Sanjay, Sorry i was on my mobile. I think this should sum it up based on the code you postednew GridView.builder(
scrollDirection: Axis.vertical,
itemCount: snapshot.data.contacts.length,
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 4),
itemBuilder: (context, index) => _buildGridItem(index),
);Widget _buildGridItem(int index){return new GestureDetector(
onTap: () async {
setState(() {
//if multiple select is allowed then remove loop below for(int i = 0; i < snapshot.data.contacts.length; i++){ snapshot.data.contacts[index].isSelected = true; }
snapshot.data.contacts[index].isSelected = !snapshot.data.contacts[index].isSelected; setUser(index);
},
child: new Container(
decoration: new BoxDecoration(
border: new Border.all(color: snapshot.data.contacts[index].isSelected? _selectedColor : _defaultColor),
shape: BoxShape.rectangle),
padding: const EdgeInsets.all(5.0),
child: new Column(
children: <Widget>[
new CircleAvatar(
backgroundColor: Colors.white,
backgroundImage: new AssetImage(
'assets/images/avtar1.png'),
radius: 30.0,
),
new Text(
snapshot.data.contacts[index].name,
style: new TextStyle(fontSize: 12.0),
)
],
),
),
);} setUser(int index){ _selectedUser = new User(
name: snapshot.data.contacts[index].name,
times: snapshot.data.contacts[index].times,
lastActive: snapshot
.data.contacts[index].lastActive,
isSelected: true);
_isButtonDisabled = true;
});}Sorry there was an error in loop, rectified it.new GridView.builder(
scrollDirection: Axis.vertical,
itemCount: snapshot.data.contacts.length,
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 4),
itemBuilder: (context, index) => _buildGridItem(index),);Widget _buildGridItem(int index){return new GestureDetector(
onTap: () async {
setState(() {
//for single selection is loop below
for(int i = 0; i < snapshot.data.contacts.length; i++){ if(i == index){ snapshot.data.contacts[index].isSelected = true;
setUser(index); } else snapshot.data.contacts[index].isSelected = false; } //for multiple selection remove loop and use only this line
snapshot.data.contacts[index].isSelected = !snapshot.data.contacts[index].isSelected;