Last active
December 7, 2021 14:53
-
-
Save rodydavis/2ae31e1c61a865ef2ea0bb567beb5f20 to your computer and use it in GitHub Desktop.
Flutter Device Based On BoxConstraints
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/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; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'm new to flutter, please can I get a sample use case for this? How to apply it.