如何修改插件 Dart 代码 Flutter? [英] How to modify plugins Dart code Flutter?
问题描述
我正在开发 Flutter 应用程序,它使用 map_view 插件.我想通过修改源代码为插件添加新功能.通过 Flutter 安装插件后,如何在我的项目中找到插件的实际源代码?
Flutter 中插件是如何添加的
map_view
插件的依赖添加到pubspec.yaml
如下,然后运行flutter packages get
将它添加到项目中.开发依赖:地图视图:
这里是如何在本地修改插件的步骤,我的插件名为:flutter_abc-0.4.1
右键单击包/插件的导入文件名,选择在 Finder 中显示或按住 CMD + 单击该文件名以转到该文件,然后右键单击文件中的任意位置并选择在 Finder 中显示".
通常它位于
~/.pub-cache/hosted/pub.darlang.org/flutter_abc-0.4.1
将整个包文件夹复制到您的应用程序文件夹
为了方便劫持文件,只需将所有文件复制到您的应用程序文件夹(与
pubspec.yaml
相同级别,而不是在lib
文件夹中),然后重命名版本:>例如:
flutter_abc-0.4.1-hijacking
现在您可以修改任何想要在本地修复错误的内容.
修改 pubspec.yaml 指向本地包
打开你的项目 pubspec.yaml将依赖路径更改为,例如:
flutter_abc:路径:./flutter_abcd-0.4.1-hijacking/
I am developing a Flutter app, and it uses map_view plugin. I want to add new functionalities to the plugin by modifying the source code. How do I find the actual source code of the plugin in my project after installing it through Flutter?
How plugin is added in Flutter
The dependency for map_view
plugin is added to pubspec.yaml
as below, then running flutter packages get
will add it to the project.
dev_dependecies:
map_view:
Here is step by step of how to modify plugin locally, my plugin named: flutter_abc-0.4.1
Right click on package/plugin's import file name, choose Reveal in Finder Or hold CMD + Click on that file name to go to that file, then Right click anywhere in the file and choose "Reveal in Finder".
Normally it's located at
~/.pub-cache/hosted/pub.darlang.org/flutter_abc-0.4.1
Copy whole package folder to your app folder
For easy hijacking files, just copy all to your app folder (same level with
pubspec.yaml
, not in thelib
folder), then renaming version:For example:
flutter_abc-0.4.1-hijacking
Now you can modify whatever you want to fix bug locally.
Modify pubspec.yaml to point to local package
Open your project pubspec.yaml Change path of dependencies to, for example:
flutter_abc: path: ./flutter_abcd-0.4.1-hijacking/
这篇关于如何修改插件 Dart 代码 Flutter?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!