英文:
Flutter Create Spawns app That Contains Unexpected Folders and Files
问题
关于一周前,我使用以下命令创建了一个新的Flutter项目:
flutter create -t app my_app
但当我在集成开发环境中打开生成的项目时,我惊讶地发现该项目与我习惯的项目有一些关键差异:
- 在lib文件夹内有一个名为"src"的文件夹。
- main.dart文件不包含通常的"计数器应用程序",而是如下所示:
import 'package:flutter/material.dart';
import 'src/app.dart';
import 'src/settings/settings_controller.dart';
import 'src/settings/settings_service.dart';
void main() async {
// 设置SettingsController,将用户设置与多个Flutter小部件连接起来。
final settingsController = SettingsController(SettingsService());
// 在显示闪屏屏幕时加载用户的首选主题。
// 这可以防止应用程序首次显示时主题突然更改。
await settingsController.loadSettings();
// 运行应用程序并传递SettingsController。应用程序会侦听SettingsController的更改,然后将其进一步传递给SettingsView。
runApp(MyApp(settingsController: settingsController));
}
我尝试创建其他新项目,并验证了当使用"flutter create -t skeleton"时,也发生了相同的情况。
现在,一周后,似乎已经恢复到旧的行为。
有人知道这背后的解释吗?
英文:
About a week ago, I created a new flutter project using:
flutter create -t app my_app
But when I opened the resulting project in the IDE, I was surprised to find the project has some key differences compared to what I'm used to:
- there is a folder inside the lib folder, "src"
- the main.dart does not contain the usual "counter app" and looks like this:
import 'package:flutter/material.dart';
import 'src/app.dart';
import 'src/settings/settings_controller.dart';
import 'src/settings/settings_service.dart';
void main() async {
// Set up the SettingsController, which will glue user settings to multiple
// Flutter Widgets.
final settingsController = SettingsController(SettingsService());
// Load the user's preferred theme while the splash screen is displayed.
// This prevents a sudden theme change when the app is first displayed.
await settingsController.loadSettings();
// Run the app and pass in the SettingsController. The app listens to the
// SettingsController for changes, then passes it further down to the
// SettingsView.
runApp(MyApp(settingsController: settingsController));
}
I tried creating other new projects and I verified it also happened when using "flutter create -t skeleton."
Now, after a week, it seems to have gone back to the old behavior.
Does anyone know the explanation for this?
答案1
得分: 1
你可能运行了以下命令:
flutter create -t skeleton my_app
那么你的项目将会和你描述的一样。你可以在这里看到。
如果你运行了以下命令:
flutter create -t app my_app
或者
flutter create my_app
那么一个默认的计数应用程序将会被创建,可以在这里找到。
可能存在未发现的错误。但要解决这个问题,你需要知道你当时使用的Flutter精确版本,以及你输入的完整命令。只有这样才能重现问题。一切都正常吗?
英文:
You probably ran the command
flutter create -t skeleton my_app
Then that's exactly what your project will look like, as you described. This can be seen here.
If you run
flutter create -t app my_app
or
flutter create my_app
then a default counter application must be created, as here
There may have been an undiscovered error. But to do this, you need to know the exact version of flutter you were using at the time, and the 100% command you entered. That's how it could be repeated. Is everything all right now?
答案2
得分: 0
首先让我描述一下 flutter create -t skeleton
是什么:
多年来,每次创建新项目时,Flutter都会提供基本的 计数器应用
。
虽然这个示例很好地介绍了 StatefulWidget
的基本概念以及基本的字体/资源管理,但它并不真正类似于一个完整的应用程序
的结构。
这使得开发人员在创建基本单页面应用之外没有得到更多的指导。
为了解决这个问题,Flutter团队一直在努力开发一个新的模板,其陈述的目标是:
让开发人员更容易继续他们的学习之旅,超越计数器应用。与原始的计数器应用模板共存,而不是替代它。
新的模板已于2021年6月合并到主分支,您可以使用以下命令创建它:
flutter create -t skeleton 你的项目名称
现在你发生了什么?
我猜你的项目名字是 my_app
。
这段代码是通过运行 flutter create -t skeleton my_app
创建的,与 flutter create -t app my_app
语句非常相似。
英文:
At first let me describe what is flutter create -t skeleton
:
For many years Flutter has provided the basic Counter App
each time you created a new project.
While that example provides a nice introduction to the foundational concepts of StatefulWidget
and basic font/asset management, it does not really resemble the structure of a complete app
.
This has left developers without guidance for anything beyond a basic single page app.
To fix this issue the Flutter team have been hard at work on a new template with the stated goals:
Make it easier for developers to continue their learning journey beyond the Counter app.Co-exist with the original Counter app template.It is not a replacement.
The new template was merged into master in June 2021, and you can create it with this command:
flutter create -t skeleton your_project_name
Now what happened to you ?
I guess your name of project is my_app
.
And this code created by run flutter create -t skeleton my_app
and very similar to flutter create -t app my_app
statement .
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论