Webプログラミング言語「Dart」をインストールする(Windows10)

スポンサーリンク

Dartのインストールについて解説しています。(Windows10)

■PC環境

・Windows10、Administrator(管理者)アカウント

・chocolatey 0.10.15

■Dartをインストールする

Dartをインストールするには、ソフトウェア開発キット (SDK) が必要です。インストールするには、Windows10のデスクトップ画面の検索ボックスで「コマンドプロンプト」と入力します。

入力すると、「最も一致する検索結果」に「コマンドプロンプト」が表示されますので、こちらをクリックします。クリックすると、コマンドプロンプトが起動します。

choco install dart-sdk

起動後、上記のコマンドを入力し、Enterキーを押します。

Chocolatey v0.10.15
Installing the following packages:
dart-sdk
By installing you accept licenses for the packages.
Progress: Downloading dart-sdk 2.10.4… 100%

dart-sdk v2.10.4 [Approved]
dart-sdk package files install completed. Performing other installation steps.
The package dart-sdk wants to run ‘chocolateyInstall.ps1’.
Note: If you don’t run this script, the installation will fail.
Note: To confirm automatically next time, use ‘-y’ or consider:
choco feature enable -n allowGlobalConfirmation
Do you want to run the script?([Y]es/[A]ll – yes to all/[N]o/[P]rint):

Enterキーを押すと「Do you want to run the script?(スクリプトを実行しますか?)」と質問されますので、「Y」と入力し、Enterキーを押します。

PATH environment variable does not have C:\tools\dart-sdk\bin in it. Adding…
PATH environment variable does not have C:\Users\Administrator\AppData\Roaming\Pub\Cache\bin in it. Adding…
Downloading dart-sdk 64 bit
from ‘https://storage.googleapis.com/dart-archive/channels/stable/release/2.10.4/sdk/dartsdk-windows-x64-release.zip’
Progress: 100% – Completed download of C:\Users\Administrator\AppData\Local\Temp\dart-sdk\2.10.4\dartsdk-windows-x64-release.zip (150.05 MB).
Download of dartsdk-windows-x64-release.zip (150.05 MB) completed.
Hashes match.
Extracting C:\Users\Administrator\AppData\Local\Temp\dart-sdk\2.10.4\dartsdk-windows-x64-release.zip to C:\tools…
C:\tools
Environment Vars (like PATH) have changed. Close/reopen your shell to
see the changes (or in powershell/cmd.exe just type `refreshenv`).
The install of dart-sdk was successful.
Software installed to ‘C:\tools’

Chocolatey installed 1/1 packages.
See the log for details (C:\ProgramData\chocolatey\logs\chocolatey.log).

Did you know the proceeds of Pro (and some proceeds from other
licensed editions) go into bettering the community infrastructure?
Your support ensures an active community, keeps Chocolatey tip top,
plus it nets you some awesome features!
https://chocolatey.org/compare

Enterキーを押すと、インストールが開始され、「The install of dart-sdk was successful.」と表示されます。これが表示されれば、Dart SDKのインストールが正常に完了しました。

インストール後、環境変数(PATHなど)が変更されているので、コマンドプロンプトは閉じます。

■アプリを作成する

正常にインストールが完了した後は、アプリを作成します。

dart create -t console-full test01

再度、コマンドプロンプトを起動し、上記のコマンドを入力し、Enterキーを押します。

The Dart tool uses Google Analytics to anonymously report feature usage
statistics, and crash reporting to send basic crash reports. This data is used to help improve the Dart platform and tools over time.
To disable reporting of anonymous tool usage statistics in general, run
the command: `dart –disable-analytics`.(DartツールはGoogle Analyticsを使って機能の利用状況を匿名でレポートする
統計情報、および基本的なクラッシュレポートを送信するクラッシュレポート。このデータはDartのプラットフォームとツールの改善に役立てられる。
匿名のツール使用統計のレポートを無効にするには、次のコマンドを実行します。
コマンド:`dart–disable-analytics`)

Enterキーを押すと上記のメッセージが表示されます。

Creating C:\Users\Administrator\test01 using template console-full...

  .gitignore
  CHANGELOG.md
  README.md
  analysis_options.yaml
  bin\test01.dart
  lib\test01.dart
  pubspec.yaml
  test\test01_test.dart

Running pub get...
  Resolving dependencies...
  Downloading pedantic 1.9.2...
  Downloading meta 1.2.4...
  Downloading test 1.15.7...
  Downloading test_core 0.3.11+4...
  Downloading test_api 0.2.18+1...
  Downloading matcher 0.12.9...
  Downloading package_config 1.9.3...
  Downloading shelf_static 0.2.8...
  Downloading stream_channel 2.0.0...
  Downloading shelf_packages_handler 2.0.0...
  Downloading path 1.7.0...
  Downloading io 0.3.4...
  Downloading source_map_stack_trace 2.0.0...
  Downloading http 0.12.2...
  Downloading term_glyph 1.1.0...
  Downloading js 0.6.2...
  Downloading charcode 1.1.3...
  Downloading shelf_web_socket 0.2.3...
  Downloading http_multi_server 2.2.0...
  Downloading convert 2.1.1...
  Downloading string_scanner 1.0.5...
  Downloading coverage 0.14.2...
  Downloading source_maps 0.10.9...
  Downloading boolean_selector 2.0.0...
  Downloading args 1.6.0...
  Downloading webkit_inspection_protocol 0.7.4...
  Downloading logging 0.11.4...
  Downloading pool 1.4.0...
  Downloading stack_trace 1.9.6...
  Downloading mime 0.9.7...
  Downloading shelf 0.7.9...
  Downloading http_parser 3.1.4...
  Downloading async 2.4.2...
  Downloading node_preamble 1.4.12...
  Downloading glob 1.2.0...
  Downloading node_io 1.2.0...
  Downloading node_interop 1.2.1...
  Downloading typed_data 1.2.0...
  Downloading source_span 1.7.0...
  Downloading file 5.2.1...
  Downloading intl 0.16.1...
  Downloading web_socket_channel 1.1.0...
  Downloading crypto 2.1.5...
  Downloading yaml 2.2.1...
  Downloading analyzer 0.41.1...
  Downloading _fe_analyzer_shared 14.0.0...
  Downloading cli_util 0.2.0...
  Downloading pub_semver 1.4.4...
  Downloading watcher 0.9.7+15...
  Downloading collection 1.14.13...
  Downloading vm_service 4.2.0...
  Changed 51 dependencies!

Created project test01! In order to get started, type:

  cd test01

表示された後に、アプリの作成が行われ「Created project」と表示されます。これが表示されれば、アプリの作成は完了となります。

■アプリを実行する

完了後、アプリを実行します。

cd test01

アプリを実行するには、まず作成されたアプリに移動するために、cdコマンドを入力し、Enterキーを押します。

dart run

Enterキーを押した後、上記のコマンドを入力し、Enterキーを押します。

Hello world: 42!

Enterキーを押すと、アプリが実行され、上記のメッセージが表示されます。これが表示されれば、アプリの実行は完了となります。

■アプリの変更とカスタマイズをする

完了後、アプリの変更とカスタマイズを行ってみます。

アプリの変更とカスタマイズを行う場合は、作成したアプリ内の「lib/(アプリ名).dart」のファイルをコードエディタで変更します。

※今回は Visual Studio Codeを使用しています。Dartの算術演算子を使ってみます。

コードエディタで変更後、ファイルを保存します。

dart run

保存後、コマンドプロンプトで作成したアプリ内に移動し、上記のコマンドを入力し、Enterキーを押します。

Enterキーを押すと、変更したコードの内容でアプリが実行されることを確認できました。

■本番用にコンパイルする

確認できましたので、本番用にコンパイル(コンピュータが実行可能な形式に変換する)を行ってみます。

dart compile exe bin/(アプリ名).dart

コンパイルする場合は、コマンドプロンプトで作成したアプリ内に移動し、上記のコマンドを入力し、Enterキーを押します。

Generated: c:\users\administrator\(アプリ名)\bin\(アプリ名).exe

上記のようなメッセージが表示されます。これでコンパイルは完了です。

コメント

タイトルとURLをコピーしました