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;
},
),
),
);
}
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
4085 次 |
最近记录: |