Skip to content

Commit e9667c2

Browse files
committed
Add convenience comparison operators for DeviceScreenType and RefinedSize
1 parent 62bc9ae commit e9667c2

File tree

1 file changed

+36
-9
lines changed

1 file changed

+36
-9
lines changed

lib/src/device_screen_type.dart

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,43 @@
1+
import 'package:responsive_builder/responsive_builder.dart';
2+
13
enum DeviceScreenType {
24
@Deprecated('Use lowercase version')
3-
Mobile,
5+
Mobile(1),
46
@Deprecated('Use lowercase version')
5-
Tablet,
7+
Tablet(2),
68
@Deprecated('Use lowercase version')
7-
Desktop,
9+
Desktop(3),
810
@Deprecated('Use lowercase version')
9-
Watch,
10-
mobile,
11-
tablet,
12-
desktop,
13-
watch
11+
Watch(0),
12+
mobile(1),
13+
tablet(2),
14+
desktop(3),
15+
watch(0);
16+
17+
const DeviceScreenType(this._ordinal);
18+
19+
final int _ordinal;
20+
21+
bool operator >(DeviceScreenType other) => _ordinal > other._ordinal;
22+
23+
bool operator >=(DeviceScreenType other) => _ordinal >= other._ordinal;
24+
25+
bool operator <(DeviceScreenType other) => _ordinal < other._ordinal;
26+
27+
bool operator <=(DeviceScreenType other) => _ordinal <= other._ordinal;
1428
}
1529

16-
enum RefinedSize { small, normal, large, extraLarge }
30+
enum RefinedSize {
31+
small,
32+
normal,
33+
large,
34+
extraLarge;
35+
36+
bool operator >(RefinedSize other) => index > other.index;
37+
38+
bool operator >=(RefinedSize other) => index >= other.index;
39+
40+
bool operator <(RefinedSize other) => index < other.index;
41+
42+
bool operator <=(RefinedSize other) => index <= other.index;
43+
}

0 commit comments

Comments
 (0)