-
-
Save angelabauer/cdf727bed6e5d82fb45e3b24b8c19c35 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: () { | |
ballNumber = Random().nextInt(5); | |
print(ballNumber); | |
}, | |
child: Image.asset('images/ball1.png'), | |
), | |
); | |
} | |
} |
//My solution
// ignore_for_file: prefer_const_constructors
import 'dart:math';
import 'package:flutter/material.dart';
void main() => runApp(
MaterialApp(
debugShowCheckedModeBanner: false,
home: BallPage(),
),
);
class BallPage extends StatelessWidget {
const BallPage({Key? key}) : super(key: key);
@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 {
const Ball({Key? key}) : super(key: key);
@OverRide
_BallState createState() => _BallState();
}
class _BallState extends State {
int ballNumber = 0;
@OverRide
Widget build(BuildContext context) {
return Center(
child: TextButton(
onPressed: () {
setState(() {
ballNumber = Random().nextInt(5);
});
print(ballNumber);
},
child: Image.asset('images/ball1.png'),
),
);
}
}
import 'dart:math';
import 'package:flutter/material.dart';
void main() => runApp(
MaterialApp(
home: Scaffold(
backgroundColor:Colors.blue,
appBar: AppBar(
backgroundColor: Color.fromARGB(255, 6, 20, 27),
title: Text('Ask Me Anything'),
),
body: Ball (
),
),
),
);
class Ball extends StatefulWidget {
@OverRide
State createState() => _BallPageState();
}
class _BallPageState extends State {
int ballNumber = 1;
Widget build(BuildContext context) {
return Center(
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Row(
children: [
Center (
child: Container(
width: 350,
child: TextButton(
onPressed: () {
setState(() {
ballNumber = Random().nextInt(5);
});
print (ballNumber);
},
child: Image.asset('images/ball1.png')),
),
),
],
),
),
);
}
}
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(
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: Row(
children: <Widget>[
Expanded(
child: TextButton(
onPressed: () => {shuffleImage()},
child: Image.asset('images/ball$ballNumber.png'),
))
],
),
);
}
void shuffleImage() {
setState(() {
ballNumber = Random().nextInt(5) + 1;
print("I got clicked");
});
}
}
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.black54,
appBar: AppBar(
backgroundColor: Colors.black,
title: Text('"NOTHING IMPOSSIBLE TO DO"'),
),
body: Ball(),
);
}
}
class Ball extends StatefulWidget {
@OverRide
_BallState createState() => _BallState();
}
class _BallState extends State {
@OverRide
int ballNumber = 1;
Widget build(BuildContext context) {
return Center(
child: TextButton(
onPressed: () {
ballNumber = Random().nextInt(5);
print(ballNumber);
},
child: Image.asset('images/ball1.png'),
),
);
}
}
import 'dart:math';
import 'package:flutter/material.dart';
void main() {
runApp(MaterialApp(
home: MagicBall(),
));
}
class MagicBall extends StatelessWidget {
const MagicBall({super.key});
@OverRide
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Color.fromARGB(255, 174, 29, 18),
appBar: AppBar(
backgroundColor: Color.fromARGB(255, 142, 20, 20),
title: Text(
'Ask me Anything',
style: TextStyle(color: Colors.white),
),
centerTitle: true,
),
body: Ball(),
);
}
}
class Ball extends StatefulWidget {
const Ball({super.key});
@OverRide
State createState() => _BallPage();
}
class _BallPage extends State {
int ballnumber = 1;
@OverRide
Widget build(BuildContext context) {
return Center(
child: TextButton(
onPressed: () {
setState(() {
ballnumber = Random().nextInt(5) + 1;
});
print('Button is pressed!');
},
child: Image.asset('images/ball${ballnumber}.png'),
),
);
}
}
My solution