Flutter初识:安装配置与Hello world

2018-08-31  本文已影响83人  最爱平角裤

安装Flutter

mac系统:

open .bash_profile

export PUB_HOSTED_URL=https://pub.flutter-io.cn
export FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn

source .bash_profile

git clone -b beta https://github.com/flutter/flutter.git

export PATH=pwd/flutter/bin:$PATH

window系统

Android Studio 集成Flutter插件

第一个程序Hello world


class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      title: 'Welcome to Flutter',
      home: new Scaffold(
        appBar: new AppBar(
          title: new Text('Welcome to Flutter'),
        ),
        body: new Center(
          child: new Text('Hello World'),
        ),
      ),
    );
  }
}

分析

问题:会出现 Resolving dependencies... 报错
多尝试重启了几次就好了···


brew update   
brew install --HEAD libimobiledevice   
brew install ideviceinstaller ios-deploy cocoapods   
pod setup

安装完毕之后打开hello_world/ios目录下的
在运行之前需要配置bundle identifier和签名
不然会出现如下提示


尝试增加english_words外部包
在Android Studio的编辑器视图中查看pubspec时,单击右上角的 Packages get,依赖包会安装到项目中。控制台中看到以下内容:

flutter packages get
Running "flutter packages get" in startup_namer...
Process finished with exit code 0

在 lib/main.dart 中, 引入 english_words

import 'package:flutter/material.dart';
import 'package:english_words/english_words.dart';

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

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    final wordPair = new WordPair.random();
    return new MaterialApp(
      title: 'Welcome to Flutter',
      home: new Scaffold(
        appBar: new AppBar(
          title: new Text('Welcome to Flutter'),
        ),
        body: new Center(
//          child: new Text('Hello World'),
          child:new Text(wordPair.asPascalCase),
        ),
      ),
    );
  }
}
上一篇 下一篇

猜你喜欢

热点阅读