Created
December 5, 2019 08:19
-
-
Save Lecarvalho/7561199ba457b162f2e471c670926959 to your computer and use it in GitHub Desktop.
A class to help in adaptation of the sizes for widgets, texts, images, etc, on different screen sizes. In my case it uses a base designWidth = 411 because this is the width for my device used for development. Check yours with your designer or in your sketch / prototype.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
class DynamicSize { | |
MediaQueryData _mediaQuery; | |
static const double _designWidth = 411; | |
DynamicSize._constructor(); | |
static final DynamicSize instance = DynamicSize._constructor(); | |
init(BuildContext context){ | |
_mediaQuery = MediaQuery.of(context); | |
} | |
double fromWidth(double width){ | |
var scaleWidth = _mediaQuery.size.width / _designWidth; | |
var res = width * scaleWidth; | |
return res; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment