Generating random numbers in flutter and printing it on the screen

 import 'dart:math';


import 'package:flutter/material.dart';

class PrintRandomNumbers extends StatefulWidget {
const PrintRandomNumbers({Key? key}) : super(key: key);

@override
State<PrintRandomNumbers> createState() => _PrintRandomNumbersState();
}

class _PrintRandomNumbersState extends State<PrintRandomNumbers> {

var number;
void randomNumbers() {
setState(() {
number = Random().nextInt(9)+1;
});
}

@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Text(
"$number",
style: const TextStyle(fontWeight: FontWeight.bold, fontSize: 150,color: Colors.red),
),
ElevatedButton(
onPressed: () {
randomNumbers();
},
child: const Text(
"Generate Numbers",
style: TextStyle(fontWeight: FontWeight.bold,fontSize: 20),
))
],
),
),
);
}
}

Comments

Popular posts from this blog

swapping the alternate values in given array's element ! 17/11/2022

Learning stage | c++ programs

c++ basic question