2

I am trying to set minWidth in ButtonTheme. I am getting following error:

Error: Getter not found: 'context'.
compiler message:     minWidth: MediaQuery.of(context).size.width-40,

For reference I am sharing code here:

final resetButton = ButtonTheme(
    minWidth: MediaQuery.of(context).size.width-40,
    height: 50.0,
    child: new RaisedButton(
        color: blueColor,
        onPressed: (){
//          Navigator.of(context).pushNamed(Home.tag);
        },
        child: Text('Log In',
          style: styleLoginButton,
        ),
        shape: new RoundedRectangleBorder(borderRadius: new BorderRadius.circular(30.0))
    ),
  );
Code Hunter
  • 10,075
  • 23
  • 72
  • 102

1 Answers1

1

You can't use MediaQuery.of(context) when there is no context. Either pass context when you call this code from build(BuildContext context) { ... } or move the code to build() { ... }

Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567