美文网首页
Flutter中使用16进制颜色

Flutter中使用16进制颜色

作者: 刘铁崧 | 来源:发表于2020-12-29 21:18 被阅读0次

案例:将数据模型中的16进制颜色字符串转化为Color

import 'package:flutter/material.dart';

class CategoryModel {
  String id;
  String title;
  String color;
  Color hexColor;
  CategoryModel({this.id, this.title, this.color});
  CategoryModel.fromJson(Map<String, dynamic> json) {
    id = json['id'];
    title = json['title'];
    color = json['color'];

    hexColor = Color(int.parse(color,radix: 16) | 0xFF000000);
  }
  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['id'] = this.id;
    data['title'] = this.title;
    data['color'] = this.color;
    return data;
  }
}

使用:

相关文章

网友评论

      本文标题:Flutter中使用16进制颜色

      本文链接:https://www.haomeiwen.com/subject/xcbqoktx.html