简体   繁体   English

有没有办法为整个包/lib/文件夹设置`//@dart=2.12`?

[英]Is there a way to set `//@dart=2.12` for an entire package/lib/folder?

When migrating large code bases to nnbd, it would be helpful if we could opt entire local packages in/out of NNBD.在将大型代码库迁移到 nnbd 时,如果我们可以选择整个本地包加入/退出 NNBD,将会很有帮助。 For example, I may want to migrate some of my leaf nodes first, like /lib/helper_widgets/* before moving onto the higher-order views.例如,我可能想先迁移一些叶节点,例如/lib/helper_widgets/* ,然后再迁移到高阶视图。

Currently dart supports this on a per file basis using // @dart=2.12 which is fairly tedious if your package has many files.目前 dart 使用// @dart=2.12在每个文件的基础上支持此功能,如果您的 package 有很多文件,这是相当乏味的。

I was hoping I could do this with lib and part of , but this just gives me a compile error, to add a header to each file.我希望我可以使用libpart of来做到这一点,但这只会给我一个编译错误,将 header 添加到每个文件中。

[Edit] A pragmatic solution here is to run something like find. -name "*.dart" | xargs sed -i "1s/^/\/\/ @dart=2.9\n/" [编辑] 一个实用的解决方案是运行find. -name "*.dart" | xargs sed -i "1s/^/\/\/ @dart=2.9\n/" find. -name "*.dart" | xargs sed -i "1s/^/\/\/ @dart=2.9\n/" find. -name "*.dart" | xargs sed -i "1s/^/\/\/ @dart=2.9\n/" on your project. find. -name "*.dart" | xargs sed -i "1s/^/\/\/ @dart=2.9\n/"在你的项目上。 That will put the 2.9 import in every file.这会将 2.9 导入到每个文件中。 At that pt, you can use find/replace to just turn on entire sub-directories of your /lib code.在那个 pt,您可以使用 find/replace 来打开 /lib 代码的整个子目录。

It's gonna be either per file, or with the pubspec.yaml .它可以是每个文件,也可以是pubspec.yaml The pubspec method will change the entire package. pubspec 方法会改变整个 package。 If you use dart migrate , that's one of the steps it performs.如果您使用dart migrate ,这是它执行的步骤之一。 Then be sure to dart pub upgrade , because a different set of dependencies will then be available.然后一定要dart pub upgrade ,因为随后会有一组不同的依赖项可用。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Flutter 中的 lib(dart) 文件夹的风格类似于 Android 中的 src 文件夹 - Flavor for lib(dart) folder in Flutter like src folder in Android Flutter 项目不再配置 lib 文件夹和 dart 文件 - Flutter projects are no longer being provisioned with the lib folder and dart files 即使安装了包,它也没有显示在 dart 包文件夹中 - Package is not showing up in the dart packages folder even though it is installed 在 Dart 2.12 中,以前使用带有 runtimeType 的开关的可能性是什么? - What's the replacement in Dart 2.12 for the previous possibility to use switch with runtimeType? 为什么 Dart 2.12 是次要 SDK 升级,但它破坏了之前的代码? - Why is Dart 2.12 a minor SDK upgrade when it breaks the previous code? 如何在切换到 Dart 2.12 后使用可比较的 function - How to adapt function using comparables after switching to Dart 2.12 如何在同一 lib 文件夹中的其他 screen.dart 文件中使用 main.dart 中的 flutter 变量? - How do i use flutter variables from main.dart in other screen.dart files in the same lib folder? 无法从导入的 flutter 项目中找到 main.dart 和 lib 文件夹 - unable to find main.dart and lib folder from imported flutter project Flutter/Dart:同步读取资产文件夹中的文件 - Flutter/Dart : synchronous way to read file in asset folder 在企业(私有)环境中托管 dart / flutter package 的官方方式是什么? - What is the official way to host dart / flutter package in enterprise (private) environment?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM