Update main.dart

This commit is contained in:
shamilkeheliya 2020-10-05 18:17:36 +05:30
parent 421f982ae2
commit 472766721c

View File

@ -1,3 +1,4 @@
import 'dart:math';
import 'package:flutter/material.dart';
void main() {
@ -6,7 +7,7 @@ void main() {
home: Scaffold(
backgroundColor: Colors.red,
appBar: AppBar(
title: Text('Dicee'),
title: Center(child: Text('Dicee')),
backgroundColor: Colors.red,
),
body: DicePage(),
@ -15,9 +16,48 @@ void main() {
);
}
class DicePage extends StatelessWidget {
class DicePage extends StatefulWidget {
@override
_DicePageState createState() => _DicePageState();
}
class _DicePageState extends State<DicePage> {
int leftDiceeNum = 1;
int rightDiceeNum = 1;
void genNum() {
leftDiceeNum = Random().nextInt(6) + 1;
rightDiceeNum = Random().nextInt(6) + 1;
}
@override
Widget build(BuildContext context) {
return Container();
return Center(
child: Row(
children: <Widget>[
Expanded(
flex: 1,
child: FlatButton(
onPressed: () {
setState(() {
genNum();
});
},
child: Image.asset('images/dice$leftDiceeNum.png'),
),
),
Expanded(
child: FlatButton(
onPressed: () {
setState(() {
genNum();
});
},
child: Image.asset('images/dice$rightDiceeNum.png'),
),
),
],
),
);
}
}