如何修复此错误?以下是我的数据table.dart:
Widget build(BuildContext context) {
Controller controller = Get.put(Controller());
return Column(
children: [
SingleChildScrollView(
scrollDirection: Axis.vertical,
child: SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: DataTable(columns: [
DataColumn(
label: Text('Order No'),
),
DataColumn(
label: Text('Quantity'),
),
DataColumn(
label: Text('Retail Price'),
),
DataColumn(
label: Text('Payment Status'),
),
DataColumn(
label: Text('Date'),
),
DataColumn(
label: Text('Assign Rider'),
),
], rows: [
DataRow(
cells: [
DataCell(Text('637c8e3a')),
DataCell(Text('1')),
DataCell(Text('1.00')),
DataCell(Text('UnPaid')),
DataCell(
Text('2022-11-22 08:54:18'),
),
DataCell(
Obx( () => DropdownButton(
hint: Text(
'Book Type',
),
onChanged: (newValue) {
controller.setSelected(newValue);
},
value: controller.selected.value,
items: controller.listType.map((selectedType) {
return DropdownMenuItem(
child: new Text(
selectedType,
),
value: selectedType,
);
}).toList(),
)
),
),
])
]),
),
)
],
);
}final selected = "".obs;
void setSelected(String value){
selected.value = value;
},这是我在我的控制台中得到的:
Performing hot reload...
Syncing files to device TECNO CH7n...
lib/widget/data_table.dart:52:46: Error: The argument type 'Object?' can't be assigned to the parameter type 'String'.
- 'Object' is from 'dart:core'.
controller.setSelected(newValue);
^
lib/widget/data_table.dart:55:39: Error: The getter 'listType' isn't defined for the class 'Controller'.
- 'Controller' is from 'package:vendor_app/controller/dropdown_controller.dart' ('lib/controller/dropdown_controller.dart').
Try correcting the name to the name of an existing getter, or defining a getter or field named 'listType'.
items: controller.listType.map((selectedType) {
^^^^^^^^请帮我解决这个错误,谢谢!
发布于 2022-11-26 02:35:17
有两种解决问题的方法,首先在.toString()后面添加newValue (),如下所示
onChanged: ( newValue) {
controller.setSelected(newValue.toString());
},也可以在onChanged方法中定义类型,如下所示
onChanged: (String? newValue) {
controller.setSelected(newValue??'');
},我想这会对你有帮助。如果你有任何困惑,请随便问
https://stackoverflow.com/questions/74568653
复制相似问题