Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to modify plugins Dart code Flutter?

Tags:

flutter

dart

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:

like image 415
grepLines Avatar asked Nov 14 '17 22:11

grepLines


3 Answers

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.dartlang.org/flutter_abc-0.4.1

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

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

like image 123
thachnb Avatar answered Sep 18 '22 14:09

thachnb


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.

like image 32
Owczar Avatar answered Sep 22 '22 14:09

Owczar


With the git reposity of the desired plugin here

Clone it.

Make your modification

Submit a pull request.

And done

like image 43
Rémi Rousselet Avatar answered Sep 18 '22 14:09

Rémi Rousselet