Getting error when trying to set min width using ButtonTheme


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))


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() { ... }

Answered By – Günter Zöchbauer

Answer Checked By – Cary Denson (FlutterFixes Admin)

Leave a Reply

Your email address will not be published. Required fields are marked *