Flutter 강의 Section 8에서는 지난 강의의 내용들을 토대로 Magic 8 Ball 앱을 만드는 것이다.
<Magic 8 Ball>
(1) 코드 작성
import 'package:flutter/material.dart';
import 'dart:math';
void main() {
runApp(
MaterialApp(
home: BallPage(),
),
);
}
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: [
Expanded(
child: FlatButton(
onPressed: (){
setState(() {
print('I got clicked');
ballNumber = Random().nextInt(5)+1;
});
},
child: Image.asset('images/ball$ballNumber.png'),
),
),
],
),
);
}
}
class BallPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.blue,
appBar: AppBar(
backgroundColor: Colors.blue[900],
title: Center(
child: Text(
'Asking me Anything',
style: TextStyle(
fontFamily: 'Pacifico',
fontWeight: FontWeight.bold,
),
),
),
),
body: Ball(),
);
}
}
(2) 실행 화면
강의: www.appbrewery.co/p/flutter-development-bootcamp-with-dart
원글: luke-computer.tistory.com/5
'Flutter' 카테고리의 다른 글
[Flutter - 1team] 섹션 4 : 실제 기기에서 빌드해보기 (0) | 2020.11.23 |
---|---|
[Flutter - 1team] 섹션 3 : I Am Rich - How to CreateFlutter Apps From Scratch (0) | 2020.11.13 |
[Flutter - 2team] Section 7: Dicee (0) | 2020.11.09 |
[Flutter - 2team] Section 6: Mi Card (0) | 2020.11.09 |
[Flutter - 2team] Section 5: I Am Poor (0) | 2020.11.09 |