-
-
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'), | |
), | |
); | |
} | |
} |
``import 'dart:math';
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@OverRide
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
backgroundColor: Colors.blue,
appBar: AppBar(
backgroundColor: Colors.blue.shade900,
title: Center(
child: Text("MENDAN SO'RORASAN"),
),
),
body: Asosiy(),
),
);
}
}
class Asosiy extends StatefulWidget {
Asosiy({Key? key}) : super(key: key);
@OverRide
State createState() => _AsosiyState();
}
class _AsosiyState extends State {
int raqamalar = 1;
@OverRide
Widget build(BuildContext context) {
return Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
TextButton(
onPressed: () {
setState(() {
raqamalar = Random().nextInt(5) + 1;
});
},
child: Image.asset('images/ball$raqamalar.png'),
),
],
);
}
}
I added one of my own photos that says "Press to start" that's why there are 6 photos instead of 5.
I see you did it a bit different than me... is one way better than the other?
Mine works as intended...
I thought maybe I can remove the Row on line 45 but then I receive errors in the console even though everything appeared to be functioning.
[root]
└── MaterialApp
└── Scaffold
├── MyApp
│ └── Center
│ └── Row
│ └── Expanded
│ └── TextButton
│ └── Padding
│ └── Image
└── AppBar
└── Text
import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart';
import 'dart:math';
void main() {
return runApp(
MaterialApp(
home: Scaffold(
backgroundColor: Colors.blueAccent,
appBar: AppBar(
centerTitle: true, // Needed for web
title: Text(
'Ask me a Yes or No Question',
style: GoogleFonts.anton(
textStyle: const TextStyle(
color: Colors.white,
letterSpacing: 1.0,
),
),
),
backgroundColor: Colors.blue,
),
body: const Main(),
),
),
);
}
class Main extends StatefulWidget {
const Main({Key? key}) : super(key: key);
@override
State<Main> createState() => _MainState();
}
class _MainState extends State<Main> {
int magicResponse = 6;
void regenMagicResponse() {
magicResponse = Random().nextInt(5) + 1;
//print('Response is $magicResponse');
}
@override
Widget build(BuildContext context) {
return Center(
child: Row(
children: [
Expanded(
child: TextButton(
onPressed: () {
setState(() {
regenMagicResponse();
});
},
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Image.asset('images/ball$magicResponse.png'),
),
),
)
],
),
);
}
}
Most of comments was "In 5 mins DONE" , "It's a piece of cake" bla bla..
I wanna say; So, What then? I have done it with multiple mistakes and in along term. This was my result. It makes me happy to create something virtual.
Anyway;
I used instead of . It was working with FB but there was a warning that says, it was old versions stuff.
`import 'package:flutter/material.dart';
import 'dart:math';
// imports a library
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 {
int ballNumber = 1;
@OverRide
Widget build(BuildContext context) {
return Center(
child: TextButton(
onPressed: () {
setState(() {
ballNumber = Random().nextInt(5) + 1;
print('$ballNumber');
});
},
child: Image.asset('images/ball$ballNumber.png'),
),
);
}
}`
`import 'dart:math';
import 'package:flutter/material.dart';
void main() => runApp(
MaterialApp(
home: BallPage(),
),
);
class BallPage extends StatelessWidget {
const BallPage({Key key}) : super(key: key);
@OverRide
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Colors.blue.shade900,
title: Text("Ask Me Anything"),
),
body: Ball(),
);
}
}
class Ball extends StatefulWidget {
const Ball({Key key}) : super(key: key);
@OverRide
State createState() => _BallState();
}
class _BallState extends State {
int ballNumber = 1;
@OverRide
Widget build(BuildContext context) {
return Container(
color: Colors.blue,
child: Center(
child: TextButton(
onPressed: (() {
setState(() {
ballNumber = Random().nextInt(5) + 1;
print("Button Clicked");
});
}),
child: Image.asset("images/ball$ballNumber.png"),
),
),
);
}
}
`
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(
backgroundColor: Colors.blue[900],
title: Text('Ask Me Anything'),
),
body: Ball(),
);
}
}
class Ball extends StatefulWidget {
const Ball({Key key}) : super(key: key);
@OverRide
State createState() => _BallState();
}
class _BallState extends State {
int ballNumber = 1;
@OverRide
Widget build(BuildContext context) {
return Center(
child: TextButton(
onPressed: () {
setState(() {
ballNumber = Random().nextInt(5) + 1;
});
},
child: Image(
image: AssetImage('images/ball$ballNumber.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 'dart:math';
import 'package:flutter/material.dart';
void main() {
return runApp(
MaterialApp(
home: Scaffold(
backgroundColor: Colors.blue.shade300,
appBar: AppBar(
title: const Text('Ask Me Anything'),
backgroundColor: Colors.blue.shade900,
),
body: MagicEightBall(),
),
),
);
}
class MagicEightBall extends StatefulWidget {
const MagicEightBall({Key? key}) : super(key: key);
@override
State<MagicEightBall> createState() => _MagicEightBallState();
}
class _MagicEightBallState extends State<MagicEightBall> {
int ball_number = 1;
void ChangeBallNumber() {
setState(() {
ball_number = Random().nextInt(5) + 1;
});
}
@override
Widget build(BuildContext context) {
return Center(
child: Expanded(
child: TextButton(
onPressed: () {
ChangeBallNumber();
},
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Image.asset('images/ball$ball_number.png'),
),
),
),
);
}
}
Screen.Recording.2023-04-03.at.11.06.30.AM.mov
Done.
I Did It!!
I Tried To Make It More Interactive By Typing The Questions But Didn't Know How Yet
import 'package:flutter/material.dart';
import 'dart:math';
void main() {
return runApp(
MaterialApp(
title: 'Ask Me Anything',
home: Scaffold(
appBar: AppBar(
backgroundColor: Colors.white30,
centerTitle: true,
title: Text(
'Magic 8 Ball',
style: TextStyle(
fontSize: 20.0,
color: Colors.black,
),
),
),
body: SafeArea(child: magic()),
),
),
);
}
class magic extends StatefulWidget {
const magic({super.key});
@OverRide
State createState() => _magic();
}
class _magic extends State {
int bn = 1;
void rand() {
setState(
() {
bn = Random().nextInt(5) + 1;
},
);
}
@OverRide
Widget build(BuildContext context) {
return Center(
child: Row(
children: [
Expanded(
child: TextButton(
onPressed: () {
rand();
},
child: Image.asset('images/ball$bn.png'),
),
),
],
),
);
}
}
import 'package:flutter/material.dart';
import 'dart:math';
void main() {
return runApp(MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
backgroundColor: Colors.blue,
appBar: AppBar(
backgroundColor: Color.fromARGB(255, 0, 84, 153),
title: Text('Ask Me Anything'),
),
body: Magicball(),
),
));
}
class Magicball extends StatefulWidget {
const Magicball({super.key});
@OverRide
State createState() => _MagicballState();
}
class _MagicballState extends State {
int BallNumber = 1;
@OverRide
Widget build(BuildContext context) {
return Center(
child: Row(
children: [
Container(
child: Expanded(
child: TextButton(
onPressed: () {
setState(() {
BallNumber = Random().nextInt(5) + 1;
});
},
child: Image.asset(
'images/ball$BallNumber.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.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: () {
setState(
() {
ballNumber = Random().nextInt(5) + 1;
},
);
},
child: Image.asset('images/ball$ballNumber.png'),
),
);
}
}
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'),
),
);
}
}
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(),
);
}
}
// 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 = 1;
@OverRide
Widget build(BuildContext context) {
return Center(
child: TextButton(
onPressed: () {
setState(() {
ballNumber = Random().nextInt(5) + 1;
});
}
}