下面是我的代碼:
我面臨的問題 => 第一個按鈕也在更新第二個按鈕狀態。
但它應該以不同的方式作業:
first與first,
second與second
我只想使第二個按鈕的狀態獨立于其他按鈕我需要更新什么謝謝,任何建議對我來說都很好
class _LinearProgressBar extends State<LinearProgressBar> {
bool loadingLinear = false;
bool loadingCircular = false;
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text("CheckBox and Radio Button Stateful"),
),
body: Center(
child: Column(
children: [
Container(
child: loadingLinear
? const LinearProgressIndicator()
: const Text("Click to download "),
),
//Here is my first button which reflects the second button state as well
ElevatedButton(
style: ElevatedButton.styleFrom(
primary: Colors.red, // background
onPrimary: Colors.white, // foreground
),
onPressed: () {
setState(() {
// when I click here it also updates the second set state of SecondBtn
loadingLinear = !loadingLinear;
});
},
child: const Text('FirstBtn'),
),
Container(
child: loadingLinear
? CircularProgressBar_()
: const Text("Click to download"),
),
// Here is my second button which doesn't work
ElevatedButton(
style: ElevatedButton.styleFrom(
primary: Colors.red, // background
onPrimary: Colors.white, // foreground
),
onPressed: () {
setState(() {
// this state is not working even on clicking...
loadingCircular = !loadingCircular;
});
},
child: const Text('SecondBtn'),
)
],
),
)));
}
}
uj5u.com熱心網友回復:
我認為您在第二個容器上使用了錯誤的變數,請改用它
Container(
child: loadingCircular // not loadingLinear
? CircularProgressBar_()
: const Text("Click to download"),
),
uj5u.com熱心網友回復:
因為在第二個按鈕中,您loadingCircular在檢查loadingLinear值時更改狀態,,,
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/530393.html
標籤:扑镖颤振布局
上一篇:如何使用來自父小部件的資料傳輸?
