[英]Switch - case in flutter
I dont know why i cant send data of "altMenuIndex" to "degisenMenu()".我不知道为什么我不能将“altMenuIndex”的数据发送到“degisenMenu()”。 When i change inside of switch manually, it works.
当我手动更改开关内部时,它可以工作。 But when i change like "int altMenuIndex = 2", it doesnt work.
但是当我改变像“int altMenuIndex = 2”时,它不起作用。
The codes below show the "default" value.下面的代码显示了“默认”值。
class AltMenuDegistir {
int altMenuIndex = 1;
AltMenuDegistir({this.altMenuIndex});
degisenMenu() {
switch (altMenuIndex) {
case 1:
return Kutuphane();
break;
case 2:
return KitapAra();
break;
case 3:
return TalebeEkle();
break;
case 4:
return TalebeAra();
break;
default:
return Container(
child: Center(
child: Text("Bir şeyler ters gitti!"),
),
);
}
}
}
Probably you are missing the pass altMenuIndex
in constructor可能您在构造函数中缺少传递
altMenuIndex
var x = AltMenuDegistir(altMenuIndex:2);
x.degisenMenu();
var y = AltMenuDegistir(altMenuIndex:3);
y.degisenMenu();
So, why not change the degisenMenu method?那么,为什么不改变 degisenMenu 方法呢?
degisenMenu(altMenuIndex) { // <====== altMenuIndex
switch (altMenuIndex) {
case 1:
return Kutuphane();
break;
case 2:
return KitapAra();
break;
case 3:
return TalebeEkle();
break;
case 4:
return TalebeAra();
break;
default:
return Container(
child: Center(
child: Text("Bir şeyler ters gitti!"),
),
);
}
}
Then call this method through each button with passing appropriate index.然后通过每个按钮调用此方法并传递适当的索引。
For instance, Kutuphane, call it like degisenMenu(1)
etc.例如,Kutuphane,将其
degisenMenu(1)
等。
The default value should be set inside the constructor:默认值应该在构造函数中设置:
int altMenuIndex;
AltMenuDegistir({this.altMenuIndex = 1});
When you call the constructor yo can set the value:当您调用构造函数时,您可以设置值:
AltMenuDegistir(altMenuIndex: 2)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.