我的下拉列表是API的工作呼叫列表,并获取错误类型; _internallinkedHashmap< string,dynamic>>'不是类型的子类型。
我正在尝试从REST API获取下拉列表,但是获得此错误例外:键入'_internallinkedhashmap< string,dynamic>'不是类型“列表”的子类型。如何解决此错误并在屏幕上获取我的原因列表。我的下拉无法正常工作。
console screen:
{Result: Success, Remarks: Records Found Successfully, data: [{reason: DOOR LOCKED}, {reason:
CUSTOMER NOT INTERESTED}, {reason: DEFECTIVE SPARES}, {reason: NO WATER SUPPLY TO CHECK},
{reason: PROBLEM NOT UNDERSTOOD}, {reason: NO ELECTRICITY WHEN VISITED },
{reason: RESCHEDULED VISIT}, {reason: CUSTOMER UN-AWARE OF COMPLAINT LODGED}, {reason: SPARES
UN-AVAILABLE DURING VISIT}, {reason: SPARES UN-AVAILABLE HENCE NOT VISITED}, {reason: CALL
CLOSED BUT OPEN IN SYSTEM}]}
E/flutter (21266): [ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception:
Exception: type '_InternalLinkedHashMap<String, dynamic>' is not a subtype of type
'List<dynamic>'
E/flutter (21266): #0 CustomerDetailsOTCoPageState._getPendingRsn
package:zero_b/Options/customerdetailsOTCo_sp.dart:852
E/flutter (21266): <asynchronous suspension>
E/flutter (21266):
这是我的下拉按钮的主要课程。
class CustomerDetailsOTCoPageState extends State<CustomerDetailsOTCoPage>
with AutomaticKeepAliveClientMixin<CustomerDetailsOTCoPage> {
final GlobalKey<ScaffoldState> _scaffoldKey = new GlobalKey<ScaffoldState>();
List datalist = List();
String selectedreason;
@override
void initState() {
super.initState();
this._getPendingRsn();
}
@override
Widget build(BuildContext context) {
return Scaffold(
key: _scaffoldKey,
body: WillPopScope(
onWillPop: _onBackPressed,
child: SingleChildScrollView(
child: Container(
width: MediaQuery.of(context).size.width,
height: MediaQuery.of(context).size.height,
child: Column(children: <Widget>[
Container(
margin: EdgeInsets.only(
top: 2,
bottom: 4,
left: 8,
right: 8,
),
padding: EdgeInsets.only(
top: 2,
bottom: 4,
left: 8,
right: 8,
),
child: Row(children: <Widget>[
Text("Result : ",
style: TextStyle(
fontFamily: "WorkSansMedium",
color: Colors.black,
fontSize: 15,
)),
DropdownButton<String>(
value: dropdownValue,
icon: Icon(Icons.arrow_drop_down),
iconSize: 19,
elevation: 14,
style: TextStyle(
color: Colors.black,
fontSize: 15,
fontFamily: "WorkSansMedium"),
onChanged: (String data) {
setState(() {
dropdownValue = data;
});
},
items: spinnerItems
.map<DropdownMenuItem<String>>((String value) {
return DropdownMenuItem<String>(
value: value,
child: Text(value),
);
}).toList(),
),
]),
),
dropdownValue == 'Pending'
? _dropdownPending()
: Column(children: <Widget>[
FutureBuilder<Result>(
future: apiWorkComplete(),
builder: (context, snapshot) {
try {
if (snapshot.connectionState ==
ConnectionState.done) {
if (snapshot.hasError) {
return Container(
alignment: Alignment.center,
child: Text(
"Failed to load Page",
style: TextStyle(
color: Colors.black,
fontSize: 15.0,
fontFamily: "WorkSansMedium"),
),
);
} else if (snapshot.hasData &&
snapshot.data != null) {
return _workCompleteList(snapshot);
} else {
return Center(
child: Column(
children: <Widget>[
SizedBox(
height: 100,
),
CircularProgressIndicator(
backgroundColor: Colors.white,
),
],
));
}
} else {
return Center(
child: Column(
children: <Widget>[
SizedBox(
height: 100,
),
CircularProgressIndicator(
backgroundColor: Colors.white,
),
],
));
}
} catch (e) {
return Container(
alignment: Alignment.center,
child: Text(
"Failed to load Page!!",
style: TextStyle(
color: Colors.black,
fontSize: 15.0,
fontFamily: "WorkSansSemiBold"),
),
);
}
},
),
SizedBox(
height: 100,
)
]),
]),
),
));
}
这是我的下拉小部件,它无法正常工作。 IT项目不映射。
Widget _dropdownPending() => DropdownButton(
icon: Icon(Icons.arrow_drop_down),
iconSize: 19,
elevation: 14,
style: TextStyle(
color: Colors.black54, fontSize: 19, fontFamily: "WorkSansMedium"),
hint: Text(
"Select Pending Reason",
style: TextStyle(
color: Colors.grey, fontSize: 15, fontFamily: "WorkSansMedium"),
),
items: datalist.map((list) {
debugger();
return DropdownMenuItem(
child: Text(list['reason']),
value: list['reason'],
);
}).toList(),
onChanged: (newVal) {
setState(() {
selectedreason = newVal;
});
},
value: selectedreason,
);
这是未来获得待处理原因的呼吁。该行可以正常工作。
Future<String> _getPendingRsn() async {
try {
var url = Uri.parse(Constant.path + '/DSRTestV3/api_pndng_rsn');
var response = await http.get(url);
// print(response.body);
if (response.statusCode == 200) {
var responseJson = json.decode(response.body);
print(responseJson);
setState(() {
datalist = responseJson;
});
print(datalist);
return responseJson;
} else {
throw Exception('Failed to load page');
}
} catch (e) {
throw Exception(e.toString());
}
}
}
这是获得待处理的原因项目的类。
class Pend_rsnitem {
final String reason;
Pend_rsnitem({
this.reason,
});
factory Pend_rsnitem.fromJson(Map<String, dynamic> json) {
return Pend_rsnitem(
reason: json['reason'],
);
}
Map<String, dynamic> toJson(){
final Map<String, dynamic> data = new Map<String, dynamic>();
data['reason'] = this.reason;
return data;
}
}
I am trying to get dropdown list from rest api but getting this error Exception: type '_InternalLinkedHashMap<String, dynamic>' is not a subtype of type 'List'. How can solve this error and get my list of reasons on the screen. my dropdown is not working properly.
console screen:
{Result: Success, Remarks: Records Found Successfully, data: [{reason: DOOR LOCKED}, {reason:
CUSTOMER NOT INTERESTED}, {reason: DEFECTIVE SPARES}, {reason: NO WATER SUPPLY TO CHECK},
{reason: PROBLEM NOT UNDERSTOOD}, {reason: NO ELECTRICITY WHEN VISITED },
{reason: RESCHEDULED VISIT}, {reason: CUSTOMER UN-AWARE OF COMPLAINT LODGED}, {reason: SPARES
UN-AVAILABLE DURING VISIT}, {reason: SPARES UN-AVAILABLE HENCE NOT VISITED}, {reason: CALL
CLOSED BUT OPEN IN SYSTEM}]}
E/flutter (21266): [ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception:
Exception: type '_InternalLinkedHashMap<String, dynamic>' is not a subtype of type
'List<dynamic>'
E/flutter (21266): #0 CustomerDetailsOTCoPageState._getPendingRsn
package:zero_b/Options/customerdetailsOTCo_sp.dart:852
E/flutter (21266): <asynchronous suspension>
E/flutter (21266):
this is my main class for dropdown button .
class CustomerDetailsOTCoPageState extends State<CustomerDetailsOTCoPage>
with AutomaticKeepAliveClientMixin<CustomerDetailsOTCoPage> {
final GlobalKey<ScaffoldState> _scaffoldKey = new GlobalKey<ScaffoldState>();
List datalist = List();
String selectedreason;
@override
void initState() {
super.initState();
this._getPendingRsn();
}
@override
Widget build(BuildContext context) {
return Scaffold(
key: _scaffoldKey,
body: WillPopScope(
onWillPop: _onBackPressed,
child: SingleChildScrollView(
child: Container(
width: MediaQuery.of(context).size.width,
height: MediaQuery.of(context).size.height,
child: Column(children: <Widget>[
Container(
margin: EdgeInsets.only(
top: 2,
bottom: 4,
left: 8,
right: 8,
),
padding: EdgeInsets.only(
top: 2,
bottom: 4,
left: 8,
right: 8,
),
child: Row(children: <Widget>[
Text("Result : ",
style: TextStyle(
fontFamily: "WorkSansMedium",
color: Colors.black,
fontSize: 15,
)),
DropdownButton<String>(
value: dropdownValue,
icon: Icon(Icons.arrow_drop_down),
iconSize: 19,
elevation: 14,
style: TextStyle(
color: Colors.black,
fontSize: 15,
fontFamily: "WorkSansMedium"),
onChanged: (String data) {
setState(() {
dropdownValue = data;
});
},
items: spinnerItems
.map<DropdownMenuItem<String>>((String value) {
return DropdownMenuItem<String>(
value: value,
child: Text(value),
);
}).toList(),
),
]),
),
dropdownValue == 'Pending'
? _dropdownPending()
: Column(children: <Widget>[
FutureBuilder<Result>(
future: apiWorkComplete(),
builder: (context, snapshot) {
try {
if (snapshot.connectionState ==
ConnectionState.done) {
if (snapshot.hasError) {
return Container(
alignment: Alignment.center,
child: Text(
"Failed to load Page",
style: TextStyle(
color: Colors.black,
fontSize: 15.0,
fontFamily: "WorkSansMedium"),
),
);
} else if (snapshot.hasData &&
snapshot.data != null) {
return _workCompleteList(snapshot);
} else {
return Center(
child: Column(
children: <Widget>[
SizedBox(
height: 100,
),
CircularProgressIndicator(
backgroundColor: Colors.white,
),
],
));
}
} else {
return Center(
child: Column(
children: <Widget>[
SizedBox(
height: 100,
),
CircularProgressIndicator(
backgroundColor: Colors.white,
),
],
));
}
} catch (e) {
return Container(
alignment: Alignment.center,
child: Text(
"Failed to load Page!!",
style: TextStyle(
color: Colors.black,
fontSize: 15.0,
fontFamily: "WorkSansSemiBold"),
),
);
}
},
),
SizedBox(
height: 100,
)
]),
]),
),
));
}
here is my dropdown widget which is not working properly . it items not map.
Widget _dropdownPending() => DropdownButton(
icon: Icon(Icons.arrow_drop_down),
iconSize: 19,
elevation: 14,
style: TextStyle(
color: Colors.black54, fontSize: 19, fontFamily: "WorkSansMedium"),
hint: Text(
"Select Pending Reason",
style: TextStyle(
color: Colors.grey, fontSize: 15, fontFamily: "WorkSansMedium"),
),
items: datalist.map((list) {
debugger();
return DropdownMenuItem(
child: Text(list['reason']),
value: list['reason'],
);
}).toList(),
onChanged: (newVal) {
setState(() {
selectedreason = newVal;
});
},
value: selectedreason,
);
here is the future call for getting the pending reason. which works fine with this line of code.
Future<String> _getPendingRsn() async {
try {
var url = Uri.parse(Constant.path + '/DSRTestV3/api_pndng_rsn');
var response = await http.get(url);
// print(response.body);
if (response.statusCode == 200) {
var responseJson = json.decode(response.body);
print(responseJson);
setState(() {
datalist = responseJson;
});
print(datalist);
return responseJson;
} else {
throw Exception('Failed to load page');
}
} catch (e) {
throw Exception(e.toString());
}
}
}
here is the class of getting pending reason item.
class Pend_rsnitem {
final String reason;
Pend_rsnitem({
this.reason,
});
factory Pend_rsnitem.fromJson(Map<String, dynamic> json) {
return Pend_rsnitem(
reason: json['reason'],
);
}
Map<String, dynamic> toJson(){
final Map<String, dynamic> data = new Map<String, dynamic>();
data['reason'] = this.reason;
return data;
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论