【发布时间】:2020-10-25 14:53:07
【问题描述】:
我想从主页导航到登录页面。我已经实现了一些代码。但这是行不通的。运行代码时出现错误。 MaterialPageRoute(builder: (context) => LoginPage()));此行出现错误。无论我尝试了多少次,我都无法解决这个问题。这是完整的代码段。
return Scaffold(
appBar: new AppBar(
title: new Text("Home"),
backgroundColor: Colors.grey[500],
actions: <Widget>[
PopupMenuButton<String>(
child: Container(
width: 63,
height: 63,
child: alucard,
),
onSelected: (value) {
if(value == Constants.logout){
Navigator.pushReplacementNamed(
context,
MaterialPageRoute(builder: (context) => LoginPage()));
}
},
itemBuilder: (BuildContext context) {
return Constants.choices.map((String choice){
return PopupMenuItem<String>(
value: choice,
child: Text(choice),
);
}).toList();
},
)
],
),
backgroundColor: Colors.grey[800],
body: body,
drawer: AppDrawer(value:this.value),
);
这是发生的错误。
{
"resource": "/d:/3rd Year/Group Project II/CrickDom/SLCricketLeaderBoad_MoblieApp/crick_dom/lib/home.dart",
"owner": "dart",
"code": {
"value": "argument_type_not_assignable",
"target": {
"$mid": 1,
"external": "https://dart.dev/tools/diagnostic-messages#argument_type_not_assignable",
"path": "/tools/diagnostic-messages",
"scheme": "https",
"authority": "dart.dev",
"fragment": "argument_type_not_assignable"
}
},
"severity": 8,
"message": "The argument type 'MaterialPageRoute<dynamic>' can't be assigned to the parameter type 'String'.",
"source": "dart",
"startLineNumber": 84,
"startColumn": 21,
"endLineNumber": 84,
"endColumn": 73,
"tags": []
}
这是我的 Flutter 医生结果。
Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel stable, v1.17.3, on Microsoft Windows [Version 10.0.18362.900], locale en-US)
[√] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
[√] Android Studio (version 3.6)
[√] VS Code (version 1.46.1)
[√] Connected device (1 available)
• No issues found!
谁能帮我解决这个问题?
【问题讨论】: