Skip to content

Instantly share code, notes, and snippets.

@simoales
Created June 11, 2020 08:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save simoales/45e1b25fee8aeeee788a2408b280cb43 to your computer and use it in GitHub Desktop.
Save simoales/45e1b25fee8aeeee788a2408b280cb43 to your computer and use it in GitHub Desktop.
import 'package:flutter/material.dart';
import 'dart:math';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Future Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
visualDensity: VisualDensity.adaptivePlatformDensity,
),
home: FuturePage(),
);
}
}
class FuturePage extends StatefulWidget {
@override
_FuturePageState createState() => _FuturePageState();
}
class _FuturePageState extends State<FuturePage> {
int result;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Back to the Future'),
),
body: Center(
child: Column(
children: [
Spacer(),
RaisedButton(
child: Text('GO!'),
onPressed: () {
setState(() {
result = find42s();
});
},),
Spacer(),
Text(result.toString()),
Spacer(),
CircularProgressIndicator(),
Spacer(),
]
),
),
);
}
int find42s() {
int counter = 0;
var rnd = Random();
for (int i = 0; i<10000000; i++) {
int myNumber = rnd.nextInt(100);
if (myNumber == 42) {
counter++;
}
}
return counter;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment