Flutter

随机颜色

2019-08-14  本文已影响0人  Victory_886

flutter 产生随机颜色

static Color slRandomColor({int r = 255, int g = 255, int b = 255, a = 255}) {
  if (r == 0 || g == 0 || b == 0) return Colors.black;
  if (a == 0) return Colors.white;
  return Color.fromARGB(
    a,
    r != 255 ? r : Random.secure().nextInt(r),
    g != 255 ? g : Random.secure().nextInt(g),
    b != 255 ? b : Random.secure().nextInt(b),
  );
}

需要导入以下两个

import 'package:flutter/material.dart';
import 'dart:math';

有了随机颜色妈妈再也不用但心选择颜色了~ 哈哈哈哈哈
6666666~

上一篇 下一篇

猜你喜欢

热点阅读