前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >用vscode创建第一个flutter项目

用vscode创建第一个flutter项目

作者头像
徐建国
发布2021-11-30 20:43:24
5560
发布2021-11-30 20:43:24
举报
文章被收录于专栏:个人路线个人路线

今天教大家

用vscode创建第一个项目

创建新项目

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

默认第一个。直接按return

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

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

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

启动调试

运行-启动调试

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

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

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

5B3EC55B-F3B8-4969-B0FF-E7B11848A2B8

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

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

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

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

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

69B9A0B4-D7A0-4BE0-942A-14193591ABA6

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

227A35FB-8CC9-4E7D-967D-AEDFB6BA8B63

web/index.html

代码语言:javascript
复制
<!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

代码语言:javascript
复制
// 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

代码语言:javascript
复制
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 上面而且不是试验性质的,是正式版的,这是令人多么激动无比啊,我也情不自禁为其写下一篇相关文章。

本文参与 腾讯云自媒体分享计划,分享自微信公众号。
原始发表:2021-11-19,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 坚果前端 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 创建新项目
  • web/index.html
  • web/main.dart
  • lib/main.dart
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档