Итак, я пытаюсь создать стиль, когда человек нажимает кнопку. Он изменит свой цвет, у меня есть отдельная функция, в которой создаются кнопки, поэтому я вызываю эту функцию для их создания. Но когда я передал переменную bool, основная функция, кажется, не принимает эту переменную (bool). Он остается подсвеченным красным и дает мне это. Сеттер pressed
не определен для класса _HomeState
Вот функция кнопки создания:
class CustomButton extends StatefulWidget {
// define this parameters as you will need them
final Function onPressed;
final IconData icon;
final String text;
final String text2;
// define a constructor for the class custom button
CustomButton({this.onPressed, this.icon, this.text, this.text2});
@override
_CustomButtonState createState() => _CustomButtonState();
}
class _CustomButtonState extends State<CustomButton> {
@override
Widget build(BuildContext context) {
return ClipRRect(
borderRadius: BorderRadius.circular(10),
child: SizedBox(
width: 90.0,
height: 90.0,
child: RaisedButton(
// remove the default padding the raised button has
padding: EdgeInsets.zero,
onPressed: () {},
color: Colors.grey,
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
Row(
children: <Widget>[
Padding(
padding: EdgeInsets.only(top: 5, right: 25, bottom: 10),
child: Icon(
widget.icon,
size: 35,
),
),
Padding(
padding: EdgeInsets.only(
top: 0, right: 0, bottom: 20, left: 0),
child: new Text(
widget.text,
),
),
],
),
Padding(
padding: EdgeInsets.only(top: 8, right: 17),
child: Text(
widget.text2,
style: TextStyle(fontSize: 13),
),
),
],
),
),
),
);
}
}
Вот основная функция, когда я вызвать CustomButton ():
CustomButton(
icon: Icons.lightbulb_outline,
text: 'On',
text2: 'Lâmpada 1\nSchuma',
pressed: false,
style: pressed ?
TextStyle(fontSize: 30.0) :
TextStyle(fontSize: 10.0),
onPressed: () => (){
setState(() {
pressed = !pressed; <- THis stay highlighted in red
});
},
),