added new file

flutterdice
This commit is contained in:
Ayush Raj 2020-04-28 01:25:59 +05:30 committed by GitHub
parent 3638a6940b
commit 13d440240e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,4 +1,5 @@
import 'package:flutter/material.dart';
import 'dart:math';
void main() {
return runApp(
@ -15,9 +16,49 @@ 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(
onPressed: () {
setState(() {
leftdicenumber = Random().nextInt(6) + 1;
rightdicenumber = Random().nextInt(6) + 1;
});
},
child: Image.asset(
'images/dice$leftdicenumber.png',
color: Colors.black,
),
),
),
Expanded(
child: FlatButton(
onPressed: () {
setState(() {
rightdicenumber = Random().nextInt(6) + 1;
leftdicenumber = Random().nextInt(6) + 1;
});
},
child: Image.asset(
'images/dice$rightdicenumber.png',
color: Colors.black,
),
),
),
],
),
);
}
}