-
-
Save angelabauer/3b3919bc59100d06997aec2c3d4c57ab to your computer and use it in GitHub Desktop.
| 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'), | |
| ), | |
| ); | |
| } | |
| } |
you should all try https://ray.so/ , its awesome sharing code snippets. you will thank me later. cheers
Dear Dr Angela,
i'm kamole burume edouard
I wanted to inform you that while I'm studying this course in 2024, I’ve noticed that some elements in the code provided, such as FlatButton, have been deprecated and replaced by newer widgets like TextButton. Flutter has undergone updates, and some older components are no longer in use. I’ve updated my code accordingly to ensure compatibility with the current Flutter framework. thank you for the docs you always provide are the one helping to move well and advanced i really love the course i'm always greatfull to have you, coz you've been there for me again for Web Development and here were together again .
so this is my work also
import 'dart:math';
import 'package:flutter/material.dart';
void main() => runApp(
MaterialApp(
home: BallPage(),
theme: ThemeData(
primaryColor: Colors.deepPurple,
),
),
);
class BallPage extends StatelessWidget {
@OverRide
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.deepPurple[100],
appBar: AppBar(
backgroundColor: Colors.deepPurple,
title: Text('Ask Anything Magic Ball'),
centerTitle: true,
elevation: 5,
),
body: Ball(),
);
}
}
class Ball extends StatefulWidget {
@OverRide
_BallState createState() => _BallState();
}
class _BallState extends State {
int ballNumber = 1;
void shakeBall() {
setState(() {
ballNumber = Random().nextInt(5) + 1;
});
}
@OverRide
Widget build(BuildContext context) {
return Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
'Ask a Question & Tap the Ball!',
style: TextStyle(
fontSize: 24,
color: Colors.deepPurple[900],
fontWeight: FontWeight.bold,
),
),
SizedBox(height: 20),
GestureDetector(
onTap: shakeBall,
child: Image.asset('images/ball$ballNumber.png', height: 150),
),
],
),
);
}
}

Yes! I did it!