Dice page challenge completed

This commit is contained in:
Jitender 2021-12-06 04:23:22 +05:30
parent 421f982ae2
commit 3723124f0e
3 changed files with 55 additions and 10 deletions

View File

@ -1,12 +1,5 @@
![App Brewery Banner](https://github.com/londonappbrewery/Images/blob/master/AppBreweryBanner.png)
# Dicee 🎲
## Our Goal
The objective of this tutorial is to introduce you to the core programming concepts that will form the foundation of most of the apps youll build in the future. This app will teach you how to make apps with functionality using setState() inside Stateful Flutter widgets.
## What you will create

View File

@ -0,0 +1,13 @@
#!/bin/sh
# This is a generated file; do not edit or check into version control.
export "FLUTTER_ROOT=C:\src\flutter"
export "FLUTTER_APPLICATION_PATH=D:\FLUTTER PROJECTS\dicee-flutter"
export "COCOAPODS_PARALLEL_CODE_SIGN=true"
export "FLUTTER_TARGET=lib\main.dart"
export "FLUTTER_BUILD_DIR=build"
export "FLUTTER_BUILD_NAME=1.0.0"
export "FLUTTER_BUILD_NUMBER=1"
export "DART_OBFUSCATION=false"
export "TRACK_WIDGET_CREATION=false"
export "TREE_SHAKE_ICONS=false"
export "PACKAGE_CONFIG=.packages"

View File

@ -1,4 +1,6 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'dart:math';
void main() {
return runApp(
@ -6,18 +8,55 @@ void main() {
home: Scaffold(
backgroundColor: Colors.red,
appBar: AppBar(
title: Text('Dicee'),
title: Center(
child: Text('Dicee'),
),
backgroundColor: Colors.red,
),
body: DicePage(),
),
debugShowCheckedModeBanner: false,
),
);
}
class DicePage extends StatelessWidget {
class DicePage extends StatefulWidget {
@override
_DicePageState createState() => _DicePageState();
}
class _DicePageState extends State<DicePage> {
int leftDiceNumber = 1, rightDiceNumber = 1;
void changeDiceface() {
setState(() {
leftDiceNumber = Random().nextInt(6) + 1;
rightDiceNumber = Random().nextInt(6) + 1;
});
}
@override
Widget build(BuildContext context) {
return Container();
return Center(
child: Row(
children: [
Expanded(
child: FlatButton(
onPressed: () {
changeDiceface();
},
child: Image.asset('images/dice$leftDiceNumber.png'),
),
),
Expanded(
child: FlatButton(
onPressed: () {
changeDiceface();
},
child: Image.asset('images/dice$rightDiceNumber.png'),
),
),
],
),
);
}
}