Reputation: 799
Firstly, I am sorry for my poor english.
I am trying success to extract a very complex widget as package and use it on different projects. For this reason, I need to use ScreenUtil package (for responsive design.) in that widget-package.
So in the end, I succeed the extract my widget as a package but I am confused some point because as you know, screen_util package requires to be initialized like;
ScreenUtilInit(
designSize: const Size(750, 1334),
builder: () => const MyApp(),
)
So my question, how can I success to initialize the screen_util package correctly for my usage ? (I don't have any builder function because my widgets created like class MyWidget extends SizedBox(important not like stateless or statefull widget!)) so,
I added a function for initializing operation like ;
void myComponentInitializer({
required BuildContext context
}){
ScreenUtil.init(
BoxConstraints(
maxWidth: MediaQuery.of(context).size.width,
maxHeight: MediaQuery.of(context).size.height
),
context: context,
designSize: const Size(750, 1334),
minTextAdapt: true
);
ScreenUtil.setContext(context);
}
and before using the package, I am calling that function but I can't be sure, is it a best way to initialize screen_util for my widget or not. If it is not the right way, can you show me the right way ?
So I am open any idea for this.
Thanks a lot.
Upvotes: 3
Views: 4408
Reputation: 1746
I think that the builder
Generally returning a Function of MaterialApp type
,
Widget build(BuildContext context) {
return ScreenUtilInit(
designSize: Size(360, 690),
minTextAdapt: true,
splitScreenMode: true,
builder: () =>
MaterialApp()
Upvotes: 0
Reputation: 2435
You just initialise your screen utils on your first page/screen or your initial route. You can initialise it inside your init() method of your stateful widget or initialise it inside your build() function of your stateless widget. Hope this is clear.
Upvotes: 1