Flutter: How can I make a Random color generator Background

This is my way to get a random color:

Color((math.Random().nextDouble() * 0xFFFFFF).toInt()).withOpacity(1.0)

Note:
This import is required.

import 'dart:math' as math;

There is an in-built list of material colors in the Colors class. You can use it like below

Colors.primaries[Random().nextInt(Colors.primaries.length)]

example

import 'dart:math';

Icon(
    Icons.account_circle,
    size: 40,
    color: Colors.primaries[Random().nextInt(Colors.primaries.length)],
)

Above is the simplest and fastest way to colorize your list with random colors. You don't need to maintain a list of colors.

Tags:

Dart

Flutter