juanjoseleca

add function to get responsive value

... ... @@ -431,6 +431,14 @@ context.isLargeTablet()
/// True if the current device is Tablet
context.isTablet()
/// Returns a value according to the screen size
/// can give value for
/// swatch: if the shortestSide is smaller than 300
/// mobile: if the shortestSide is smaller than 600
/// tablet: if the shortestSide is smaller than 1200
/// desktop: if the shortestSide is largest than 1200
context.responsiveValue<T>()
```
### Optional Global Settings and Manual configurations
... ...
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter/foundation.dart';
extension ContextExtensionss on BuildContext {
/// The same of [MediaQuery.of(context).size]
... ... @@ -102,4 +103,27 @@ extension ContextExtensionss on BuildContext {
/// True if the current device is Tablet
bool get isTablet => isSmallTablet || isLargeTablet;
/// Returns a specific value according to the screen size
/// if the device width is higher than or equal to 1200 return [desktop] value.
/// if the device width is higher than or equal to 600 and less than 1200
/// return [tablet] value.
/// if the device width is less than 300 return [watch] value.
/// in other cases return [mobile] value.
T responsiveValue<T>({
T mobile,
T tablet,
T desktop,
T watch,
}) {
double deviceWidth = mediaQuerySize.shortestSide;
if (kIsWeb) {
deviceWidth = mediaQuerySize.width;
}
if (deviceWidth >= 1200 && desktop != null) return desktop;
if (deviceWidth >= 600 && tablet != null) return tablet;
if (deviceWidth < 300 && watch != null) return watch;
return mobile;
}
}
... ...