dart学习: 开始一个项目

更新于: 2024-06-24 09:23:09


到目标目录,创建项目 playground 并运行

cd ~/aric-notes/dart-notes
dart create playground
dart run


安装包 dart pub add

dart pub add jsw_calculator


编辑这个文件: ~/aric-notes/dart-notes/playground/bin/playground.dart

import 'package:jsw_calculator/jsw_calculator.dart' as jsw_calculator;

void main(List<String> arguments) {
  print('Hello world: ${jsw_calculator.add(1, 2)}!');


dart pub add jsw_calculator
dart pub add jsw_calculator --dev
dart pub get


$ dart pub -h
Work with packages.

Usage: dart pub [arguments...]
-h, --help               Print this usage information.
-v, --verbose            Print detailed logging.
    --[no-]color         Use colors in terminal output.
                         Defaults to color when connected to a terminal, and
                         no-color otherwise.
-C, --directory=<dir>    Run the subcommand in the directory<dir>.
                         (defaults to ".")

Available subcommands:
  add         Add dependencies to `pubspec.yaml`.
  cache       Work with the system cache.
  deps        Print package dependencies.
  downgrade   Downgrade the current package's dependencies to oldest versions.
  get         Get the current package's dependencies.
  global      Work with global packages.
  login       Log into pub.dev.
  logout      Log out of pub.dev.
  outdated    Analyze your dependencies to find which ones can be upgraded.
  publish     Publish the current package to pub.dev.
  remove      Removes dependencies from `pubspec.yaml`.
  token       Manage authentication tokens for hosted pub repositories.
  upgrade     Upgrade the current package's dependencies to latest versions.

Run "dart help" to see global options.
See https://dart.dev/tools/pub/cmd/pub-global for detailed documentation.