flutter學習記錄-1

weixin_33806914發表於2018-12-17
import 'package:flutter/material.dart';

void  main(){
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title:"mmyapp",
      home:MyHome(),
    );
  }
}

class MyHome extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title:Text("flutter app")),
      body: Text("hello world"),
    );
  }
}

詳解:

1 你的widget 必須包裹在MaterialApp或者WidgetApp中,否則會報錯

2 每個自定義的widget 需要override build 方法,

3 Material的title作用

4 home是應用的首頁

5 scaffold的appBar 是應用欄

6 body是應用主體