FlatButton different text color while holding

292 views Asked by At

I'm new in Flutter. I want to make a simple example. I want to change color of the flat button while holding. Essentially I did but I'm not sure it's the right way. Isn't there an easier way? For example, could be a property like below;

higlightTextColor: Colors.white

In simple form the codes;

void _showAlertDialog(BuildContext context, Student item) {
showDialog(
  ...
  builder: (context) {
    bool _onHighlight = false;
    return StatefulBuilder(
      builder: (context, setState) {
        return AlertDialog(
          ...,
          content: Text(
            item._description + _onHighlight.toString(),
          ),
          actions: <Widget>[
            FlatButton(
              child: Text(
                'Okay',
              ),
              onPressed: () {},
              color: Colors.transparent,
              textColor: _onHighlight ? Colors.white : Colors.amber,
              splashColor: Colors.amber,
              shape: RoundedRectangleBorder(
                  side: BorderSide(
                      color: Colors.amber,
                      width: 1,
                      style: BorderStyle.solid)),
              onHighlightChanged: (value) {
                setState(() {
                  _onHighlight = value;
                });
              },
              // hoverColor: Colors.amber,
            ),
          ],
        );
      },
    );
  },
);

}

0

There are 0 answers