Skip to content

Instantly share code, notes, and snippets.

@alvinthen
Created May 9, 2020 02:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alvinthen/356ff51ff4f080d20e2afbe66b3c28d3 to your computer and use it in GitHub Desktop.
Save alvinthen/356ff51ff4f080d20e2afbe66b3c28d3 to your computer and use it in GitHub Desktop.
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: ListViewBuilder(),
);
}
}
class RadioButtom extends StatefulWidget {
@override
_RadioButtomState createState() => _RadioButtomState();
RadioButtom({this.value, this.onChanged});
final bool value;
final ValueChanged<bool> onChanged;
}
class _RadioButtomState extends State<RadioButtom> {
@override
Widget build(BuildContext context) {
return Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Radio(
value: true,
groupValue: widget.value,
onChanged: widget.onChanged,
),
Text(
'Yes',
style: TextStyle(
fontSize: 12.0,
fontFamily: "OpenSans-Regular",
),
),
Radio(
value: false,
groupValue: widget.value,
onChanged: widget.onChanged,
),
Text(
'No',
style: TextStyle(
fontSize: 12.0,
fontFamily: "OpenSans-Regular",
),
)
],
);
}
}
class ListViewBuilder extends StatefulWidget {
@override
_ListViewBuilderState createState() => _ListViewBuilderState();
}
class _ListViewBuilderState extends State<ListViewBuilder> {
final _itemCount = 10;
List<bool> _radios;
@override
initState() {
super.initState();
_radios = List<bool>.filled(_itemCount, false);
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: ListView.builder(
itemCount: _itemCount,
itemBuilder: (context, index) => RadioButtom(
value: _radios[index],
onChanged: (value) {
setState(() {
_radios[index] = value;
});
}),
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment