|
- /*
- * @Author: your name
- * @Date: 2020-05-18 14:01:56
- * @LastEditTime: 2020-06-24 13:45:26
- * @LastEditors: Please set LastEditors
- * @Description: In User Settings Edit
- * @FilePath: /hairuyi_flutter_yunfadan/lib/utils/color.dart
- */
-
- import 'dart:ui';
- import 'dart:math';
-
- extension HexColor on Color {
- /// String is in the format "aabbcc" or "ffaabbcc" with an optional leading "#".
- static Color fromHex(String hexString) {
- final buffer = StringBuffer();
- if (hexString.length == 6 || hexString.length == 7) buffer.write('ff');
- buffer.write(hexString.replaceFirst('#', ''));
- return Color(int.parse(buffer.toString(), radix: 16));
- }
-
- static Color random() {
- return Color(Random().nextInt(1 << 32));
- }
-
- /// Prefixes a hash sign if [leadingHashSign] is set to `true` (default is `true`).
- String toHex({bool leadingHashSign = true}) => '${leadingHashSign ? '#' : ''}'
- '${alpha.toRadixString(16).padLeft(2, '0')}'
- '${red.toRadixString(16).padLeft(2, '0')}'
- '${green.toRadixString(16).padLeft(2, '0')}'
- '${blue.toRadixString(16).padLeft(2, '0')}';
- }
|