/*
 * @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:math';
import 'dart:ui';

import 'package:flutter/material.dart';
import 'package:zhiying_comm/util/log/let_log.dart';

class HexColor {
  /// String is in the format "aabbcc" or "ffaabbcc" with an optional leading "#".
  static Color fromHex(String hexString) {
    if (hexString == null || hexString == '') {
      return Colors.transparent;
    }
    try {
      final buffer = StringBuffer();
      if (hexString.length == 6 || hexString.length == 7) buffer.write('ff');
      buffer.write(hexString.replaceFirst('#', ''));
      return Color(int.tryParse(buffer.toString(), radix: 16));
    } catch (e) {
      Logger.log(e);
    }
    return Colors.white;
  }

  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')}';
}
