Skip to content

Instantly share code, notes, and snippets.

@marcos-bah
Created June 18, 2020 13:44
Show Gist options
  • Save marcos-bah/62e2f507a1861f9a640c5f757d3ce9bb to your computer and use it in GitHub Desktop.
Save marcos-bah/62e2f507a1861f9a640c5f757d3ce9bb to your computer and use it in GitHub Desktop.
Classe para posicionar elementos no Flutter
import 'package:flutter/widgets.dart';
class SizeConfig {
static MediaQueryData _mediaQueryData;
static double screenWidth;
static double screenHeight;
static double blockSizeHorizontal;
static double blockSizeVertical;
static double _safeAreaHorizontal;
static double _safeAreaVertical;
static double safeBlockHorizontal;
static double safeBlockVertical;
void init(BuildContext context) {
_mediaQueryData = MediaQuery.of(context);
screenWidth = _mediaQueryData.size.width;
screenHeight = _mediaQueryData.size.height;
blockSizeHorizontal = screenWidth / 100;
blockSizeVertical = screenHeight / 100;
_safeAreaHorizontal =
_mediaQueryData.padding.left + _mediaQueryData.padding.right;
_safeAreaVertical =
_mediaQueryData.padding.top + _mediaQueryData.padding.bottom;
safeBlockHorizontal = (screenWidth - _safeAreaHorizontal) / 100;
safeBlockVertical = (screenHeight - _safeAreaVertical) / 100;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment