Skip to content

Instantly share code, notes, and snippets.

@karanahuja-android
Created August 31, 2020 15:07
Show Gist options
  • Save karanahuja-android/60db3ed35feeb5f41ed7f97443f05584 to your computer and use it in GitHub Desktop.
Save karanahuja-android/60db3ed35feeb5f41ed7f97443f05584 to your computer and use it in GitHub Desktop.
import 'package:flutter/material.dart';
import 'dart:math';
void main() {
runApp(new HelloWorld());
}
class HelloWorld extends StatefulWidget {
@override
_HelloWorldState createState() => _HelloWorldState();
}
class _HelloWorldState extends State<HelloWorld> {
String message = "Guess The Number";
static Random r = Random ();
var computer = r.nextInt (4);
void calculateResult (int player)
{
setState((){
if (computer > player)
{
this.message = "my number is higher";
}
if (computer < player)
{
this.message = "my number is lower";
}
if (computer == player)
{
this.message = "You Got It !";
computer = r.nextInt (4);
}
});
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text('Hello World Example'),
),
body:Center (
child:Column (
children:[
Text (
""
),
Text (
"$message"
),
FlatButton(
color: Colors.black,
textColor:Colors.lightGreenAccent,
onPressed: () {
calculateResult(0);
},
child: Text(
"0",
style: TextStyle(fontSize: 22.0),
),
),
FlatButton(
color: Colors.black,
textColor:Colors.lightGreenAccent,
onPressed: () {
calculateResult(1);
},
child: Text(
"1",
style: TextStyle(fontSize: 22.0),
),
),
FlatButton(
color: Colors.black,
textColor:Colors.lightGreenAccent,
onPressed: () {
calculateResult(2);
},
child: Text(
"2",
style: TextStyle(fontSize: 22.0),
),
),
FlatButton(
color: Colors.black,
textColor:Colors.lightGreenAccent,
onPressed: () {
calculateResult(3);
},
child: Text(
"3",
style: TextStyle(fontSize: 22.0),
),
),
]
),
),
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment