Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create radio button with image in Flutter

I want to create RadioListTile like this in Flutter/Dart. I tried but didn't get success.

When user select gender that selected button should display in white icon with grey background

enter image description here

like image 831
Sanjayrajsinh Avatar asked Oct 10 '19 09:10

Sanjayrajsinh


1 Answers

enter image description here

You can try this approach:

int _value = 0;

@override
Widget build(BuildContext context) {
  return Scaffold(
    appBar: AppBar(),
    body: Padding(
      padding: const EdgeInsets.all(20.0),
      child: Row(
        children: <Widget>[
          GestureDetector(
            onTap: () => setState(() => _value = 0),
            child: Container(
              height: 56,
              width: 56,
              color: _value == 0 ? Colors.grey : Colors.transparent,
              child: Icon(Icons.call),
            ),
          ),
          SizedBox(width: 4),
          GestureDetector(
            onTap: () => setState(() => _value = 1),
            child: Container(
              height: 56,
              width: 56,
              color: _value == 1 ? Colors.grey : Colors.transparent,
              child: Icon(Icons.message),
            ),
          ),
        ],
      ),
    ),
  );
}
like image 91
CopsOnRoad Avatar answered Nov 06 '22 04:11

CopsOnRoad