Skip to content

Commit b50992f

Browse files
author
Jens Becker
committed
feat(context_extensions): helper getters on FormFactor & ScreenSize (#6)
closes #6
1 parent d2b2792 commit b50992f

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

lib/src/extensions/context_extensions.dart

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,37 @@ class FormFactorBreakpoints {
1616
/// Enum which defines the possible form factors.
1717
enum FormFactor { desktop, tablet, handset, watch }
1818

19+
extension FormFactorExtensions on FormFactor {
20+
/// Whether `context.formFactor` is equal to `FormFactor.desktop`.
21+
bool get isDesktop => this == FormFactor.desktop;
22+
23+
/// Whether `context.formFactor` is equal to `FormFactor.tablet`.
24+
bool get isTablet => this == FormFactor.tablet;
25+
26+
/// Whether `context.formFactor` is equal to `FormFactor.handset`.
27+
bool get isHandset => this == FormFactor.handset;
28+
29+
/// Whether `context.formFactor` is equal to `FormFactor.watch`.
30+
bool get isWatch => this == FormFactor.watch;
31+
}
32+
1933
/// Alternative to [FormFactor], which is more abstract and defines it in terms of small to large.
2034
enum ScreenSize { small, normal, large, extraLarge }
2135

36+
extension ScreenSizeExtensions on ScreenSize {
37+
/// Whether `context.screenSize` is equal to `ScreenSize.small`.
38+
bool get isSmall => this == ScreenSize.small;
39+
40+
/// Whether `context.screenSize` is equal to `ScreenSize.normal`.
41+
bool get isNormal => this == ScreenSize.normal;
42+
43+
/// Whether `context.screenSize` is equal to `ScreenSize.large`.
44+
bool get isLarge => this == ScreenSize.large;
45+
46+
/// Whether `context.screenSize` is equal to `ScreenSize.extraLarge`.
47+
bool get isExtraLarge => this == ScreenSize.extraLarge;
48+
}
49+
2250
extension AdpativeContextExtensions on BuildContext {
2351
/// The [MediaQueryData] from the closest instance of this class that encloses the given context.
2452
///

0 commit comments

Comments
 (0)