Flutter —— 使用RGB颜色

turboksFlutter95

import 'dart:ui';


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

  }


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

}

使用:


 color: HexColor.fromHex("#f45555"),


返回列表

上一篇:Flutter —— 网络请求

没有最新的文章了...

相关文章

Flutter —— 左右切换视图

Flutter —— 左右切换视图

import 'package:flutter/material.dart';import 'package:ks/pageone.dart';import '...

Flutter —— 轮播图

Flutter —— 轮播图

1.pubspec.yaml  flutter_swiper: ^1.1.6 # 轮播图2.自定义一个类import 'package:flutter/material.dart&#...

Flutter —— 路由

Flutter —— 路由

1. pubspec.yamlfluro: ^1.5.1 #路由2. 路由管理中心    // ignore: import_of_legacy_library...

Flutter —— 网络请求

Flutter —— 网络请求

1.pubspec.yamldio: ^3.0.9 #网络请求2.使用    var url = "urlurlurlurlurl";   ...

Flutter —— 原生交互

Flutter —— 原生交互

一:传递数据flutter:var methodChannel = const MethodChannel("ksapp");onPressed: () {// sendToAnd...

Flutter —— TabBarView每次进入都刷新?

Flutter —— TabBarView每次进入都刷新?

import 'package:flutter/material.dart';class PageOne extends StatefulWidget {const PageOne({...