flutter constants class with flutter_screenutil

Viewed 24

i`m using contants class for common things.

like

//define
class AppSpacing{
    static const top20bottom20Left10 = EdgeInsets.only(top:20, bottom:20, left: 10);
  ...
}

//using
Container(
   margin: AppSpacing.top20bottom20Left10
...
}

but suddenly the day comes, i must use flutter_screenutil..

ScreenUtilInit(
    designSize: const Size(750, 1622),
    builder: (context, child){
        return MaterialApp(
            title: 'Flutter Demo',
            debugShowCheckedModeBanner: false,
            theme: ThemeData(
               primarySwatch: Colors.blue,
            ),
            home: child,
        );
    },
    child: MyHomePage(title: 'Flutter Demo Home Page'),
),

But, when i use like below, there`s not working what i want.

class AppSpacing{
    static final EdgeInsets top20bottom20Left10 = EdgeInsets.only(top:20.h, bottom:20.h, left: 50.w);
}

I think that the problem is AppSpacing class is not in ScreenUtil widget.

Is there way to apply other class in ScreenUtil Widget?

1 Answers

can't because it's called outside the screen utils widget.

Alternatively, you can use the static get method

// define
class AppSpacing{
    static get top20bottom20Left10 => EdgeInsets.only(top:20.h, bottom:20.h, left: 50.w);
}

// use
Container(
   margin: AppSpacing.top20bottom20Left10

}
Related