Created
March 27, 2020 07:45
-
-
Save evgkarasev/8f95b724cd9ff9b96a55deb9e79f54a4 to your computer and use it in GitHub Desktop.
Dicee - simple app to learn Stateful Flutter widgets
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'dart:math'; | |
import 'package:flutter/material.dart'; | |
void main() { | |
return runApp( | |
MaterialApp( | |
home: Scaffold( | |
backgroundColor: Colors.red, | |
appBar: AppBar( | |
backgroundColor: Colors.red, | |
title: Text('Dicee'), | |
), | |
body: DicePage(), | |
), | |
), | |
); | |
} | |
class DicePage extends StatefulWidget { | |
@override | |
_DicePageState createState() => _DicePageState(); | |
} | |
class _DicePageState extends State<DicePage> { | |
int leftDiceNum = Random().nextInt(6) + 1; | |
int rightDiceNum = Random().nextInt(6) + 1; | |
void stateUpdate() { | |
setState(() { | |
leftDiceNum = Random().nextInt(6) + 1; | |
rightDiceNum = Random().nextInt(6) + 1; | |
}); | |
} | |
@override | |
Widget build(BuildContext context) { | |
return Center( | |
child: Column( | |
children: <Widget>[ | |
Spacer( | |
flex: 2, | |
), | |
Row( | |
children: <Widget>[ | |
Spacer( | |
flex: 2, | |
), | |
Expanded( | |
flex: 4, | |
child: FlatButton( | |
onPressed: stateUpdate, | |
child: Image.asset('images/dice$leftDiceNum.png'), | |
), | |
), | |
Spacer(), | |
Expanded( | |
flex: 4, | |
child: FlatButton( | |
onPressed: stateUpdate, | |
child: Image.asset('images/dice$rightDiceNum.png'), | |
), | |
), | |
Spacer( | |
flex: 2, | |
), | |
], | |
), | |
Spacer( | |
flex: 1, | |
), | |
Row( | |
children: <Widget>[ | |
Spacer( | |
flex: 2, | |
), | |
Expanded( | |
flex: 4, | |
child: FlatButton( | |
onPressed: stateUpdate, | |
child: Image.asset('images/dice$leftDiceNum.png'), | |
), | |
), | |
Spacer(), | |
Expanded( | |
flex: 4, | |
child: FlatButton( | |
onPressed: stateUpdate, | |
child: Image.asset('images/dice$rightDiceNum.png'), | |
), | |
), | |
Spacer( | |
flex: 2, | |
), | |
], | |
), | |
Spacer( | |
flex: 2, | |
), | |
], | |
), | |
); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: flutterfirstapp | |
description: Dicee - simple app to learn Stateful Flutter widgets | |
version: 1.0.0+1 | |
environment: | |
sdk: ">=2.7.0 <3.0.0" | |
dependencies: | |
flutter: | |
sdk: flutter | |
cupertino_icons: ^0.1.3 | |
dev_dependencies: | |
flutter_test: | |
sdk: flutter | |
# For information on the generic Dart part of this file, see the | |
# following page: https://dart.dev/tools/pub/pubspec | |
# The following section is specific to Flutter. | |
flutter: | |
# The following line ensures that the Material Icons font is | |
# included with your application, so that you can use the icons in | |
# the material Icons class. | |
uses-material-design: true | |
# To add assets to your application, add an assets section, like this: | |
assets: | |
- images/ | |
# An image asset can refer to one or more resolution-specific "variants", see | |
# https://flutter.dev/assets-and-images/#resolution-aware. | |
# For details regarding adding assets from package dependencies, see | |
# https://flutter.dev/assets-and-images/#from-packages | |
fonts: | |
- family: Pacifico | |
fonts: | |
- asset: fonts/Pacifico-Regular.ttf | |
- family: SourceSansPro | |
fonts: | |
- asset: fonts/Source_Sans_Pro/SourceSansPro-Regular.ttf | |
# For details regarding fonts from package dependencies, | |
# see https://flutter.dev/custom-fonts/#from-packages |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment