앱개발/flutter

flutter 공부 4일차 (코딩쉐프 순한 맛 강좌 8 ~)

watervin 2022. 4. 15. 00:57
import 'package:flutter/material.dart';

void main()  => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title : "first app", //여기는 프로젝트 이름이라고 생각하면 돼
      theme: ThemeData(
        primarySwatch: Colors.blue
      ),
      home : MyHomePage(),
    );
  }
}

class MyHomePage extends StatelessWidget {
  const MyHomePage({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold( //발판을 만들어주다
      appBar: AppBar(
        title: Text('first app'), //여기는 앱화면에서 보이는 이름
      ),
      body: Center(
        child: Column(
          children: <Widget>[
            Text('hello'),
            Text('hello'),
            Text('hello')

          ],
        ),
      ),

    );
  }
}

이런 식으로 나눠서 코딩해주는게 코드도 간결하고 좋다고 한다. 나도 앞으로 더 연습해야겠다.

처음부터 버릇이 들게 이렇게 해야지...