Toggle navigation
Toggle navigation
This project
Loading...
Sign in
flutter_package
/
fluttertpc_get
Go to a project
Toggle navigation
Projects
Groups
Snippets
Help
Toggle navigation pinning
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
juanjoseleca
2020-08-23 10:50:56 -0500
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
53e5a23b4b6ea8ca44e29b7080370fc233167d1a
53e5a23b
1 parent
422c9061
add function to get responsive value
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
0 deletions
README.md
lib/src/utils/context_extensions/extensions.dart
README.md
View file @
53e5a23
...
...
@@ -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
...
...
lib/src/utils/context_extensions/extensions.dart
View file @
53e5a23
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
;
}
}
...
...
Please
register
or
login
to post a comment