var _oneValue = '';
var timeSlot = [
"١٢:٠٠ منتصف الليل",
"١:٠٠ صباحا",......
Row(
mainAxisAlignment:
MainAxisAlignment
.spaceBetween,
children: [
Expanded(
child: Text(
(timeSlot[i]),
style: Typographies
.largeBodyStyle(),
),
),
Radio(
activeColor:
ColorManager
.black,
value: timeSlot[i],
groupValue:
_oneValue,
onChanged:
(value) {
setState(
() {
_oneValue =
value!;
print(
_oneValue);
});
})
],
),
尝试使用 RadioListTile 小部件
这里是一个示例实现
import 'package:flutter/material.dart';
void main() => runApp(const MyApp());
class MyApp extends StatelessWidget {
const MyApp({super.key});
static const String _title = 'Flutter Code Sample';
@override
Widget build(BuildContext context) {
return MaterialApp(
title: _title,
home: Scaffold(
appBar: AppBar(title: const Text(_title)),
body: const MyStatefulWidget(),
),
);
}
}
class MyStatefulWidget extends StatefulWidget {
const MyStatefulWidget({super.key});
@override
State<MyStatefulWidget> createState() => _MyStatefulWidgetState();
}
class _MyStatefulWidgetState extends State<MyStatefulWidget> {
List items = [{'label':'Item1', 'value':1} ,{'label':'Item2', 'value':2}] ;
int _selectedValue=-1;
@override
Widget build(BuildContext context) {
return Column(
children: <Widget>[
for(var item in items)
RadioListTile(
title: Text(item['label']),
value: item['value'],
groupValue: _selectedValue,
onChanged: (value) {
print('Selected value $value');
setState(() {
_selectedValue = value as int;
});
},
),
],
);
}
}