Error: The method 'init' isn't defined for the class 'SizerUtil'

215 views Asked by At

I am running an older Flutter project and have recently upgraded my pubspec.yaml file. It is giving a compile error.

 Error: The method 'init' isn't defined for the class 'SizerUtil'

When I tried to look inside the class SizerUtil, which is a part of the library sizer and inside utils.dart, I am unable to find any init method inside it.

My Code, where I am getting the error in main.dart:

OrientationBuilder(
          builder: (context,orientation){
            SizerUtil().init(constraints, orientation); // this line gives error
            return MaterialApp(
              debugShowCheckedModeBanner: false,
              theme: _appTheme(base),
              initialRoute: RoutingConstants.gatewayScreen,
              onGenerateRoute: RouterPage.ongenerateRoute,
            );
          },
        );
1

There are 1 answers

0
Sweta Jain On

Method init has been removed from the library and has been replaced with the setScreenMethod().

Inside class SizerUtil ->

  /// Sets the Screen's size and Device's Orientation,
  /// BoxConstraints, Height, and Width
  static void setScreenSize(
      BoxConstraints constraints, Orientation currentOrientation) {
    // Sets boxconstraints and orientation
    boxConstraints = constraints;
    orientation = currentOrientation;

Replace the code with this:

OrientationBuilder(
          builder: (context, orientation) {
            SizerUtil.setScreenSize(constraints, orientation);  // method changed
            return MaterialApp(
              debugShowCheckedModeBanner: false,
              theme: _appTheme(base),
              initialRoute: RoutingConstants.gatewayScreen,
              onGenerateRoute: RouterPage.ongenerateRoute,
            );
          },
        );