본문 바로가기
Flutter

[Flutter - 2team] Section 8: Magic 8 Ball

by _uke_ee 2020. 11. 9.

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

 

The Complete Flutter Development Bootcamp with Dart

The Complete Flutter Development Bootcamp with Dart

www.appbrewery.co

원글: luke-computer.tistory.com/5

 

Flutter Section 8: Magic 8 Ball (Instructor. Angela Yu)

Flutter 강의 Section 8에서는 지난 강의의 내용들을 토대로 Magic 8 Ball 앱을 만드는 것이다. (1) 코드 작성 import 'package:flutter/material.dart'; import 'dart:math'; void main() { runApp( MaterialApp(..

luke-computer.tistory.com