dicee-flutter/lib/main.dart

66 lines
1.3 KiB
Dart
Raw Normal View History

2022-02-11 15:31:04 +00:00
import 'dart:math';
2019-03-05 11:08:12 +00:00
import 'package:flutter/material.dart';
void main() {
return runApp(
MaterialApp(
home: Scaffold(
backgroundColor: Colors.red,
appBar: AppBar(
2022-02-11 15:31:04 +00:00
centerTitle: true,
2019-03-05 11:08:12 +00:00
title: Text('Dicee'),
backgroundColor: Colors.red,
),
body: DicePage(),
),
),
);
}
2022-02-11 15:31:04 +00:00
class DicePage extends StatefulWidget {
@override
_DicePageState createState() => _DicePageState();
}
class _DicePageState extends State<DicePage> {
int leftDiceNumber = 1, rightDiceNumber = 1;
int randomNumb() {
int a = 1 + Random().nextInt(6);
return a;
}
void changeNumb() {
setState(() {
leftDiceNumber = randomNumb();
rightDiceNumber = randomNumb();
});
}
2019-03-05 11:08:12 +00:00
@override
Widget build(BuildContext context) {
2022-02-11 15:31:04 +00:00
return Center(
child: Row(
children: <Widget>[
Expanded(
child: TextButton(
onPressed: () {
changeNumb();
},
child: Image.asset('images/dice$leftDiceNumber.png'),
),
),
Expanded(
child: TextButton(
onPressed: () {
changeNumb();
},
child: Image.asset('images/dice$rightDiceNumber.png'),
),
),
],
),
);
2019-03-05 11:08:12 +00:00
}
}