Search
 
SCRIPT & CODE EXAMPLE
 

DART

custom radio button flutter

class CustomRadio extends StatefulWidget {
  @override
  createState() {
    return new CustomRadioState();
  }
}

class CustomRadioState extends State<CustomRadio> {
  List<RadioModel> sampleData = new List<RadioModel>();

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    sampleData.add(new RadioModel(false, 'A', 'April 18'));
    sampleData.add(new RadioModel(false, 'B', 'April 17'));
    sampleData.add(new RadioModel(false, 'C', 'April 16'));
    sampleData.add(new RadioModel(false, 'D', 'April 15'));
  }

  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: new AppBar(
        title: new Text("ListItem"),
      ),
      body: new ListView.builder(
        itemCount: sampleData.length,
        itemBuilder: (BuildContext context, int index) {
          return new InkWell(
            //highlightColor: Colors.red,
            splashColor: Colors.blueAccent,
            onTap: () {
              setState(() {
                sampleData.forEach((element) => element.isSelected = false);
                sampleData[index].isSelected = true;
              });
            },
            child: new RadioItem(sampleData[index]),
          );
        },
      ),
    );
  }
}

class RadioItem extends StatelessWidget {
  final RadioModel _item;
  RadioItem(this._item);
  @override
  Widget build(BuildContext context) {
    return new Container(
      margin: new EdgeInsets.all(15.0),
      child: new Row(
        mainAxisSize: MainAxisSize.max,
        children: <Widget>[
          new Container(
            height: 50.0,
            width: 50.0,
            child: new Center(
              child: new Text(_item.buttonText,
                  style: new TextStyle(
                      color:
                          _item.isSelected ? Colors.white : Colors.black,
                      //fontWeight: FontWeight.bold,
                      fontSize: 18.0)),
            ),
            decoration: new BoxDecoration(
              color: _item.isSelected
                  ? Colors.blueAccent
                  : Colors.transparent,
              border: new Border.all(
                  width: 1.0,
                  color: _item.isSelected
                      ? Colors.blueAccent
                      : Colors.grey),
              borderRadius: const BorderRadius.all(const Radius.circular(2.0)),
            ),
          ),
          new Container(
            margin: new EdgeInsets.only(left: 10.0),
            child: new Text(_item.text),
          )
        ],
      ),
    );
  }
}

class RadioModel {
  bool isSelected;
  final String buttonText;
  final String text;

  RadioModel(this.isSelected, this.buttonText, this.text);
}
Comment

flutter radio button

Radio<int>(
    activeColor: Colors.white,
    value: 1,
    groupValue: gender,
    onChanged: (value) {
    setState(() {
    	gender = value!;
	}
);
                  
Comment

flutter radio button

// Outof class 
enum SingingCharacter { lafayette, jefferson }

// declare object
SingingCharacter? _character = SingingCharacter.lafayette;
 
Radio<SingingCharacter>(
                    value: SingingCharacter.lafayette,
                    groupValue: _character,
                    onChanged: (SingingCharacter? value) {
                      setState(() {
                        _character = value;
                      }
                      );
                    },
                  ),
                  
                  
     
Comment

PREVIOUS NEXT
Code Example
Dart :: how to give width based on screen size flutter 
Dart :: onetime onboarding flutter 
Dart :: Array of colors in dart 
Dart :: flutter bottom sheet input button overlay flow by 
Dart :: dart while loop 
Dart :: concatenate in flutter 
Dart :: dart strip html 
Dart :: add all items to a list in dart 
Dart :: dart fold list 
Dart :: remove .0 flutter 
Dart :: what is pubspec.yaml 
Dart :: flutter increment decrement widget 
Dart :: bubble sort dart 
Dart :: how to load asset image to server in flutter 
Dart :: quebrar linha texto flutter 
Dart :: toolbar image dart 
Dart :: animation in flutter 
Dart :: flutter test from sdk incomapatible with package or plugin 
Dart :: a function body must be provided. try adding a function body. flutter 
Dart :: glowing buttons in flutter 
Dart :: flutter when to use methods 
Swift :: swift + data to string 
Swift :: swift create label programmatically 
Swift :: swift xcode debug cannot see code backtrace 
Swift :: detect end of scroll in UICollectionView ios swift 
Swift :: swift javascript injection 
Swift :: swiftui text field 
Swift :: rotate image animated swift 
Swift :: clone repo using jenkins pipeline 
Swift :: swift iterate over a dictionary 
ADD CONTENT
Topic
Content
Source link
Name
2+3 =