我想更改我的收藏圖示是否推入它,但它沒有發生,因為我無法使用 int 值來控制它。這是我的代碼示例=>
class _WebViewExampleState extends State<WebViewExample> {
final Completer<WebViewController> _controller = Completer<WebViewController>();
int ctr=0;
...
floatingActionButton: favoriteButton(),
...
Widget favoriteButton() {
return FutureBuilder<WebViewController>(
future: _controller.future,
builder: (BuildContext context,
AsyncSnapshot<WebViewController> controller) {
if (controller.hasData) {
return FloatingActionButton(
backgroundColor: Colors.indigo,
onPressed: () async {
final String url = (await controller.data!.currentUrl())!;
// ignore: deprecated_member_use
Scaffold.of(context).showSnackBar(
SnackBar(content: Text('Favorited $url')),
);
setState(() {
ctr ;
});
},
child: const Icon(Icons.favorite,
<this place where i got the mistake>
color: this.ctr%2==1 ? Colors.red : Colors.white),
</this place where i got the mistake>
);
}
return Container();
});
}
}//end of top row.
我在上面提到了 html 標簽“我出錯的地方”。錯誤是無效的常量值我也嘗試在 favoriteButton 中宣告變數。為什么我不能使用變數來檢查條件?有人幫我嗎?
uj5u.com熱心網友回復:
請從圖示小部件中洗掉 const
請檢查我的代碼
child: Icon(Icons.favorite,
<this place where i got the mistake>
color: this.ctr%2==1 ? Colors.red : Colors.white),
</this place where i got the mistake>
);
這樣做你可以使用可變值
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/453226.html
