问题描述
对不起各位,我试图建立一个新页面,但其中包含变量“nextcode”。所以在新页面中,它将显示nextcode文本
onTap: () {
Navigator.push(
context,MaterialPageRoute(
builder: (context) => Lemari(nextcode)));
},
但是在“Widget build(String Kode) {”行中,它必须是这样的“Widget build(BuildContext context) {”
class Lemari extends StatelessWidget {
@override
Widget build(String Kode) {
return Scaffold(
appBar: AppBar(
backgroundColor: Colors.blue[900],title: Text('this is th next page'),),backgroundColor: Colors.white,body: Center(
child: Column(
children: [
Container(height: 100,width: 100,color: Colors.red,child: Text('hhe'),]
),);
}
}
有谁能帮帮我吗?请:(
解决方法
您不必更改构建方法参数,而是应该在小部件中添加一个新参数并要求它
示例 const MyPageView({Key? key}) : super(key: key);
在这里您可以添加另一个参数。 然后在类中定义该参数..所以当你创建一个新的 MyPageView 时,你必须传递新添加的参数
再见:)
,你的代码应该有一个编译器错误
在 Lemari
中,您永远不会声明 nextcode
并且构造函数也没有参数 nextcode
。
你可以这样试试,添加
class Lemari extends StatelessWidget {
final String nextcode;
const Lemari({Key key,this.nextcode}) : super(key: key);
@override
Widget build(BuildContext context) {}
}
如果您的 nextcode
是 String