如何在命令行上创建和运行Dart项目

问题描述 投票:0回答:2

我想创建一个Dart项目来玩,但我无法弄清楚如何从命令行创建一个。

我试过了

dart create playground.dart

我也试过了

dart playground.dart 

但我粘贴的代码有依赖性要求。

dart
2个回答
4
投票

创建新项目的最简单方法是使用Stagehand。这与IntelliJ在创建新Dart项目时使用的相同。

您可以使用此命令安装它

pub global activate stagehand

然后你需要做的就是使用它

mkdir playground
cd playground
stagehand <generator-name>

这些是您现在可以使用的不同生成器:

  • console-full - 命令行应用程序示例。
  • package-simple - Dart库或应用程序的起点。
  • server-shelf - 使用shelf包构建的Web服务器。
  • web-angular - 具有材料设计组件的Web应用程序。
  • web-simple - 仅使用核心Dart库的Web应用程序。
  • web-stagexl - 2D动画和游戏的起点。

2
投票

1. Create a new folder

mkdir playground

2. Add a dart file with a main() function

playground.dart

void main() {
  print("hello world");
}

3. Run the app

dart playground.dart

If your app has dependencies...

4. Setup configuration

创建pubspec.yaml文件

touch pubspec.yaml

粘贴您拥有的任何依赖项

name: playground
description: Just a place to practice
version: 0.0.1
author: suragch

dependencies:
  crypto: ^2.0.6

5. Get dependencies

pub get
© www.soinside.com 2019 - 2024. All rights reserved.