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

radio button validation in flutter

This package helps in creation of Flutter Forms by providing the syntactic sugar for creating a Form Widget and reduce the boilerplate needed to build a form, validate fields, react to changes, and collect the value of the Form
Comment

PREVIOUS NEXT
Code Example
Dart :: flutter bool variable 
Dart :: flutter CustomPaint clip 
Dart :: flutter Explain Hot Reload in 
Dart :: FloatingActionButton rtl flutter 
Dart :: flutter: provider ChangeNotifierProvider() 
Dart :: how to check Flutter app comes to foreground 
Dart :: flutter button playing sound 
Dart :: dart map where 
Dart :: what is pubspec.yaml 
Dart :: path dart 
Dart :: flutter map 
Dart :: flutter firebase get provider type 
Dart :: naming convention class names flutter 
Dart :: flutter button sound effects 
Dart :: bloc to bloc communication in flutter 
Dart :: flutter string add , for 1000 
Dart :: seach flutter 
Dart :: how to add a listner to a object in dart 
Dart :: how to group data by date in a listview in flutter 
Dart :: dart remove the last letter in a string 
Swift :: swift check if string contains string 
Swift :: swift remove space from string 
Swift :: add toggle without text swiftui 
Swift :: change selection color uitableviewcell swift 
Swift :: swift do catch 
Swift :: how to convert int to double in swiftui 
Swift :: swift thread.sleep 
Swift :: and in swift1 
Swift :: define enum swift 
Swift :: how to set the center in view in swift 
ADD CONTENT
Topic
Content
Source link
Name
9+2 =