Flutter- Dicee project

 

import 'package:flutter/material.dart';
import 'dart:math';

void main() => runApp(
MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
backgroundColor: Colors.red,
appBar: AppBar(
backgroundColor: Colors.red,
title: Text(
'Dice',
style: TextStyle(
color: Colors.white,
),
),
centerTitle: true,
),
body: DicePage())),
);

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

class _DicePageState extends State<DicePage> {
int leftDiceNum = 1;
int RightDiceNum = 1;
void change() {
setState(() {
leftDiceNum = Random().nextInt(6) + 1;
RightDiceNum = Random().nextInt(6) + 1;
});
}

@override
Widget build(BuildContext context) {
return Center(
child: Row(
children: [
Expanded(
child: FlatButton(
child: Image.asset('images/dice$leftDiceNum.png'),
onPressed: () {
change();
},
),
),
Expanded(
child: FlatButton(
child: Image.asset('images/dice$RightDiceNum.png'),
onPressed: () {
change();
},
),
),
],
),
);
}
}

Comments

Popular posts from this blog

Go-VSCode -Autocomplete and Auto-import

Go - mail