我如何 运行 来自 Flutter package/library 的示例?
How can I run an example from a Flutter package/library?
我有以下简单的目录结构:
flutter_published
.idea
android
build
ios
lib
main.dart
flutter_published.iml
pubspec.lock
pubspec.yaml
network_to_file_image
.idea
example
main.dart
lib
network_to_file_image.dart
test
network_to_file_image.iml
pubspec.lock
pubspec.yaml
network_to_file_image
是一个包。
有两个 main.dart files
,一个在 flutter_published/lib/main.dart
和
另一个在 flutter_published/network_to_file_image/example/main.dart
我可以 运行 第一个,但不能 network_to_file_image
下的 example
目录中的那个。第二个给我这个错误:
Launching example\lib\main.dart on Android SDK built for x86 in debug mode...
No application found for TargetPlatform.android_x86.
Is your project missing an android\AndroidManifest.xml?
Consider running "flutter create ." to create one.
此外,生成应用程序时,我使用的包的 example
和 test
目录会发生什么变化?它们是包含在部署的最终应用程序中还是从中删除?
example/main.dart
只存在于 https://pub.dartlang.org/packages/network_to_file_image#-example-tab-
中显示
发布站点在示例目录中查找内容以显示在 Example
选项卡中的方式受到限制。
为了解决这个问题,需要在example
目录中创建一个完整的Flutter应用程序类型的项目,而不是example
目录中的main.dart
文件。然后,示例选项卡将指向该目录中的 README.md
文件。
example
目录将有自己的 lib
目录,其中包含一个 main.dart
文件。由于该文件现在位于应用程序类型目录中,因此它可以是 运行.
访问此存储库以查看其工作原理:
https://github.com/marcglasberg/async_redux/tree/master/example
更新:
需要说明的是,示例的 pubspec.yaml
文件可以使用相对引用来引用其包。例如,这是我提到的 async_redux
包的 example
目录的 dependencies
部分:
dependencies:
http: ^0.13.1
async_redux:
path: ../
flutter:
sdk: flutter
由于 example
目录与包的 pubspec.yaml
文件处于同一级别,因此示例自己的 pubspec.yaml
目录比它低一级。因此,它可以使用 ../
路径引用包本身:
async_redux:
path: ../
cd 到目录执行flutter create .
。之后你应该可以 运行
我有以下简单的目录结构:
flutter_published
.idea
android
build
ios
lib
main.dart
flutter_published.iml
pubspec.lock
pubspec.yaml
network_to_file_image
.idea
example
main.dart
lib
network_to_file_image.dart
test
network_to_file_image.iml
pubspec.lock
pubspec.yaml
network_to_file_image
是一个包。
有两个 main.dart files
,一个在 flutter_published/lib/main.dart
和
另一个在 flutter_published/network_to_file_image/example/main.dart
我可以 运行 第一个,但不能 network_to_file_image
下的 example
目录中的那个。第二个给我这个错误:
Launching example\lib\main.dart on Android SDK built for x86 in debug mode...
No application found for TargetPlatform.android_x86.
Is your project missing an android\AndroidManifest.xml?
Consider running "flutter create ." to create one.
此外,生成应用程序时,我使用的包的 example
和 test
目录会发生什么变化?它们是包含在部署的最终应用程序中还是从中删除?
example/main.dart
只存在于 https://pub.dartlang.org/packages/network_to_file_image#-example-tab-
发布站点在示例目录中查找内容以显示在 Example
选项卡中的方式受到限制。
为了解决这个问题,需要在example
目录中创建一个完整的Flutter应用程序类型的项目,而不是example
目录中的main.dart
文件。然后,示例选项卡将指向该目录中的 README.md
文件。
example
目录将有自己的 lib
目录,其中包含一个 main.dart
文件。由于该文件现在位于应用程序类型目录中,因此它可以是 运行.
访问此存储库以查看其工作原理:
https://github.com/marcglasberg/async_redux/tree/master/example
更新:
需要说明的是,示例的 pubspec.yaml
文件可以使用相对引用来引用其包。例如,这是我提到的 async_redux
包的 example
目录的 dependencies
部分:
dependencies:
http: ^0.13.1
async_redux:
path: ../
flutter:
sdk: flutter
由于 example
目录与包的 pubspec.yaml
文件处于同一级别,因此示例自己的 pubspec.yaml
目录比它低一级。因此,它可以使用 ../
路径引用包本身:
async_redux:
path: ../
cd 到目录执行flutter create .
。之后你应该可以 运行