Skip to content

Commit

Permalink
Complete code
Browse files Browse the repository at this point in the history
  • Loading branch information
belkale committed Apr 14, 2023
1 parent efc000e commit 5930216
Showing 1 changed file with 42 additions and 2 deletions.
44 changes: 42 additions & 2 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'dart:math';

import 'package:flutter/material.dart';

void main() {
Expand All @@ -15,9 +17,47 @@ void main() {
);
}

class DicePage extends StatelessWidget {
class DicePage extends StatefulWidget {
@override
State<DicePage> createState() => _DicePageState();
}

class _DicePageState extends State<DicePage> {
int leftDiceNumber = 1;
int rightDiceNumber = 1;

void buttonPressed() {
leftDiceNumber = Random().nextInt(6) + 1;
rightDiceNumber = Random().nextInt(6) + 1;
}

@override
Widget build(BuildContext context) {
return Container();
return Center(
child: Row(
children: [
Expanded(
child: Padding(
padding: const EdgeInsets.all(16.0),
child: TextButton(
onPressed: () {
setState(buttonPressed);
},
child: Image.asset('images/dice$leftDiceNumber.png'),
),
)),
Expanded(
child: Padding(
padding: const EdgeInsets.all(16.0),
child: TextButton(
onPressed: () {
setState(buttonPressed);
},
child: Image.asset('images/dice$rightDiceNumber.png'),
),
)),
],
),
);
}
}

0 comments on commit 5930216

Please sign in to comment.