Reputation: 348
I have a widget and I want it to have a specific space from the edge of the screen, according to screen size. I have already tried MediaQuery
but that is not helpful. Because I want to have a space according to resolution. Here is what I have tried :
MediaQuery.of(context).size.width - 50,
And here is what I'm trying to do
How I'm gonna do that?
Upvotes: 2
Views: 661
Reputation: 1135
You can store width of screen to field to use it easily anywhere. And to have dynamic spaces, you can doing like Hamza says in comments:
double mWidth;
@override
Widget build(BuildContext context) {
mWidth= MediaQuery.of(context).size.width;
return Scaffold(
body: Container(
width: mWidth,
margin: EdgeInsets.all(mWidth * 0.01),
),
);
}
Upvotes: 3