How to modify plugins Dart code Flutter?

后端 未结 4 1066
半阙折子戏
半阙折子戏 2020-12-14 18:01

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 cod

相关标签:
4条回答
  • 2020-12-14 18:24

    The most elegant way is to fork a repo, do all changes you need and commit them to your fork of the repo. After that you just need to add forked repo from git as a dependency in pubspec.yaml file.

    0 讨论(0)
  • 2020-12-14 18:27

    With the git reposity of the desired plugin here

    Clone it.

    Make your modification

    Submit a pull request.

    And done

    0 讨论(0)
  • 2020-12-14 18:40

    Here is step by step of how to modify plugin locally, my plugin named: flutter_abc-0.4.1

    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

    2. 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 the lib folder), then renaming version:

      For example: flutter_abc-0.4.1-hijacking

      Now you can modify whatever you want to fix bug locally.

    3. 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/

    0 讨论(0)
  • 2020-12-14 18:44

    We usually use packages by importing them in the files where we need them. To modify a plugin, you need to Ctrl + click on the import line (for e.g. import 'package:dio/dio.dart';) ctrl + clicking on this line will open the source code for this plugin. You can edit the code there. Remember, the change won't be permanent and if you push your code to git and then clone it later, the changes you've done will be reverted to the original. So to avoid this, you can just copy all the source code and make a separate dart file and copy and modify all the code there to play safe.

    0 讨论(0)
提交回复
热议问题