Flutter Hello World

Flutter Hello World

AndroidStudio Flutter Hello World

打開IDEA 選擇 Start a new Flutter project

image.png

選擇Flutter Application

image.png

Flutter Application 項(xiàng)目文件結(jié)構(gòu)

image.png
image.png

Android Studio 對(duì)Flutter支持工具簡(jiǎn)單介紹

image.png

上圖1,2,3,4工具按鈕介紹

  1. 運(yùn)行Flutter App的設(shè)備列表


    image.png
  2. Flutter的執(zhí)行入口文件
  3. 正常模式運(yùn)行Flutter APP
  4. Debug模式運(yùn)行Flutter APP

Flutter Hello World main.dart源碼

import 'package:flutter/material.dart';

//Flutter 運(yùn)行主函數(shù)入口
void main() => runApp(MyApp());

//構(gòu)建一個(gè)無狀態(tài)的組件為程序的入口
class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        // This is the theme of your application.
        //
        // Try running your application with "flutter run". You'll see the
        // application has a blue toolbar. Then, without quitting the app, try
        // changing the primarySwatch below to Colors.green and then invoke
        // "hot reload" (press "r" in the console where you ran "flutter run",
        // or simply save your changes to "hot reload" in a Flutter IDE).
        // Notice that the counter didn't reset back to zero; the application
        // is not restarted.
        primarySwatch: Colors.blue,
      ),
      home: MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

//構(gòu)建一個(gè)有狀態(tài)變化的組件,就是Hello World中所看到的頁(yè)面
class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);

  // This widget is the home page of your application. It is stateful, meaning
  // that it has a State object (defined below) that contains fields that affect
  // how it looks.

  // This class is the configuration for the state. It holds the values (in this
  // case the title) provided by the parent (in this case the App widget) and
  // used by the build method of the State. Fields in a Widget subclass are
  // always marked "final".

  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  //聲明私有變量counter
  int _counter = 0;

  //聲明私有方法 incrementCounter用來增counter的值
  void _incrementCounter() {
    //更新組件狀態(tài) counter 增加 1
    setState(() {
      // This call to setState tells the Flutter framework that something has
      // changed in this State, which causes it to rerun the build method below
      // so that the display can reflect the updated values. If we changed
      // _counter without calling setState(), then the build method would not be
      // called again, and so nothing would appear to happen.
      _counter++;
    });
  }

  //構(gòu)建當(dāng)前頁(yè)面現(xiàn)實(shí)內(nèi)容
  @override
  Widget build(BuildContext context) {
    // This method is rerun every time setState is called, for instance as done
    // by the _incrementCounter method above.
    //
    // The Flutter framework has been optimized to make rerunning build methods
    // fast, so that you can just rebuild anything that needs updating rather
    // than having to individually change instances of widgets.
    return Scaffold(
      appBar: AppBar(
        // Here we take the value from the MyHomePage object that was created by
        // the App.build method, and use it to set our appbar title.
        title: Text(widget.title),
      ),
      body: Center(
        // Center is a layout widget. It takes a single child and positions it
        // in the middle of the parent.
        child: Column(
          // Column is also layout widget. It takes a list of children and
          // arranges them vertically. By default, it sizes itself to fit its
          // children horizontally, and tries to be as tall as its parent.
          //
          // Invoke "debug painting" (press "p" in the console, choose the
          // "Toggle Debug Paint" action from the Flutter Inspector in Android
          // Studio, or the "Toggle Debug Paint" command in Visual Studio Code)
          // to see the wireframe for each widget.
          //
          // Column has various properties to control how it sizes itself and
          // how it positions its children. Here we use mainAxisAlignment to
          // center the children vertically; the main axis here is the vertical
          // axis because Columns are vertical (the cross axis would be
          // horizontal).
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Text(
              'You have pushed the button this many times:',
            ),
            Text(
              '$_counter',
              style: Theme.of(context).textTheme.display1,
            ),
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _incrementCounter,
        tooltip: 'Increment',
        child: Icon(Icons.add),
      ), // This trailing comma makes auto-formatting nicer for build methods.
    );
  }
}

Flutter Hello World運(yùn)行效果

image.png
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末酪穿,一起剝皮案震驚了整個(gè)濱河市亮曹,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌,老刑警劉巖厢绝,帶你破解...
    沈念sama閱讀 212,718評(píng)論 6 492
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件剑肯,死亡現(xiàn)場(chǎng)離奇詭異,居然都是意外死亡欺旧,警方通過查閱死者的電腦和手機(jī)姑丑,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 90,683評(píng)論 3 385
  • 文/潘曉璐 我一進(jìn)店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來辞友,“玉大人栅哀,你說我怎么就攤上這事〕屏” “怎么了留拾?”我有些...
    開封第一講書人閱讀 158,207評(píng)論 0 348
  • 文/不壞的土叔 我叫張陵,是天一觀的道長(zhǎng)鲫尊。 經(jīng)常有香客問我痴柔,道長(zhǎng),這世上最難降的妖魔是什么疫向? 我笑而不...
    開封第一講書人閱讀 56,755評(píng)論 1 284
  • 正文 為了忘掉前任咳蔚,我火速辦了婚禮,結(jié)果婚禮上搔驼,老公的妹妹穿的比我還像新娘谈火。我一直安慰自己,他們只是感情好舌涨,可當(dāng)我...
    茶點(diǎn)故事閱讀 65,862評(píng)論 6 386
  • 文/花漫 我一把揭開白布糯耍。 她就那樣靜靜地躺著,像睡著了一般。 火紅的嫁衣襯著肌膚如雪谍肤。 梳的紋絲不亂的頭發(fā)上啦租,一...
    開封第一講書人閱讀 50,050評(píng)論 1 291
  • 那天,我揣著相機(jī)與錄音荒揣,去河邊找鬼篷角。 笑死,一個(gè)胖子當(dāng)著我的面吹牛系任,可吹牛的內(nèi)容都是我干的恳蹲。 我是一名探鬼主播,決...
    沈念sama閱讀 39,136評(píng)論 3 410
  • 文/蒼蘭香墨 我猛地睜開眼俩滥,長(zhǎng)吁一口氣:“原來是場(chǎng)噩夢(mèng)啊……” “哼嘉蕾!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起霜旧,我...
    開封第一講書人閱讀 37,882評(píng)論 0 268
  • 序言:老撾萬榮一對(duì)情侶失蹤错忱,失蹤者是張志新(化名)和其女友劉穎,沒想到半個(gè)月后挂据,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體以清,經(jīng)...
    沈念sama閱讀 44,330評(píng)論 1 303
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 36,651評(píng)論 2 327
  • 正文 我和宋清朗相戀三年崎逃,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了掷倔。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點(diǎn)故事閱讀 38,789評(píng)論 1 341
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡个绍,死狀恐怖勒葱,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情巴柿,我是刑警寧澤凛虽,帶...
    沈念sama閱讀 34,477評(píng)論 4 333
  • 正文 年R本政府宣布,位于F島的核電站广恢,受9級(jí)特大地震影響凯旋,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜袁波,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 40,135評(píng)論 3 317
  • 文/蒙蒙 一瓦阐、第九天 我趴在偏房一處隱蔽的房頂上張望蜗侈。 院中可真熱鬧篷牌,春花似錦、人聲如沸踏幻。這莊子的主人今日做“春日...
    開封第一講書人閱讀 30,864評(píng)論 0 21
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)。三九已至夭苗,卻和暖如春信卡,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背题造。 一陣腳步聲響...
    開封第一講書人閱讀 32,099評(píng)論 1 267
  • 我被黑心中介騙來泰國(guó)打工傍菇, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留,地道東北人界赔。 一個(gè)月前我還...
    沈念sama閱讀 46,598評(píng)論 2 362
  • 正文 我出身青樓丢习,卻偏偏與公主長(zhǎng)得像,于是被迫代替她去往敵國(guó)和親淮悼。 傳聞我的和親對(duì)象是個(gè)殘疾皇子咐低,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 43,697評(píng)論 2 351

推薦閱讀更多精彩內(nèi)容