Showing
1 changed file
with
10 additions
and
18 deletions
| 1 | import 'package:flutter/material.dart'; | 1 | import 'package:flutter/material.dart'; |
| 2 | import 'package:flutter/widgets.dart'; | 2 | import 'package:flutter/widgets.dart'; |
| 3 | - | 3 | +import 'package:collection/collection.dart'; |
| 4 | import '../platform/platform.dart'; | 4 | import '../platform/platform.dart'; |
| 5 | 5 | ||
| 6 | extension ContextExtensionss on BuildContext { | 6 | extension ContextExtensionss on BuildContext { |
| @@ -120,30 +120,22 @@ extension ContextExtensionss on BuildContext { | @@ -120,30 +120,22 @@ extension ContextExtensionss on BuildContext { | ||
| 120 | /// if the device width is less than 300 return [watch] value. | 120 | /// if the device width is less than 300 return [watch] value. |
| 121 | /// in other cases return [mobile] value. | 121 | /// in other cases return [mobile] value. |
| 122 | T responsiveValue<T>({ | 122 | T responsiveValue<T>({ |
| 123 | + T? watch, | ||
| 123 | T? mobile, | 124 | T? mobile, |
| 124 | T? tablet, | 125 | T? tablet, |
| 125 | T? desktop, | 126 | T? desktop, |
| 126 | - T? watch, | ||
| 127 | }) { | 127 | }) { |
| 128 | var deviceWidth = mediaQuerySize.shortestSide; | 128 | var deviceWidth = mediaQuerySize.shortestSide; |
| 129 | if (GetPlatform.isDesktop) { | 129 | if (GetPlatform.isDesktop) { |
| 130 | deviceWidth = mediaQuerySize.width; | 130 | deviceWidth = mediaQuerySize.width; |
| 131 | } | 131 | } |
| 132 | - if (deviceWidth >= 1200) { | ||
| 133 | - if (desktop != null) { | ||
| 134 | - return desktop; | ||
| 135 | - } | ||
| 136 | - } | ||
| 137 | - if (deviceWidth >= 600) { | ||
| 138 | - if (tablet != null) { | ||
| 139 | - return tablet; | ||
| 140 | - } | ||
| 141 | - } | ||
| 142 | - if (deviceWidth >= 300) { | ||
| 143 | - if (mobile != null) { | ||
| 144 | - return mobile; | ||
| 145 | - } | ||
| 146 | - } | ||
| 147 | - return watch!; | 132 | + //big screen width can display smaller sizes |
| 133 | + final values = [ | ||
| 134 | + if (deviceWidth >= 1200) desktop, //desktop is allowed | ||
| 135 | + if (deviceWidth >= 600) tablet, //tablet is allowed | ||
| 136 | + if (deviceWidth >= 300) mobile, //mobile is allowed | ||
| 137 | + watch, //watch is allowed | ||
| 138 | + ]; | ||
| 139 | + return values.whereType<T>().first; | ||
| 148 | } | 140 | } |
| 149 | } | 141 | } |
-
Please register or login to post a comment