我只有很少的基本代码,但不明白为什么这么说:
“不能将参数类型‘JsObject’分配给参数类型‘BuildContext’。”
我在 stackoverflow 上搜索过,但所有这些都不适用于此类问题。
希望你能帮帮我!!!
class HomePage extends StatelessWidget {
Future addInvoice()async {
var invoice = {
"name":"testname",
"mobile":"testmobile",
"email":"testemail",
"invId":"testinvId",
"amount":"testamount",
"discout":"testdiscount",
"productname":"testproductname",
};
var invoiceresponse = await http.post('https://XYZ/test.php',body: invoice);
if (invoiceresponse.statusCode == 200) {
Navigator.push(context, MaterialPageRoute(builder: (context)=>myPdfViewer(invoiceId: "testinvId",),),);
print(invoiceresponse.body);
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Column(
children: [
RaisedButton(
splashColor: Colors.pinkAccent,
color: Colors.black,
child: new Text(
"Save",
style: new TextStyle(fontSize: 20.0, color: Colors.white),
),
onPressed: () {
addInvoice();
},
)
],
),
);
}
}
答案 0 :(得分:1)
将 BuildContext
传递给您的函数,例如
Future addInvoice(BuildContext context)async ...
并且不要忘记在调用构建函数时将其作为参数传递。