72 lines
1.5 KiB
Dart
72 lines
1.5 KiB
Dart
import 'dart:math';
|
|
import 'package:flutter/material.dart';
|
|
|
|
void main() {
|
|
return runApp(
|
|
MaterialApp(
|
|
debugShowCheckedModeBanner: false,
|
|
home: Scaffold(
|
|
backgroundColor: Colors.red,
|
|
appBar: AppBar(title: Text('Dicee'), backgroundColor: Colors.red),
|
|
body: DicePage(),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
class DicePage extends StatefulWidget {
|
|
const DicePage({super.key});
|
|
|
|
@override
|
|
State<DicePage> createState() => _DicePageState();
|
|
}
|
|
|
|
class _DicePageState extends State<DicePage> {
|
|
int leftDie = 0;
|
|
int rightDie = 0;
|
|
|
|
int diceRoll() {
|
|
return Random().nextInt(6) + 1;
|
|
}
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
leftDie = diceRoll();
|
|
rightDie = diceRoll();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Container(
|
|
margin: EdgeInsets.all(16.0),
|
|
child: Center(
|
|
child: Row(
|
|
children: [
|
|
Expanded(
|
|
child: TextButton(
|
|
onPressed: () {
|
|
setState(() {
|
|
leftDie = diceRoll();
|
|
});
|
|
},
|
|
child: Image.asset('assets/dice$leftDie.png'),
|
|
),
|
|
),
|
|
Expanded(
|
|
child: TextButton(
|
|
onPressed: () {
|
|
setState(() {
|
|
rightDie = diceRoll();
|
|
});
|
|
},
|
|
child: Image.asset('assets/dice$rightDie.png'),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|