用 vscode 创建第一个 flutter 项目

简介: 今天教大家用 vscode 创建第一个项目创建新项目在安装了 Flutter 扩展的 VS Code 中,通过选择 View ▸ Command Palette...或在 macOS 上按 Command-Shift-P 或在 Linux 或 Windows 上按 Control-Shift-P 打开命令面板。在面板中输入 Flutter: New 并按 Return。

用 vscode 创建第一个项目

创建新项目

在安装了 Flutter 扩展的 VS Code 中,通过选择 View ▸ Command Palette...或在 macOS 上按 Command-Shift-P 或在 Linux 或 Windows 上按 Control-Shift-P 打开命令面板。在面板中输入 Flutter: New 并按 Return


image.png


默认第一个。直接按 return


image.png


这个时候选择一个文件夹创建。


image.png


然后返回这个界面。给自己的项目命名。


image.png


这个就是创建后的项目结构


image.png


启动调试


运行-启动调试


image.png


我没有连真机,所以显示的是我安装的浏览器


然后直接运行,VSCode 只需要按 F5 快捷键就行了。


然后你就可以看到 VSCode 弹出一个框让你选择运行项目的环境:


image.png


老铁,听我说,选 “ Dart & Flutter ” 就对了。


然后稍等一下吧,项目会编译,然后自动生成内容,其实就是 Dart 转换成 JavaScript 的过程。


Dart 原本就是(谷歌)想代替 JavaScript 而发明的,可以转换成 JavaScript 代码。


感觉 Dart 走了曲线救国的方式,终于走到这步 —— 代替 JavaScript。


最后,你会看到你系统默认的浏览器会弹出一个新的窗口来运行你的项目。(感觉刚开始有点慢吧。。。。)


image.png


下面我们来看看项目的目录:

image.png


web/index.html

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title></title>
  <script defer src="main.dart.js" type="application/javascript"></script>
</head>
<body>
</body>
</html>

复制代码

web/main.dart

// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter_web_ui/ui.dart' as ui;
import 'package:aaaaaaa/main.dart' as app;
main() async {
  await ui.webOnlyInitializePlatform();
  app.main();
}

复制代码

lib/main.dart

import 'package:flutter_web/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}
class MyHomePage extends StatelessWidget {
  MyHomePage({Key key, this.title}) : super(key: key);
  final String title;
  @override
  Widget build(BuildContext context) {
    // The Flutter framework has been optimized to make rerunning build methods
    // fast, so that you can just rebuild anything that needs updating rather
    // than having to individually change instances of widgets.
    return Scaffold(
      appBar: AppBar(
        title: Text(title),
      ),
      body: Center(
        // Center is a layout widget. It takes a single child and positions it
        // in the middle of the parent.
        child: Column(
          // Column is also layout widget. It takes a list of children and
          // arranges them vertically. By default, it sizes itself to fit its
          // children horizontally, and tries to be as tall as its parent.
          //
          // Invoke "debug painting" (choose the "Toggle Debug Paint" action
          // from the Flutter Inspector in Android Studio, or the "Toggle Debug
          // Paint" command in Visual Studio Code) to see the wireframe for each
          // widget.
          //
          // Column has various properties to control how it sizes itself and
          // how it positions its children. Here we use mainAxisAlignment to
          // center the children vertically; the main axis here is the vertical
          // axis because Columns are vertical (the cross axis would be
          // horizontal).
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Text(
              'Hello, World!',
            ),
          ],
        ),
      ), // This trailing comma makes auto-formatting nicer for build methods.
    );
  }
}

复制代码


本文就大致介绍到这里吧,不管怎么说 Flutter 跑在 Web 上面而且不是试验性质的,是正式版的,这是令人多么激动无比啊,我也情不自禁为其写下一篇相关文章。

相关文章
|
2月前
|
设计模式 前端开发 测试技术
Flutter 项目架构技术指南
探讨Flutter项目代码组织架构的关键方面和建议。了解设计原则SOLID、Clean Architecture,以及架构模式MVC、MVP、MVVM,如何有机结合使用,打造优秀的应用架构。
Flutter 项目架构技术指南
|
5月前
|
移动开发 前端开发 JavaScript
VSCode设置类似Webstorm那样可以用本地局域网IP地址访问自己开发的测试项目,vs code 前端如何以服务器模式打开?
VSCode设置类似Webstorm那样可以用本地局域网IP地址访问自己开发的测试项目,vs code 前端如何以服务器模式打开?
VSCode设置类似Webstorm那样可以用本地局域网IP地址访问自己开发的测试项目,vs code 前端如何以服务器模式打开?
|
1月前
|
前端开发 Python
在vscode中如何配置Django项目
在vscode中如何配置Django项目
18 0
|
1月前
|
Ubuntu 关系型数据库 MySQL
ubuntu部署python环境,vscode编辑wsl项目遇到的问题汇总
ubuntu部署python环境,vscode编辑wsl项目遇到的问题汇总
|
6月前
|
JavaScript C++ Windows
VS code运行vue项目
VS code运行vue项目
317 0
|
8月前
Flutter MAC VSCode 常用快捷键和命令行
Flutter MAC VSCode 常用快捷键和命令行
112 0
|
4月前
|
IDE 前端开发 搜索推荐
5款超好用的在线IDE,媲美vscode,可以直接编写前端构建化项目,而无需在本地下载依赖包,非常适合学习、demo、原型开发
5款超好用的在线IDE,媲美vscode,可以直接编写前端构建化项目,而无需在本地下载依赖包,非常适合学习、demo、原型开发
110 0
|
4月前
uniapp项目实践第二章:使用vscode开发uniapp项目
uniapp项目实践第二章:使用vscode开发uniapp项目
254 0
|
4月前
|
JSON NoSQL C++
VScode调试C/C++项目调试多个C++程序makefile
VScode调试C/C++项目调试多个C++程序makefile
79 0
|
4月前
|
JSON NoSQL C++
VScode调试C/C++项目调试多个C++程序
VScode调试C/C++项目调试多个C++程序
43 0