Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add convenience comparison operators for DeviceScreenType and RefinedSize #55

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.8.0

Adds comparison operators to DeviceScreenType and RefinedSize, for convenience.

## 0.7.1

- Fixes [#53](https://github.com/FilledStacks/responsive_builder/issues/53)
Expand Down
45 changes: 36 additions & 9 deletions lib/src/device_screen_type.dart
Original file line number Diff line number Diff line change
@@ -1,16 +1,43 @@
import 'package:responsive_builder/responsive_builder.dart';

enum DeviceScreenType {
@Deprecated('Use lowercase version')
Mobile,
Mobile(1),
@Deprecated('Use lowercase version')
Tablet,
Tablet(2),
@Deprecated('Use lowercase version')
Desktop,
Desktop(3),
@Deprecated('Use lowercase version')
Watch,
mobile,
tablet,
desktop,
watch
Watch(0),
mobile(1),
tablet(2),
desktop(3),
watch(0);

const DeviceScreenType(this._ordinal);

final int _ordinal;

bool operator >(DeviceScreenType other) => _ordinal > other._ordinal;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is really cool


bool operator >=(DeviceScreenType other) => _ordinal >= other._ordinal;

bool operator <(DeviceScreenType other) => _ordinal < other._ordinal;

bool operator <=(DeviceScreenType other) => _ordinal <= other._ordinal;
}

enum RefinedSize { small, normal, large, extraLarge }
enum RefinedSize {
small,
normal,
large,
extraLarge;

bool operator >(RefinedSize other) => index > other.index;

bool operator >=(RefinedSize other) => index >= other.index;

bool operator <(RefinedSize other) => index < other.index;

bool operator <=(RefinedSize other) => index <= other.index;
}
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: responsive_builder
description: A set of widgets that can be used to define a readable responsive UI for widgets.
version: 0.7.1
version: 0.8.0
homepage: https://github.com/FilledStacks/responsive_builder

funding:
Expand Down