Created
June 11, 2020 08:08
-
-
Save simoales/45e1b25fee8aeeee788a2408b280cb43 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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