[A-00119]Dartを使ってみる
dartをインストールして簡単なappを作成するところまでを記載
dartの後にFlutterも一緒にインストールします。
・インストール
下記は公式ページでSDKをダウンロードもしくはbrewでインストール
brew install dart
インストールが完了したら下記を実行する
dart --version
MacBook-Pro:Dart$ dart --version
Dart SDK version: 3.0.7 (stable) (Mon Jul 24 13:17:56 2023 +0000) on "macos_x64"
・簡単なアプリの作成
下記は公式ページで紹介しているチュートリアル
https://dart.dev/tutorials/server/get-started
適当なディレクトリを作成して下記のコマンドを実行
dart create -t console cli
MacBook-Pro:test1-pj$ dart create -t console cli
╔════════════════════════════════════════════════════════════════════════════╗
║ The Dart tool uses Google Analytics to report feature usage statistics ║
║ and to send basic crash reports. This data is used to help improve the ║
║ Dart platform and tools over time. ║
║ ║
║ To disable reporting of analytics, run: ║
║ ║
║ dart --disable-analytics ║
║ ║
╚════════════════════════════════════════════════════════════════════════════╝
Creating cli using template console...
.gitignore
analysis_options.yaml
CHANGELOG.md
pubspec.yaml
README.md
bin/cli.dart
lib/cli.dart
test/cli_test.dart
Running pub get... 9.7s
Resolving dependencies...
Changed 46 dependencies!
Created project cli in cli! In order to get started, run the following commands:
cd cli
dart run
作成されたディレクトリ直下で下記のコマンドを実行
dart run
MacBook-Pro:test1-pj$ ls
cli
MacBook-Pro:test1-pj$ cd cli/
MacBook-Pro:cli$ ls
CHANGELOG.md analysis_options.yaml lib pubspec.yaml
README.md bin pubspec.lock test
MacBook-Pro:cli$ dart run
Building package executable...
Built cli:cli.
Hello world: 42!
・Flutterもインストールしてみる。
下記の公式サイトからSDKを取得する。
https://docs.flutter.dev/get-started/install/macos
上記はzipファイルなので解凍して適当な場所に配置
flutter/binにパスを通す。.bash_profileを下記の通り編集する
FLUTTER_PATH="/Users/xxxx/flutter/bin"
PATH="${FLUTTER_PATH}:${PATH}"
export PATH
source ~/.bash_profile
下記のコマンドでflutterが実行できるか確認する
flutter --version
(base) MacBook-Pro:~$ flutter --version
Flutter 3.13.2 • channel stable • https://github.com/flutter/flutter.git
Framework • revision ff5b5b5fa6 (12 days ago) • 2023-08-24 08:12:28 -0500
Engine • revision b20183e040
Tools • Dart 3.1.0 • DevTools 2.25.0
コメントを残す