'Code being marked as dead in if/else statement
I am building a WiFi app for an IoT device, I am generating a list of WiFi networks, and what I would like to accomplish is when the SSID is pressed it changes to a connect button.
Widget TestSSID(String ssid, String bssid) {
autoUpdate = false;
var isClicked = false;
if (!isClicked) {
return TableCell(
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
TextButton(
onPressed: () async {
setState(() {
isClicked = true;
});
},
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(ssid,
style: TextStyle(
fontSize: 20.0,
fontWeight: FontWeight.bold,
color: Colors.cyan[900]
),),
],
)),
],
),
);
} else {
return TableCell(
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
ConnectButton(ssid, bssid),
],
),
);
}
}
The code in the else statement is not executing properly, the SSID is not doing anything when pressed. The else code is being marked as dead in android studio.
The list of WiFi networks is being built using FutureBuilder, not sure the implementation is correct to accomplish what I want.
Any help is appreciated, thank you!
Solution 1:[1]
The work around was using a class instead of a function, and making isClicked global to the class.
Solution 2:[2]
You need to move the isClicked variable out of the function.
Here is the sample code.
class _MyAppState extends State<MyApp> {
bool isClicked = false;
Widget TestSSID(String ssid, String bssid) {
...
}
...
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | kbessemer |
| Solution 2 | MaNDOOoo |
