Last active
May 1, 2020 16:54
-
-
Save ruan65/1d9f5ff14d857ba20475fce9c96ef929 to your computer and use it in GitHub Desktop.
Flutter UI Helpers
This file contains hidden or 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'; | |
abstract class ScreenSize { | |
static Size size(BuildContext context) { | |
return MediaQuery.of(context).size; | |
} | |
static double height(BuildContext context, | |
{double dividedBy = 1, double reducedBy = 0.0}) { | |
return (ScreenSize.size(context).height - reducedBy) / dividedBy; | |
} | |
static double width(BuildContext context, | |
{double dividedBy = 1, double reducedBy = 0.0}) { | |
return (ScreenSize.size(context).width - reducedBy) / dividedBy; | |
} | |
static double screenHeightExcludingToolbar(BuildContext context, | |
{double dividedBy = 1}) { | |
return height(context, dividedBy: dividedBy, reducedBy: kToolbarHeight); | |
} | |
static double commonPadding(BuildContext context, {double logicalPadding = 20}) { | |
return ScreenSize.size(context).width * logicalPadding / 375; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment