I want to create such a UI
with in which ,in the last, i get the details of all the radio Buttons selected.
and this is My Full code
And when i tried to do this,all radio button are turned to one side.
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
class Affiche_grille extends StatefulWidget {
@override
_QuestionWidgetState createState() => _QuestionWidgetState();
}
int selectedRadio;
int _groupValue = -1;
class _QuestionWidgetState extends State<Affiche_grille> {
List<RadioModel> sampleData = new List<RadioModel>();
@override
void initState() {
super.initState();
sampleData.add(new RadioModel(false, 'A', 'April 18', 'text1'));
sampleData.add(new RadioModel(false, 'B', 'April 17', 'text2'));
sampleData.add(new RadioModel(false, 'C', 'April 16', 'text3'));
sampleData.add(new RadioModel(false, 'D', 'April 15', 'text4'));
}
@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(
title: new Text("ListItem"),
),
body: ListView.builder(
itemCount: sampleData.length,
itemBuilder: (context, index) => ButtonBar(
alignment: MainAxisAlignment.center,
children: <Widget>[
_myRadioButton(
title: "Checkbox 0",
value: 0,
onChanged: (newValue) => setState(() => _groupValue = newValue),
),
_myRadioButton(
title: "Checkbox 1",
value: 1,
onChanged: (newValue) => setState(() => _groupValue = newValue),
),
],
),
),
);
}
}
Widget _myRadioButton({String title, int value, Function onChanged}) {
return Radio(
value: value,
groupValue: _groupValue,
onChanged: onChanged,
);
}
class RadioModel {
bool isSelected;
final String buttonText;
final String text;
final String text1;
RadioModel(this.isSelected, this.buttonText, this.text, this.text1);
}
This APPlication UI is made from this CODE.