completed dice challenge
This commit is contained in:
parent
bba08eb791
commit
7fe8c4f6b0
@ -1,13 +1,14 @@
|
|||||||
|
import 'dart:math';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
return runApp(
|
return runApp(
|
||||||
MaterialApp(
|
MaterialApp(
|
||||||
home: Scaffold(
|
home: Scaffold(
|
||||||
backgroundColor: Colors.red,
|
backgroundColor: Colors.blueGrey.shade700,
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
title: Text('Dicee'),
|
title: Text('Dice Challenge'),
|
||||||
backgroundColor: Colors.red,
|
backgroundColor: Colors.blueGrey.shade900,
|
||||||
),
|
),
|
||||||
body: DicePage(),
|
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
|
@override
|
||||||
Widget build(BuildContext context) {
|
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
|
version: 1.0.0+1
|
||||||
|
|
||||||
environment:
|
environment:
|
||||||
sdk: ">=2.1.0 <3.0.0"
|
sdk: '>=2.18.5 <3.0.0'
|
||||||
|
|
||||||
dependencies:
|
dependencies:
|
||||||
flutter:
|
flutter:
|
||||||
|
Loading…
Reference in New Issue
Block a user