From eeb26e1aa95efae3626ae0ad3b4e3e9bbbe63ff8 Mon Sep 17 00:00:00 2001 From: Xingyu Wang Date: Sat, 23 Nov 2019 10:01:34 +0800 Subject: [PATCH 1/2] PRF @geekpi --- ... a Simple Web Application Using Flutter.md | 126 +++++++++--------- 1 file changed, 63 insertions(+), 63 deletions(-) diff --git a/translated/tech/20191115 Developing a Simple Web Application Using Flutter.md b/translated/tech/20191115 Developing a Simple Web Application Using Flutter.md index a29e2e4d91..2fb198f595 100644 --- a/translated/tech/20191115 Developing a Simple Web Application Using Flutter.md +++ b/translated/tech/20191115 Developing a Simple Web Application Using Flutter.md @@ -1,6 +1,6 @@ [#]: collector: (lujun9972) [#]: translator: (geekpi) -[#]: reviewer: ( ) +[#]: reviewer: (wxy) [#]: publisher: ( ) [#]: url: ( ) [#]: subject: (Developing a Simple Web Application Using Flutter) @@ -10,35 +10,39 @@ 使用 Flutter 开发简单的 Web 应用 ====== -[![][1]][2] +![][2] -_本文指导读者如何使用 Flutter 运行和部署第一个 Web 应用。_ +> 本文指导读者如何使用 Flutter 运行和部署第一个 Web 应用。 -Flutter 在 Android 和 iOS 开发方面走了很长一段路之后,已经迈入了一个新的阶段,即 Web。Google 发布了 Flutter 1.5,同时支持 Web 应用开发。 +Flutter 在 Android 和 iOS 开发方面走了很长一段路之后,已经迈入了一个新的阶段,即 Web 开发。Google 发布了 Flutter 1.5,同时支持 Web 应用开发。 -**为 Web 配置 Flutter** -为了使用 Web 包,输入命令 _flutter upgrade_ 更新到 Flutter 1.5.4。 +### 为 Web 开发配置 Flutter + +为了使用 Web 包,输入命令 `flutter upgrade` 更新到 Flutter 1.5.4。 * 打开终端 - * 输入 flutter upgrade - * 输入 _flutter –version_ 检查版本 + * 输入 `flutter upgrade` + * 输入 `flutter –version` 检查版本 - -![Figure 1: Upgrading Flutter to the latest version][3] - -![Figure 2: Starting a new Flutter Web project in VSC][4] +![图 1: 升级 Flutter 到最新版][3] 也可以将 Android Studio 3.0 或更高版本用于 Flutter Web 开发,但在本教程中,我们使用 Visual Studio Code。 -**使用 Flutter Web 创建新项目** -打开 Visual Studio Code,然后按 _Shift+Ctrl+P_ 开始一个新项目。输入 flutter 并选择 _New Web Project_。 -现在,为项目命名。我将其命名为 _open_source_for_you_。 +### 使用 Flutter Web 创建新项目 + +打开 Visual Studio Code,然后按 `Shift+Ctrl+P` 开始一个新项目。输入 `flutter` 并选择 “New Web Project”。 + +![图 2:在 VSC 中开始一个新的 Flatter 项目][4] + +现在,为项目命名。我将其命名为 `open_source_for_you`。 + +![图 3: 给项目命名][5] + 在 VSC 中打开终端窗口,然后输入以下命令: ``` flutter packages pub global activate webdev - flutter packages upgrade ``` @@ -48,78 +52,74 @@ flutter packages upgrade flutter packages pub global run webdev serve ``` -打开任何浏览器,然后输入 __。 -在项目目录中有个 Web 文件夹,其中包含了 _index.html_。 _dart_ 文件被编译成 JavaScript 文件,并使用以下代码包含在 HTML 文件中: +打开任何浏览器,然后输入 `http://127.0.0.1:8080/`。 + + +![图 4:运行于 8080 端口的 Flutter 演示应用][6] + +在项目目录中有个 Web 文件夹,其中包含了 `index.html`。`dart` 文件被编译成 JavaScript 文件,并使用以下代码包含在 HTML 文件中: ``` ``` -**编码和修改演示页面** -让我们创建一个简单的应用,它会在网页上打印 “ Welcome to OSFY”。 -现在打开 Dart 文件,它位于 _lib_ 文件夹 _main.dart_(默认名)中(参见图 5)。 -现在,我们可以在 _MaterialApp_ 的属性中删除调试标记,如下所示: +### 编码和修改演示页面 + +让我们创建一个简单的应用,它会在网页上打印 “Welcome to OSFY”。 + +现在打开 Dart 文件,它位于 `lib` 文件夹 `main.dart`(默认名)中(参见图 5)。 + +![图 5:main.dart 文件的位置][7] + +现在,我们可以在 `MaterialApp` 的属性中删除调试标记,如下所示: ``` debugShowCheckedModeBanner: false ``` -![Figure 3: Naming the project][5] +现在,向 Dart 中添加更多内容与用 Dart 编写 Flutter 很类似。为此,我们可以声明一个名为 `MyClass` 的类,它继承了 `StatelessWidget`。 -![Figure 4: The Flutter demo application running on port 8080][6] - -![Figure 5: Location of main.dart file][7] - -现在,向 Dart 中添加更多内容与在 Dart 中编写 Flutter 类似。为此,我们可以声明一个名为 _MyClass_ 的类,它继承了 _StatelessWidget_。 -我们使用 _Center_ 部件将元素定位到中心。我们还可以添加 _Padding_ 部件来添加填充。使用以下代码获得图 5 所示的输出。使用刷新按钮查看更改。 +我们使用 `Center` 部件将元素定位到中心。我们还可以添加 `Padding` 部件来添加填充。使用以下代码获得图 5 所示的输出。使用刷新按钮查看更改。 ``` class MyClass extends StatelessWidget { -@override -Widget build(BuildContext context) { -return Scaffold( -body: Center( -child: Column( -mainAxisAlignment: MainAxisAlignment.center, -children: [ -Padding( -padding: EdgeInsets.all(20.0), -child: Text( -'Welcome to OSFY', -style: TextStyle(fontSize: 24.0, fontWeight: FontWeight.bold), -), -), -], -), -), -); -} + @override + Widget build(BuildContext context) { + return Scaffold( + body: Center( + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Padding( + padding: EdgeInsets.all(20.0), + child: Text( + 'Welcome to OSFY', + style: TextStyle(fontSize: 24.0, fontWeight: FontWeight.bold), + ), + ), + ], + ), + ), + ); + } } ``` -![Figure 6: Output of MyClass][8] +![图 6:MyClass 的输出][8] -![Figure 7: Final output][9] - -让我们从互联网中添加一张图片,我已经从一个杂志网站选择了一张 “Open Source for You” 的 logo。我们使用 _Image.network_。 +让我们从互联网中添加一张图片,我已经从一个杂志网站选择了一张 “Open Source for You” 徽标。我们使用 `Image.network`。 ``` Image.network( -'https://opensourceforu.com/wp-content/uploads/2014/03/OSFY-Logo.jpg', -height: 100, -width: 150 + 'https://opensourceforu.com/wp-content/uploads/2014/03/OSFY-Logo.jpg', + height: 100, + width: 150 ), ``` 最终输出如图 7 所示。 -![Avatar][10] - -[Jis Joe Mathew][11] - -作者是喀拉拉邦卡尼拉帕利阿玛尔·乔蒂学院的计算机科学与工程助理教授。可以通过 [jisjoemathew@gmail.com][12] 与他联系。 - -[![][13]][14] +![图 7:最终输出][9] -------------------------------------------------------------------------------- @@ -128,7 +128,7 @@ via: https://opensourceforu.com/2019/11/developing-a-simple-web-application-usin 作者:[Jis Joe Mathew][a] 选题:[lujun9972][b] 译者:[geekpi](https://github.com/geekpi) -校对:[校对者ID](https://github.com/校对者ID) +校对:[wxy](https://github.com/wxy) 本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 From 69fe25e3b4ef509399d79dfe04c62b61b3aed64e Mon Sep 17 00:00:00 2001 From: Xingyu Wang Date: Sat, 23 Nov 2019 10:05:12 +0800 Subject: [PATCH 2/2] PUB @geekpi https://linux.cn/article-11604-1.html --- ... a Simple Web Application Using Flutter.md | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) rename {translated/tech => published}/20191115 Developing a Simple Web Application Using Flutter.md (89%) diff --git a/translated/tech/20191115 Developing a Simple Web Application Using Flutter.md b/published/20191115 Developing a Simple Web Application Using Flutter.md similarity index 89% rename from translated/tech/20191115 Developing a Simple Web Application Using Flutter.md rename to published/20191115 Developing a Simple Web Application Using Flutter.md index 2fb198f595..e52d81885a 100644 --- a/translated/tech/20191115 Developing a Simple Web Application Using Flutter.md +++ b/published/20191115 Developing a Simple Web Application Using Flutter.md @@ -1,8 +1,8 @@ [#]: collector: (lujun9972) [#]: translator: (geekpi) [#]: reviewer: (wxy) -[#]: publisher: ( ) -[#]: url: ( ) +[#]: publisher: (wxy) +[#]: url: (https://linux.cn/article-11604-1.html) [#]: subject: (Developing a Simple Web Application Using Flutter) [#]: via: (https://opensourceforu.com/2019/11/developing-a-simple-web-application-using/) [#]: author: (Jis Joe Mathew https://opensourceforu.com/author/jis-joe/) @@ -134,15 +134,15 @@ via: https://opensourceforu.com/2019/11/developing-a-simple-web-application-usin [a]: https://opensourceforu.com/author/jis-joe/ [b]: https://github.com/lujun9972 -[1]: https://i1.wp.com/opensourceforu.com/wp-content/uploads/2019/11/Screenshot-from-2019-11-15-16-20-30.png?resize=696%2C495&ssl=1 (Screenshot from 2019-11-15 16-20-30) -[2]: https://i1.wp.com/opensourceforu.com/wp-content/uploads/2019/11/Screenshot-from-2019-11-15-16-20-30.png?fit=900%2C640&ssl=1 -[3]: https://i0.wp.com/opensourceforu.com/wp-content/uploads/2019/11/Figure-1-Upgrading-Flutter-to-the-latest-version.jpg?resize=350%2C230&ssl=1 -[4]: https://i0.wp.com/opensourceforu.com/wp-content/uploads/2019/11/Figure-2-Starting-a-new-Flutter-Web-project-in-VSC.jpg?resize=350%2C93&ssl=1 -[5]: https://i2.wp.com/opensourceforu.com/wp-content/uploads/2019/11/Figure-3-Naming-the-project.jpg?resize=350%2C147&ssl=1 -[6]: https://i0.wp.com/opensourceforu.com/wp-content/uploads/2019/11/Figure-4-The-Flutter-demo-application-running-on-port-8080.jpg?resize=350%2C111&ssl=1 -[7]: https://i2.wp.com/opensourceforu.com/wp-content/uploads/2019/11/Figure-5-Location-of-main.dart-file.jpg?resize=350%2C173&ssl=1 -[8]: https://i2.wp.com/opensourceforu.com/wp-content/uploads/2019/11/Figure-6-Output-of-MyClass.jpg?resize=350%2C173&ssl=1 -[9]: https://i0.wp.com/opensourceforu.com/wp-content/uploads/2019/11/Figure-7-Final-output.jpg?resize=350%2C167&ssl=1 +[1]: https://i1.wp.com/opensourceforu.com/wp-content/uploads/2019/11/Screenshot-from-2019-11-15-16-20-30.png +[2]: https://i1.wp.com/opensourceforu.com/wp-content/uploads/2019/11/Screenshot-from-2019-11-15-16-20-30.png +[3]: https://i0.wp.com/opensourceforu.com/wp-content/uploads/2019/11/Figure-1-Upgrading-Flutter-to-the-latest-version.jpg +[4]: https://i0.wp.com/opensourceforu.com/wp-content/uploads/2019/11/Figure-2-Starting-a-new-Flutter-Web-project-in-VSC.jpg +[5]: https://i2.wp.com/opensourceforu.com/wp-content/uploads/2019/11/Figure-3-Naming-the-project.jpg +[6]: https://i0.wp.com/opensourceforu.com/wp-content/uploads/2019/11/Figure-4-The-Flutter-demo-application-running-on-port-8080.jpg +[7]: https://i2.wp.com/opensourceforu.com/wp-content/uploads/2019/11/Figure-5-Location-of-main.dart-file.jpg +[8]: https://i2.wp.com/opensourceforu.com/wp-content/uploads/2019/11/Figure-6-Output-of-MyClass.jpg +[9]: https://i0.wp.com/opensourceforu.com/wp-content/uploads/2019/11/Figure-7-Final-output.jpg [10]: https://secure.gravatar.com/avatar/64db0e07799ae14fd1b51d0633db6593?s=100&r=g [11]: https://opensourceforu.com/author/jis-joe/ [12]: mailto:jisjoemathew@gmail.com