yo guys i'll try to change text at button when clicked on...
my code :
bool pressGeoON = false;
bool cmbscritta = false;
RaisedButton(
shape: new RoundedRectangleBorder(
borderRadius: new BorderRadius.circular(18.0),
side: BorderSide(color: Colors.red)),
color: pressGeoON ? Colors.blue: Colors.red,
textColor: Colors.white,
child: cmbscritta ? Text("GeoOn"): Text("GeoOFF"),
// style: TextStyle(fontSize: 14)
onPressed: () {
setState(() => pressGeoON = !pressGeoON);
setState(() => cmbscritta = !cmbscritta);
},
)
No advice from dart Analisys but not work...help!
your class must be stateful to change state of activity
also the variable must be declared globally
class MyClass extends StatefulWidget {
@override
_MyClassState createState() => _MyClassState();
}
class _MyClassState extends State<MyClass> {
bool pressGeoON = false;
bool cmbscritta = false;
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: RaisedButton(
shape: new RoundedRectangleBorder(
borderRadius: new BorderRadius.circular(18.0),
side: BorderSide(color: Colors.red)),
color: pressGeoON ? Colors.blue : Colors.red,
textColor: Colors.white,
child: cmbscritta ? Text("GeoOn") : Text("GeoOFF"),
// style: TextStyle(fontSize: 14)
onPressed: () {
setState(() {
pressGeoON = !pressGeoON;
cmbscritta = !cmbscritta;
});
}
),
),
);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With