json - 如何将选定的单选按钮组值保存在变量中以供以后使用?
问题描述
我正在尝试将我的单选按钮 JSON 数据保存在变量中,以便以后可以使用它。目前它没有显示任何错误。它只是显示默认值。
我在我的类中取了一个变量radioItemHolder
,它保存了我的默认值。
class _DocBookingState extends State<DocBooking> {
String radioItemHolder = '03/09/2021';
然后我在 ListiewBuilder 下创建了单选按钮,在这里我将我的 JSON 数据作为单选按钮格式。
Container(
child: FutureBuilder(
future: DocVisitDays(),
builder:
(BuildContext context, AsyncSnapshot snapshot) {
if (snapshot.connectionState !=
ConnectionState.done) {
return CircularProgressIndicator();
}
if (snapshot.hasError) {
return Text("Somthing went wrong");
}
if (snapshot.hasData) {
return ListView.builder(
scrollDirection: Axis.vertical,
physics: BouncingScrollPhysics(),
shrinkWrap: true,
itemCount: snapshot.data.length,
itemBuilder: (BuildContext context, int index) {
return Container(
margin: EdgeInsets.all(10),
padding: EdgeInsets.all(10),
decoration: BoxDecoration(
color: Colors.lightBlue[50],
borderRadius:
BorderRadius.all(Radius.circular(12)),
boxShadow: [
BoxShadow(
color: Colors.grey.withOpacity(0.9),
offset: const Offset(
0.0,
5.0,
),
blurRadius: 3.0,
spreadRadius: 0.5,
),
],
),
child: Row(
children: [
Radio(
activeColor: Colors.green,
value: index,
groupValue: _radioValue,
onChanged: (value) {
setState(() {// Here Im trying to store the json value
radioItemHolder = snapshot.data[index].visitDate;
_radioValue = value as int;
});
},
),
Text(
"Visit Day: ${snapshot.data[index].visitDate},\n Fee: ${snapshot.data[index].fee}, \n Discounted Fee: ${snapshot.data[index].discountedFee}, \n Booking Fee: ${snapshot.data[index].bookingFee} ",
style:
TextStyle(fontFamily: 'Poppins'),
),
],
),
);
});
}
return Text("Error while calling");
},
),
),
我试图像这样将这个 JSON 数据保存${snapshot.data[index].visitDate}
在我的变量中
仍然没有改变默认值。radioItemHolder
radioItemHolder = snapshot.data[index].visitDate;
解决方案
我认为更改value
为val
有效。谁能告诉我原因?
onChanged: (val) {
setState(() {
radioItemHolder = snapshot.data[index].visitDate;
_radioValue = val as int;
});
},
推荐阅读
- ios - IOS 上的 WebRTC 应用程序无法在美国 iPhone 上运行
- c# - 参数值“421.0526000000”超出范围
- javascript - JQuery .on('Click') 只工作一次,而不是多次
- bash - 监控变量与上次读数中的其他 bash 相比是否在增长
- android - Android 数据绑定库 - 未解决的参考
- python - 无法在(Flask-)SQLAlchemy中获得一对多关系
- html - 如何在不更改 HTML 的情况下将单个 UL 拆分为两列布局?
- javascript - 如何使用 Sentry 报告 console.error?
- python - ValueError:期望','分隔符,同时尝试在python3中将字符串加载为json
- python - 推荐什么?tensorflow train_and_evaluate 或 estimator.train, estimator.evaluate