I need help about flatButton

66 views Asked by At
Widget build(BuildContext context) {
    return Expanded(
      child: Container(
        alignment: Alignment.center,
        child: FlatButton(
          color: (buttons == EQUAL_SIGN)
              ? Theme.of(context).primaryColor
              : Color(0xFFFFFFFF),
          padding: EdgeInsets.symmetric(vertical: 10.0),
          child: Text(
            buttons,
            style: TextStyle(
                color: (_colorTextButtons())
                    ? Colors.blueAccent
                    : (buttons == EQUAL_SIGN)
                        ? Theme.of(context).buttonColor
                        : Color(0xFF444444),
                fontSize: _fontSize() ? 18 : 20.0),
          ),
          onPressed: () => onTap(buttonText: buttons),
        ),
      ),
    );
  }
}

I try to replace with TextButton but nothing.

Widget build(BuildContext context) {
    return Expanded(
      child: Container(
        alignment: Alignment.center,
        child: TextButton(
          color: (buttons == EQUAL_SIGN)
              ? Theme.of(context).primaryColor
              : Color(0xFFFFFFFF),
          padding: EdgeInsets.symmetric(vertical: 10.0),
          child: Text(
            buttons,
            style: TextStyle(
                color: (_colorTextButtons())
                    ? Colors.blueAccent
                    : (buttons == EQUAL_SIGN)
                        ? Theme.of(context).buttonColor
                        : Color(0xFF444444),
                fontSize: _fontSize() ? 18 : 20.0),
          ),
          onPressed: () => onTap(buttonText: buttons),
        ),
      ),
    );
  }
}
2

There are 2 answers

0
Md. Yeasin Sheikh On

We don't have any FlatButton on the current version of Flutter. You can use TextButton.

enter image description here

Find more about this breaking-changes/buttons.

2
Stanly On

You can change the flatButton into some other button like textButton; it is due to update of Flutter that made the flatButton can't be used anymore.

Here is the example of simple usage textButton:

 TextButton(
     style: TextButton.styleFrom(
        textStyle: const TextStyle(fontSize: 20),
     ),
     onPressed: null,
        child: const Text('Disabled'),
     ),