Search code examples
flutterflutter-layoutscreen-orientationdart-null-safety

The argument type 'BoxConstraints' can't be assigned to the parameter type 'BuildContext'


I Hello, I need help in my code, why I am getting this error, I copied the code from another project but there is no error there.

@override
 Widget build(BuildContext context) {
dynamic screenWidth = MediaQuery.of(context).size.width;
dynamic screenHeight = MediaQuery.of(context).size.height;
ScreenUtil.init(
    BoxConstraints(maxWidth: screenWidth, maxHeight: screenHeight),
    designSize: const Size(360, 690),
    orientation: Orientation.portrait);

return Scaffold(

enter image description here


Solution

  • ScreenUtil.init's 1st argument is of type BuildContext.

        ScreenUtil.init(
          context,
          deviceSize: Size(screenWidth, screenHeight),
          designSize: const Size(360, 690),
          orientation: Orientation.portrait,
        );