Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter: How can I make a Random color generator Background

Tags:

flutter

dart

Generate random colors

return new RaisedButton(       padding:  EdgeInsets.symmetric(vertical: 30.0),     color: Colors.primaries random  List <blue,green>, 
like image 435
Dev Ed Avatar asked Jul 14 '18 14:07

Dev Ed


People also ask

How do you generate random Colors in flutter?

The Random class comes with a method name nextInt that can generate a random integer in the range from 0, inclusive, to a given max value, exclusive. You can make a random color like this: Color _randomColor = Colors. primaries[Random().

How do you add a background color to a row in flutter?

Row does not have any default attribute to set background color. So what we do then? Just wrap Row with other widgets, give color to them and it will affect in Row's background. Wraping a widget with other widget is very common in Flutter :-).


1 Answers

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; 
like image 105
Ascension Avatar answered Nov 26 '22 23:11

Ascension