Created
October 2, 2019 20:27
-
-
Save slightfoot/8c172b981396847b7845cb3af06de33a to your computer and use it in GitHub Desktop.
Enum class for Dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
class OverlayElevation { | |
static const e1 = OverlayElevation._(0.05); | |
static const e2 = OverlayElevation._(0.07); | |
static const e3 = OverlayElevation._(0.08); | |
static const e4 = OverlayElevation._(0.09); | |
static const e6 = OverlayElevation._(0.11); | |
static const values = [e1, e2, e3, e4, e6]; | |
const OverlayElevation._(this._opacity); | |
final double _opacity; | |
int get ordinal => values.indexOf(this); | |
Color merge(Color fg, Color bg) { | |
return Color.alphaBlend(fg.withOpacity(_opacity), bg); | |
} | |
} | |
void foo() { | |
blah(OverlayElevation.e4); | |
} | |
void blah(OverlayElevation e) { | |
final color = e.merge(Colors.red, Colors.blue); | |
print(color.value.toRadixString(16)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment