Skip to content

Instantly share code, notes, and snippets.

@slightfoot
Created October 2, 2019 20:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save slightfoot/8c172b981396847b7845cb3af06de33a to your computer and use it in GitHub Desktop.
Save slightfoot/8c172b981396847b7845cb3af06de33a to your computer and use it in GitHub Desktop.
Enum class for Dart
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