Closed Haidar0096 closed 1 year ago
I checked again, there is no await in this method. try future.then plz.
When designing, we did not consider that the same application will have different design ratios, so every time init is called, the ratio of this application will be changed to the latest, so every time you enter the page and call init, it will change the screen size Suitable size
@lizhuoyuan maybe there is a misunderstanding.
First, thanks for this package it is a life saver.
What I mean is that ScreenUtil.init
method, that we should call inside build method to update the library's parameters, returns a Future
, and inside build
we can't await
this Future
. This is not a good pattern in flutter, as Future
s should be awaited, and if you don't need an async method, then why declare it to return a Future
?
Here is the ScreenUtil
function from your package:
/// Initializing the library.
static Future<void> init(
BuildContext context, {
Size designSize = defaultSize,
bool splitScreenMode = false,
bool minTextAdapt = false,
bool scaleByHeight = false
})
{
...
}
You can see it returns a future.
The package works perectly fine for now, but if you can remove the Future if it is not needed and replace it with void
, this would be better
@Haidar0096 @haidarmehsen , it can be used as future for FutureBuilder. Next release will clarify the usage.
This issue is stale because it has been open for 30 days with no activity.
If I understand correctly, if I have a figma design with, say, 2 different screen dimensions, screen1 and screen2, then to map it to flutter, I need to call
and
Now there are two questions: 1-
build
method cannotawait
forFutures
, and this methodScreenUtil.init
returns aFuture
, so is this intended or a bug? If a function returns a future then I expect to await it if my code that follows it depends on its result, which is the case here.2- Is this the correct way to support different design sizes in figma?
To give you an example about point 2, this is a sample of what I want to achieve (suppose
Widget1
represents a figma screen1 andWidget2
represents figma screen2):