Skip to content

Instantly share code, notes, and snippets.

@rodydavis
Last active December 7, 2021 14:53
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rodydavis/2ae31e1c61a865ef2ea0bb567beb5f20 to your computer and use it in GitHub Desktop.
Save rodydavis/2ae31e1c61a865ef2ea0bb567beb5f20 to your computer and use it in GitHub Desktop.
Flutter Device Based On BoxConstraints
import 'package:flutter/material.dart';
const kTabletSize = Size(500, 700);
const kTabletBreakpoint = 720.0;
const kDesktopBreakpoint = 1200.0;
enum DeviceSize { mobile, tablet, desktop }
extension LayoutUtils on BoxConstraints {
DeviceSize get device {
if (this.maxWidth >= kDesktopBreakpoint) {
return DeviceSize.desktop;
}
if (this.maxWidth >= kTabletBreakpoint) {
return DeviceSize.tablet;
}
return DeviceSize.mobile;
}
}
@Gerald-97
Copy link

I'm new to flutter, please can I get a sample use case for this? How to apply it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment