Reputation: 33
I want to create a radio button style voting system using icons in Flutter (Dart) which looks like this: vote icons
The concept is simple: The page will display a movie, the user can then vote on that movie using the Icon buttons above. When a vote is made, the icon changes to red and the movie is added to an array.
The tricky part which I am struggling with is:
Thanks in advance!
Upvotes: 2
Views: 4865
Reputation: 1
GestureDetector(
onTap:() {},
child: Card(
elevation: 1,
child: Padding(
padding: EdgeInsets.symmetric(
horizontal: 15.w,
vertical: 10,
),
child: Column(
children: [
Icon(
Icons.ac_unit_outlined,
size: 40,
color: _valgroup == 1
? Colors.orange
: Colors.blue,
),
Radio(
activeColor: Colors. orange,
groupValue: _valgroup,
value: 1,
onChanged: (int? value) {
if (value != null) {
setState(() {
_valgroup = value;
});
}
},
),
],
),
),
),
),
Upvotes: 0
Reputation: 1931
class Example extends StatefulWidget {
@override
_ExampleState createState() => _ExampleState();
}
class _ExampleState extends State<Example> {
int _selected = null;
@override
Widget build(BuildContext context) {
return Row(
children: [
_icon(0, text: "No way", icon: Icons.face),
_icon(1, text: "Maybe", icon: Icons.local_movies),
_icon(2, text: "Looks good", icon: Icons.local_pizza),
_icon(3, text: "Can't wait", icon: Icons.local_fire_department),
],
);
}
Widget _icon(int index, {String text, IconData icon}) {
return Padding(
padding: const EdgeInsets.all(16.0),
child: InkResponse(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Icon(
icon,
color: _selected == index ? Colors.red : null,
),
Text(text, style: TextStyle(color: _selected == index ? Colors.red : null)),
],
),
onTap: () => setState(
() {
_selected = index;
},
),
),
);
}
}
Upvotes: 5