"Ask me anything" app.
Boss level challenge 1 Complete.
main.dart
import 'dart:math';
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: '8BallQna',
theme: ThemeData(
primarySwatch: Colors.orange,
),
home: HomeScreen(),
);
}
}
class HomeScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.orange,
appBar: AppBar(
title: Text(
'Ask Me Anything',
),
),
body: Center(
child: Row(
children: <Widget>[
Expanded(
child: AnswerButton(),
),
],
),
),
);
}
}
class AnswerButton extends StatefulWidget{
_AnswerButtonState createState() => _AnswerButtonState();
}
class _AnswerButtonState extends State<AnswerButton>{
int _ballNum = 6;
@override
Widget build(BuildContext context) {
return FlatButton(
onPressed: () => setState(() {
_ballNum = Random().nextInt(5)+1;
}),
child: Image(
image: AssetImage('images/ball$_ballNum.png'),
),
);
}
}
pubspec.yaml
name: eight_ball_qna description: A new Flutter application. version: 1.0.0+1 environment: sdk: ">=2.1.0 <3.0.0" dependencies: flutter: sdk: flutter cupertino_icons: ^0.1.2 dev_dependencies: flutter_test: sdk: flutter flutter: uses-material-design: true assets: - images/
Find me on:
Comments
Post a Comment