Flutter function using dice app

This commit is contained in:
Ashish Choudhary 2020-07-15 22:26:48 +05:30
parent 421f982ae2
commit 6b914932d0
No known key found for this signature in database
GPG Key ID: CBBDCBCBB5F3FBE0
2 changed files with 51 additions and 2 deletions

View File

@ -0,0 +1,11 @@
#!/bin/sh
# This is a generated file; do not edit or check into version control.
export "FLUTTER_ROOT=C:\studio\flutter"
export "FLUTTER_APPLICATION_PATH=C:\studio\projects\dicee-flutter"
export "FLUTTER_TARGET=lib\main.dart"
export "FLUTTER_BUILD_DIR=build"
export "SYMROOT=${SOURCE_ROOT}/../build\ios"
export "OTHER_LDFLAGS=$(inherited) -framework Flutter"
export "FLUTTER_FRAMEWORK_DIR=C:\studio\flutter\bin\cache\artifacts\engine\ios"
export "FLUTTER_BUILD_NAME=1.0.0"
export "FLUTTER_BUILD_NUMBER=1"

View File

@ -1,3 +1,5 @@
import 'dart:math';
import 'package:flutter/material.dart';
void main() {
@ -15,9 +17,45 @@ void main() {
);
}
class DicePage extends StatelessWidget {
class DicePage extends StatefulWidget {
@override
_DicePageState createState() => _DicePageState();
}
class _DicePageState extends State<DicePage> {
int leftDiceNumber = 1;
int rightDiceNumber = 1;
@override
Widget build(BuildContext context) {
return Container();
return Center(
child: Row(
children: <Widget>[
Expanded(
child: FlatButton(
child: Image.asset('images/dice$leftDiceNumber.png'),
onPressed: () {
updateRandomValues();
},
),
),
Expanded(
child: FlatButton(
child: Image.asset('images/dice$rightDiceNumber.png'),
onPressed: () {
updateRandomValues();
},
),
),
],
),
);
}
void updateRandomValues() {
setState(() {
leftDiceNumber = Random().nextInt(6) + 1;
rightDiceNumber = Random().nextInt(6) + 1;
});
}
}