我得到一个错误
Exception caught by gesture
Class 'String' has no instance getter 'status'
Receiver: 'Under PUI'
Tried calling: status
当我选择单选按钮时。我从firebase获得此单选按钮。请在下面查看我的代码:
class HealthStatusList extends StatefulWidget {
@override
_HealthStatusState createState() => _HealthStatusState();
}
class _HealthStatusState extends State<HealthStatusList> {
List<HealthStatus> healthStatusList = new List<HealthStatus>();
HealthStatus selectedHealthStatus;
@override
Widget build(BuildContext context) {
final healthStatuses = Provider.of<QuerySnapshot>(context);
// print(healthStatuses.documents);
for (var doc in healthStatuses.documents) {
int pos = doc.data['position'];
String sts = doc.data['status'];
String stc = doc.data['statusCode'];
HealthStatus hs =
new HealthStatus(position: pos, status: sts, statusCode: stc);
healthStatusList.add(hs);
print(doc.data['position']);
}
setSelectedHealthStatus(HealthStatus hs) {
setState(() {
selectedHealthStatus = hs;
});
}
List<Widget> createRadioListeners() {
List<Widget> widgets = [];
for (HealthStatus hs in healthStatusList) {
widgets.add(RadioListTile(
value: hs.status,
groupValue: selectedHealthStatus,
title: Text(hs.status),
onChanged: (currentStatus) {
print("Current Status ${currentStatus.status}");
setSelectedHealthStatus(currentStatus);
},
selected: selectedHealthStatus == hs,
activeColor: Colors.green,
));
}
return widgets;
}
return Scaffold(
body: Column(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
Container(
padding: EdgeInsets.all(20.0),
child: Text('How are you feeling?'),
),
Column(
children: createRadioListeners(),
)
],
),
);
}
}
这是HealthStatus类
class HealthStatus {
final int position;
final String status;
final String statusCode;
HealthStatus({this.position, this.status, this.statusCode});
@override
String toString() {
// TODO: implement toString
return status;
}
}
当我选择单选按钮时,我应该得到字符串“状态”字符串。
此外,当我单击单选按钮时,我看不到所选单选按钮上的点。您能指出我做错了什么吗?谢谢。
答案 0 :(得分:0)
此:
selected: selectedHealthStatus == hs,
应该是
selected: selectedHealthStatus == hs.status,