Created
January 27, 2020 00:39
-
-
Save Kav47/e379dd14421ea996f651cbee49814dfd to your computer and use it in GitHub Desktop.
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 'package:flutter/material.dart'; | |
| import 'dart:math'; | |
| void main() => runApp( | |
| MaterialApp( | |
| home: BallPage(), | |
| ), | |
| ); | |
| class BallPage extends StatelessWidget { | |
| @override | |
| Widget build(BuildContext context) { | |
| return Scaffold( | |
| backgroundColor: Colors.blue, | |
| appBar: AppBar( | |
| title: Text('Ask Me Anything'), | |
| backgroundColor: Colors.blue.shade900, | |
| ), | |
| body: Ball(), | |
| ); | |
| } | |
| } | |
| class Ball extends StatefulWidget { | |
| @override | |
| _BallState createState() => _BallState(); | |
| } | |
| class _BallState extends State<Ball> { | |
| int ballNumber = 0; | |
| @override | |
| Widget build(BuildContext context) { | |
| return FlatButton( | |
| onPressed: (){ | |
| ballNumber = Random().nextInt(4); | |
| print('ball number: $ballNumber'); | |
| }, | |
| child: Center( | |
| child: Image.asset('images/ball$ballNumber.png'), | |
| ), | |
| ); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment