Flutter - Hello Flutter

2020-09-17  本文已影响0人  tp夕阳武士

1. 两步创建Flutter项目

注意
hello_flutter是工程名字,根据自己实际项目名修改

2. Hello Flutter

import 'package:flutter/material.dart';

/*程序入口函数*/
void main() {
  //runApp : Inflate the given widget and attach it to the screen.
  // 通过这个函数,把组件显示到屏幕上去;
  runApp(
      //自定义的class 继承于 StatelessWidget
      MyApp()
   );
}

class MyApp extends StatelessWidget {
  const MyApp({
    Key key,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    //MaterialApp 是flutter SDK中提供的一个类 继承于StatefulWidget
    //An application that uses material design.
    // A convenience widget that wraps a number of widgets that are commonly required for material design applications.
    // It builds upon a [WidgetsApp] by adding material-design specific functionality, such as [AnimatedTheme] and
    // [GridPaper].
    // 使用MaterialApp 设计的应用程序。
    // 它封装了很多小部件,在 [WidgetsApp] 的基础上,
    //通过添加特定Widget设计功能,如[动画主题]和 [Grid Paper].
    return MaterialApp(

      //Implements the basic material design visual layout structure.
      //实现基本的材料设计视觉布局结构。 
      //源码中海油非常多的注释,可以深入看一下;
      home: Scaffold(
        // AppBar 是用于设计导航栏的
          appBar: AppBar(
            title: Text('标题'),
          ),
          
          // 这个body 就是用于设计页面内容的了,
          body: Center(
            child: Text('hello flutter'),
          )),
    );
  }
}
上一篇 下一篇

猜你喜欢

热点阅读