Created
October 20, 2020 14:31
-
-
Save vignarajj/68e7cd946ff64ec9b3be5caa9e35bb6c to your computer and use it in GitHub Desktop.
Size configuration of flutter
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/widgets.dart'; | |
class Sizes { | |
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; | |
//for font sizing | |
static double verySmall; | |
static double small; | |
static double medium; | |
static double large; | |
static double xlarge; | |
static double xxlarge; | |
static double heading; | |
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; | |
verySmall = blockSizeHorizontal * 3; | |
small = blockSizeHorizontal * 3.5; | |
medium = blockSizeHorizontal * 4; | |
heading = blockSizeHorizontal * 4.5; | |
large = blockSizeHorizontal * 5; | |
xlarge = blockSizeHorizontal * 6; | |
xxlarge = blockSizeHorizontal * 7; | |
} | |
} | |
void hideKeyboard(BuildContext context) { | |
FocusScope.of(context).unfocus(); | |
} | |
Size screenSize(BuildContext context) { | |
return MediaQuery.of(context).size; | |
} | |
double screenHeight(BuildContext context, | |
{double dividedBy = 1, double reducedBy = 0.0}) { | |
return (screenSize(context).height - reducedBy) / dividedBy; | |
} | |
double screenWidth(BuildContext context, | |
{double dividedBy = 1, double reducedBy = 0.0}) { | |
return (screenSize(context).width - reducedBy) / dividedBy; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment