2
3

More than 3 years have passed since last update.

Flutter for webの環境を構築してみた

Last updated at Posted at 2020-04-21

環境

Mac OS X ver10.14.5

参考URL

基本的に、flutter公式を元に対応。
自分の行った手順を記述します。

Flutter SDKを入手する

https://storage.googleapis.com/flutter_infra/releases/stable/macos/flutter_macos_v1.12.13+hotfix.9-stable.zip
※2020年4月21日現在 flutter_macos_v1.12.13+hotfix.9-stable

ダウンロード後、以下を実施

mac
$ mkdir ~/development
$ cd ~/development
$ unzip ~/Downloads/flutter_macos_v1.12.13+hotfix.9-stable.zip

Flutterのパスを通す

Flutterのパスを通すために、展開したflutterを移動します

mac
$ mv development/flutter /usr/local/var/

bash_profileに以下を追記

mac
$ vi ~/.bash_profile

===以下追記===
export PATH=$PATH:/usr/local/var/flutter/bin

以下で更新

mac
$ source ~/.bash_profile

無事Flutterがインストールできました

mac
$ flutter --version
Flutter 1.12.13+hotfix.9 • channel stable •
https://github.com/flutter/flutter.git
Framework • revision f139b11009 (3 weeks ago) • 2020-03-30 13:57:30 -0700
Engine • revision af51afceb8
Tools • Dart 2.7.2

Flutter for webを試す

参考サイト様の通り行おうと思ったのですが、すでにFlutter for webのgitはold扱い。
以下のreadmeを参考に進めてみます。
https://github.com/flutter/flutter_web/blob/master/OLD_README.md

flutter_webビルドツールをインストールする

以下コマンドでインストールを実施

mac
$ flutter pub global activate webdev

で、インストール後、私は以下の表示が出ました。

mac
  export PATH="$PATH:/usr/local/var/flutter/.pub-cache/bin"

ので、例のごとく、パスを通します。
あと、このままreadmeの通り続けてしまうとこのあと詰まったので、2つのパスを通しておきます。

mac
$ vi ~/.bash_profile

===以下追記===
export PATH=$PATH:/usr/local/var/flutter/.pub-cache/bin
export PATH=$PATH:/usr/local/var/flutter/bin/cache/dart-sdk/bin

以下で更新

mac
$ source ~/.bash_profile

hello worldを実行する

まず、任意のディレクトリでgitをcloneしましょう
私は、先程作成したdevelopmentの配下にクローンしました。

mac
$ cd ~/development
$ git clone git@github.com:flutter/flutter_web.git

クローンが成功すると、以下のようになりましたね。

mac
$ ls
flutter_web

hello_worldのディレクトリへ移動します

mac
$ cd flutter_web/examples/hello_world/

移動したら、以下を実行

mac
$ flutter pub upgrade

以下も実行します。

mac
$ pub get

最後に、以下を実行してサーバを起動

mac
$ webdev serve

私の場合は、http://127.0.0.1:8080 へアクセスし、Hello Worldが赤文字で出力されれば成功です。

以上です。

2
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
3