Last active
May 21, 2024 01:54
-
-
Save angelabauer/3b3919bc59100d06997aec2c3d4c57ab to your computer and use it in GitHub Desktop.
This file contains 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() => runApp( | |
MaterialApp( | |
home: BallPage(), | |
), | |
); | |
class BallPage extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
backgroundColor: Colors.blue, | |
appBar: AppBar( | |
backgroundColor: Colors.blue.shade900, | |
title: Text('Ask Me Anything'), | |
), | |
body: Ball(), | |
); | |
} | |
} | |
class Ball extends StatefulWidget { | |
@override | |
_BallState createState() => _BallState(); | |
} | |
class _BallState extends State<Ball> { | |
int ballNumber = 1; | |
@override | |
Widget build(BuildContext context) { | |
return Center( | |
child: FlatButton( | |
onPressed: () { | |
setState(() { | |
ballNumber = Random().nextInt(5) + 1; | |
}); | |
}, | |
child: Image.asset('images/ball$ballNumber.png'), | |
), | |
); | |
} | |
} |
Yes! I did it!
import 'dart:math';
import 'package:flutter/material.dart';
void main() => runApp(
MaterialApp(
home: BallPage()
),
);
class Ball extends StatefulWidget {
const Ball({super.key});
@override
State<Ball> createState() => _BallState();
}
class _BallState extends State<Ball> {
int ballNumber = 1;
@override
Widget build(BuildContext context) {
return Center(
child: TextButton(
onPressed: () {
setState(() {
ballNumber = Random().nextInt(5) + 1;
});
},
child: Image.asset('images/ball$ballNumber.png'),
)
);
}
}
class BallPage extends StatelessWidget {
const BallPage({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.blue,
appBar: AppBar(
title: Text('Ask Me Anything',
style: TextStyle(
color: Colors.white
),
),
backgroundColor: Colors.blue.shade900,
),
body: Ball(),
);
}
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Yay, I did it right, we really don't know what we are capable of until we try.
import 'dart:math';
import 'package:flutter/material.dart';
void main() => runApp(
MaterialApp(
debugShowCheckedModeBanner: false,
home: MagicBallPage(),
),
);
class MagicBallPage extends StatelessWidget {
const MagicBallPage({super.key});
@OverRide
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.blue.shade300,
appBar: AppBar(
backgroundColor: Colors.blue.shade500,
title: Text("Ask Me Anything"),
),
body: MagicPage(),
);
}
}
class MagicPage extends StatefulWidget {
const MagicPage({super.key});
@OverRide
State createState() => _MagicPageState();
}
class _MagicPageState extends State {
int ballTap = 1;
@OverRide
Widget build(BuildContext context) {
return Center(
child: TextButton(
onPressed: () {
setState(() {
ballTap = Random().nextInt(5) + 1;
});
},
child: Image.asset('images/ball$ballTap.png'),
),
);
}
}