Magic 8 Ball
This commit is contained in:
58
lib/main.dart
Normal file
58
lib/main.dart
Normal file
@@ -0,0 +1,58 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'dart:math';
|
||||
|
||||
void main() {
|
||||
runApp(const MagicBall());
|
||||
}
|
||||
|
||||
class MagicBall extends StatefulWidget {
|
||||
const MagicBall({super.key});
|
||||
|
||||
@override
|
||||
State<MagicBall> createState() => _MagicBallState();
|
||||
}
|
||||
|
||||
class _MagicBallState extends State<MagicBall> {
|
||||
int prediction = 1;
|
||||
|
||||
int getPrediction() {
|
||||
return Random().nextInt(5) + 1;
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
prediction = getPrediction();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return MaterialApp(
|
||||
debugShowCheckedModeBanner: false,
|
||||
home: Scaffold(
|
||||
backgroundColor: Colors.blue,
|
||||
appBar: AppBar(
|
||||
title: Center(
|
||||
child: Text(
|
||||
'Ask Me Anything',
|
||||
style: TextStyle(
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Colors.white,
|
||||
fontSize: 25,
|
||||
),
|
||||
),
|
||||
),
|
||||
backgroundColor: Colors.blue.shade900,
|
||||
),
|
||||
body: TextButton(
|
||||
child: Center(child: Image.asset('assets/ball$prediction.png')),
|
||||
onPressed: () {
|
||||
setState(() {
|
||||
prediction = getPrediction();
|
||||
});
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user