MrFlutter
MrFlutter

Reputation: 47

how to display random number in flutter

I need to display a random number in flutter using a function, but when i call it i get error.

 void generateRandomNumber() {
                        setState(() {
                          point=pointValue[new Random().nextInt(pointValue.length)];
                        });
                        }

Upvotes: 1

Views: 627

Answers (1)

Jitesh Mohite
Jitesh Mohite

Reputation: 34170

Return int value from your method which generated by Random class

 List<int> pointValue = [5,6,7,8,10,15];
  
  int generateRandomNumber() {
    return pointValue[new Random().nextInt(pointValue.length)];
  }

Upvotes: 2

Related Questions