diff --git a/lib/main.dart b/lib/main.dart index 6e68f20..51dd27f 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -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 { + 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: [ + 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'), + ), + ), + ], + ), + ); } }