Skip to content

Instantly share code, notes, and snippets.

@slightfoot
Created January 30, 2020 14:12
Show Gist options
  • Save slightfoot/20882841df46bd952a45d668a6c79e37 to your computer and use it in GitHub Desktop.
Save slightfoot/20882841df46bd952a45d668a6c79e37 to your computer and use it in GitHub Desktop.
getMaxActionButtons for Flutter/Dart
import 'package:flutter/material.dart';
int getMaxActionButtons(BuildContext context) {
final mediaQuery = MediaQuery.of(context);
final width = mediaQuery.size.width;
final height = mediaQuery.size.height;
final smallest = mediaQuery.size.shortestSide;
if (smallest > 600 || (width > 960 && height > 720) || (width > 720 && height > 960)) {
// For values-w600dp, values-sw600dp and values-xlarge.
return 5;
} else if (width >= 500 || (width > 640 && height > 480) || (width > 480 && height > 640)) {
// For values-w500dp and values-large.
return 4;
} else if (width >= 360) {
// For values-w360dp.
return 3;
} else {
return 2;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment