completed dice challenge
This commit is contained in:
parent
bba08eb791
commit
7fe8c4f6b0
@ -1,13 +1,14 @@
|
||||
import 'dart:math';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
void main() {
|
||||
return runApp(
|
||||
MaterialApp(
|
||||
home: Scaffold(
|
||||
backgroundColor: Colors.red,
|
||||
backgroundColor: Colors.blueGrey.shade700,
|
||||
appBar: AppBar(
|
||||
title: Text('Dicee'),
|
||||
backgroundColor: Colors.red,
|
||||
title: Text('Dice Challenge'),
|
||||
backgroundColor: Colors.blueGrey.shade900,
|
||||
),
|
||||
body: DicePage(),
|
||||
),
|
||||
@ -15,9 +16,41 @@ void main() {
|
||||
);
|
||||
}
|
||||
|
||||
class DicePage extends StatelessWidget {
|
||||
class DicePage extends StatefulWidget {
|
||||
const DicePage({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
State<DicePage> createState() => _DicePageState();
|
||||
}
|
||||
|
||||
class _DicePageState extends State<DicePage> {
|
||||
var leftDice = 1, rightDice = 1;
|
||||
void shuffle() {
|
||||
setState(() {
|
||||
leftDice = Random().nextInt(5) + 1;
|
||||
rightDice = Random().nextInt(5) + 1;
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container();
|
||||
return Center(
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: MaterialButton(
|
||||
child: Image.asset('images/dice$leftDice.png'),
|
||||
onPressed: shuffle,
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: MaterialButton(
|
||||
child: Image.asset('images/dice$rightDice.png'),
|
||||
onPressed: shuffle,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -4,7 +4,7 @@ description: A new Flutter application.
|
||||
version: 1.0.0+1
|
||||
|
||||
environment:
|
||||
sdk: ">=2.1.0 <3.0.0"
|
||||
sdk: '>=2.18.5 <3.0.0'
|
||||
|
||||
dependencies:
|
||||
flutter:
|
||||
|
Loading…
Reference in New Issue
Block a user