Skip to content

Instantly share code, notes, and snippets.

@Lecarvalho
Created December 5, 2019 08:19
Show Gist options
  • Save Lecarvalho/7561199ba457b162f2e471c670926959 to your computer and use it in GitHub Desktop.
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.
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