declear a variable and use the math library
This commit is contained in:
parent
3934cca572
commit
e7f29a8d94
@ -1,3 +1,4 @@
|
|||||||
|
import 'dart:math';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
@ -15,26 +16,45 @@ void main() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
class DicePage extends StatelessWidget {
|
|
||||||
|
class DicePage extends StatefulWidget {
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
_DicePageState createState() => _DicePageState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _DicePageState extends State<DicePage> {
|
||||||
|
int leftDiceNumber = 1;
|
||||||
|
int rightDiceNumber = 1;
|
||||||
|
|
||||||
|
void changeDice() {
|
||||||
|
setState(() {
|
||||||
|
leftDiceNumber = Random().nextInt(6)+ 1;
|
||||||
|
rightDiceNumber = Random().nextInt(6) + 1;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
return Center(
|
return Center(
|
||||||
child: Row(
|
child: Row(
|
||||||
children: <Widget> [
|
children: <Widget> [
|
||||||
Expanded(
|
Expanded(
|
||||||
child: FlatButton(
|
child: FlatButton(
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
print('left button is pressed');
|
changeDice();
|
||||||
},
|
},
|
||||||
child: Image.asset('images/dice1.png')),
|
child: Image.asset('images/dice$leftDiceNumber.png'),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
|
|
||||||
Expanded(
|
Expanded(
|
||||||
child: FlatButton(
|
child: FlatButton(
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
print('right button is pressed');
|
changeDice();
|
||||||
},
|
},
|
||||||
child: Image.asset('images/dice1.png')),
|
child: Image.asset('images/dice$rightDiceNumber.png')),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
Loading…
Reference in New Issue
Block a user