Skip to content

Instantly share code, notes, and snippets.

@ruan65
Last active May 1, 2020 16:54
Show Gist options
  • Save ruan65/1d9f5ff14d857ba20475fce9c96ef929 to your computer and use it in GitHub Desktop.
Save ruan65/1d9f5ff14d857ba20475fce9c96ef929 to your computer and use it in GitHub Desktop.
Flutter UI Helpers
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