Flutter第一個(gè)demo解析

之前是用終端創(chuàng)建的demo,下午下載安裝了VS Code 這個(gè)輕量級(jí)的工具做另外的嘗試!
VS code 下載鏈接
下載好后 安裝插件 把上次下載的sdk導(dǎo)入VS code
步驟如下

View>Command Palette

輸入 ‘install’, 然后選擇 Extensions: Install Extension

在搜索框輸入 flutter , 在搜索結(jié)果列表中選擇 ‘Flutter’, 然后點(diǎn)擊 Install

重新啟動(dòng) VS Code

創(chuàng)建新應(yīng)用

1 View>Command Palette…

2 輸入 ‘flutter’, 然后選擇 ‘Flutter: New Project’(注意項(xiàng)目不能有大寫(xiě)字母)
3 輸入Project名字 我的命名為 app001
4 指定放置項(xiàng)目的位置,然后按藍(lán)色的確定按鈕

然后我們可以看到創(chuàng)建完成后的項(xiàng)目是這樣的

2667FFBE-F9FD-49D5-9A6F-8A07B96873A7.png

在lib 文件夾下有個(gè)main.dart,這就是主頁(yè)面的布局
里面的代碼如下

import 'package:flutter/material.dart';

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

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      title: 'Flutter Demo',
      theme: new 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 press Run > Flutter Hot Reload in IntelliJ). Notice that the
        // counter didn't reset back to zero; the application is not restarted.
        primarySwatch: Colors.blue,
      ),
      home: new MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

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() => new _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  int _counter = 0;

  void _incrementCounter() {
    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++;
    });
  }

  @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 new Scaffold(
      appBar: new 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: new Text(widget.title),
      ),
      body: new Center(
        // Center is a layout widget. It takes a single child and positions it
        // in the middle of the parent.
        child: new 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 paint" (press "p" in the console where you ran
          // "flutter run", or select "Toggle Debug Paint" from the Flutter tool
          // window in IntelliJ) 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>[
            new Text(
            'You have pushed the button this many times:',
              //"我來(lái)了,我看見(jiàn),我擁有",
            ),
            new Text(
              '$_counter',
              style: Theme.of(context).textTheme.display1,
            ),
          ],
        ),
      ),
      floatingActionButton: new FloatingActionButton(
        onPressed: _incrementCounter,
        tooltip: 'Increment',
        child: new Icon(Icons.add),
      ), // This trailing comma makes auto-formatting nicer for build methods.
    );
  }
}

這個(gè)文件里有布局容器 Widget 類(lèi)似于iOS的UIView,具體的區(qū)別以后再說(shuō),有事件響應(yīng)方法,有導(dǎo)航欄的設(shè)置等.
選擇設(shè)備后 VS code 右下角會(huì)顯示運(yùn)行的設(shè)備


5EC931D7-C933-46D2-ACC4-3542B85D29E9.png

我們先去iOS的目錄下配置證書(shū),按F5或者Debug---start debug
會(huì)發(fā)現(xiàn)程序會(huì)在真機(jī)運(yùn)行起來(lái).效果如下


[圖片上傳中...(IMG_0623.PNG-8ca8dc-1538037858410-0)]

我們修改children里面的text的內(nèi)容 再次運(yùn)行

IMG_0623.PNG
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末塘慕,一起剝皮案震驚了整個(gè)濱河市蚌堵,隨后出現(xiàn)的幾起案子匾寝,更是在濱河造成了極大的恐慌,老刑警劉巖差油,帶你破解...
    沈念sama閱讀 206,126評(píng)論 6 481
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場(chǎng)離奇詭異,居然都是意外死亡件相,警方通過(guò)查閱死者的電腦和手機(jī),發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 88,254評(píng)論 2 382
  • 文/潘曉璐 我一進(jìn)店門(mén)氧苍,熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái)夜矗,“玉大人,你說(shuō)我怎么就攤上這事让虐∥伤海” “怎么了?”我有些...
    開(kāi)封第一講書(shū)人閱讀 152,445評(píng)論 0 341
  • 文/不壞的土叔 我叫張陵赡突,是天一觀的道長(zhǎng)对扶。 經(jīng)常有香客問(wèn)我,道長(zhǎng)麸俘,這世上最難降的妖魔是什么辩稽? 我笑而不...
    開(kāi)封第一講書(shū)人閱讀 55,185評(píng)論 1 278
  • 正文 為了忘掉前任,我火速辦了婚禮从媚,結(jié)果婚禮上逞泄,老公的妹妹穿的比我還像新娘。我一直安慰自己拜效,他們只是感情好喷众,可當(dāng)我...
    茶點(diǎn)故事閱讀 64,178評(píng)論 5 371
  • 文/花漫 我一把揭開(kāi)白布。 她就那樣靜靜地躺著紧憾,像睡著了一般到千。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上赴穗,一...
    開(kāi)封第一講書(shū)人閱讀 48,970評(píng)論 1 284
  • 那天憔四,我揣著相機(jī)與錄音膀息,去河邊找鬼。 笑死了赵,一個(gè)胖子當(dāng)著我的面吹牛潜支,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播柿汛,決...
    沈念sama閱讀 38,276評(píng)論 3 399
  • 文/蒼蘭香墨 我猛地睜開(kāi)眼冗酿,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼!你這毒婦竟也來(lái)了络断?” 一聲冷哼從身側(cè)響起裁替,我...
    開(kāi)封第一講書(shū)人閱讀 36,927評(píng)論 0 259
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤,失蹤者是張志新(化名)和其女友劉穎貌笨,沒(méi)想到半個(gè)月后弱判,有當(dāng)?shù)厝嗽跇?shù)林里發(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 43,400評(píng)論 1 300
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡躁绸,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 35,883評(píng)論 2 323
  • 正文 我和宋清朗相戀三年裕循,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了臣嚣。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片净刮。...
    茶點(diǎn)故事閱讀 37,997評(píng)論 1 333
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡,死狀恐怖硅则,靈堂內(nèi)的尸體忽然破棺而出淹父,到底是詐尸還是另有隱情,我是刑警寧澤怎虫,帶...
    沈念sama閱讀 33,646評(píng)論 4 322
  • 正文 年R本政府宣布暑认,位于F島的核電站,受9級(jí)特大地震影響大审,放射性物質(zhì)發(fā)生泄漏蘸际。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 39,213評(píng)論 3 307
  • 文/蒙蒙 一徒扶、第九天 我趴在偏房一處隱蔽的房頂上張望粮彤。 院中可真熱鬧,春花似錦姜骡、人聲如沸导坟。這莊子的主人今日做“春日...
    開(kāi)封第一講書(shū)人閱讀 30,204評(píng)論 0 19
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)惫周。三九已至,卻和暖如春康栈,著一層夾襖步出監(jiān)牢的瞬間递递,已是汗流浹背喷橙。 一陣腳步聲響...
    開(kāi)封第一講書(shū)人閱讀 31,423評(píng)論 1 260
  • 我被黑心中介騙來(lái)泰國(guó)打工, 沒(méi)想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留登舞,地道東北人重慢。 一個(gè)月前我還...
    沈念sama閱讀 45,423評(píng)論 2 352
  • 正文 我出身青樓,卻偏偏與公主長(zhǎng)得像逊躁,于是被迫代替她去往敵國(guó)和親似踱。 傳聞我的和親對(duì)象是個(gè)殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 42,722評(píng)論 2 345

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