ScreenUtil parameters are not defined

Issue

I followed an old flutter tutorial
with changing all old dependencies which caused a lot of errors ofc,
I was able to fix all of them only this one:
after changing the version of screenutil from 0.4.2 to 5.0.2
I got this error: (and other errors that I fixed already)

No named parameter with the name 'width'.
ScreenUtil.init(context, width: 750, height: 1334, allowFontScaling: true);

on this line of code

ScreenUtil.init(context, width: 750, height: 1334, allowFontScaling: true);

I’m a newbie in flutter and dart so even after reading the documentation of screenutil 5.0.2 I still don’t understand what changes I have to do to fix the error.
What I undestood after reading the doc is: that the ScreenUtil object doesn’t have width,height and allowFontScaling properties anymore. I think now it takes (designSize, builder, orientation and splitScreenMode).
So I need a way to convert my old line of code

ScreenUtil.init(context, width: 750, height: 1334, allowFontScaling: true);

to a newer one with the newer properties.
help please.

Solution

I just coppied some lines from the documentation and it seems to be working just fine
https://pub.dev/packages/flutter_screenutil

//ScreenUtil.init(context, 750, height: 1334, allowFontScaling: true); 
// == 

    ScreenUtil.init(BoxConstraints(
        maxWidth: MediaQuery.of(context).size.width,
        maxHeight: MediaQuery.of(context).size.height
    ),
    designSize: const Size(750, 1334),
    minTextAdapt: true,
    );

Answered By – AzerSD

Answer Checked By – Mildred Charles (FlutterFixes Admin)

Leave a Reply

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