Skip to content

Commit c9b2937

Browse files
committed
Add convenience comparison operators for DeviceScreenType and RefinedSize
1 parent 94f9025 commit c9b2937

3 files changed

Lines changed: 41 additions & 10 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.8.0
2+
3+
Adds comparison operators to DeviceScreenType and RefinedSize, for convenience.
4+
15
## 0.7.1
26

37
- Fixes [#53](https://github.com/FilledStacks/responsive_builder/issues/53)

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+
}

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: responsive_builder
22
description: A set of widgets that can be used to define a readable responsive UI for widgets.
3-
version: 0.7.1
3+
version: 0.8.0
44
homepage: https://github.com/FilledStacks/responsive_builder
55

66
funding:

0 commit comments

Comments
 (0)