5

I want to edit a plugin to fit into my App. I just did that by CTRL+clicking on the plugin import code in flutter and editing the desired .dart file.

Now I wonder, if this could be overwritten in the future.

The path (where I edited the dart file) is:

flutter > .pub-cache > hosted > pub.dartlang.org > PLUGIN NAME > lib > templates > FILENAME.dart

Was this the right way to edit the plugin? Or where should I edit the .dart file?

Thanks for help!

Daniel
  • 101
  • 1
  • 3
  • 15

1 Answers1

7

I would advise you to firstly check the license of the package you are editing to see if you are legally allowed to change it. Nevertheless, lets imagine you are and you want to go on.

If you edit a plugin like that, you are just editing your cached version of that plugin. This changes only persist as long as the cache is not updated.

However, if you want your changes to be persistent, you should fork the Github repository and edit the files there. Once you have edited the files in Github you can import them to your project, knowing that they won't be changed unexpectedly.

To import your new forked repository from Github, you go to the pubspec.yaml file and then import it like this:

my_forked_package:
  git:
    url: git://github.com/'YOUR_USERNAME'/my_forked_package.git

Similarly, you can just download the Github repository as a Zip, unZip it wherever you want (not in the project folder) and then import the package like this:

my_forked_package:
  path: 'path_to_package_folder'

I hope this helps you further develop your app!

  • Thanks for your help! But I have some problems with the implementation. I downloaded the zip. Should I create a new folder in the main root of my App project and copy the .zip into it? Should I unzip the zip file? Would it look like this? : my_forked_package: path: 'Foldername/unzipFoldername/' ? And how should the import ' ' in the .dart file where I want to use the plugin should look like? Thanks for help! – Daniel Apr 28 '20 at 19:44
  • unZip it wherever you want (not in the project folder) and the path would be : C/users/downloaded_package/ for example. I hope this clarifies it. – Francisco Javier Snchez Apr 28 '20 at 19:51
  • Thanks, I could figure it out in the mean time. But it worked like I wrote above. So I created a new folder in my App-Project-Folder (where e.g. also the lib folder is located), and than I unzip the plugin into this folder. And it worked like path:'Foldername/unzipFoldername/' – Daniel Apr 28 '20 at 20:06
  • Thanks Francisco. How would you do this for Flutter plugins in the the `flutter/plugins` repo? – Ben Butterworth Jul 22 '20 at 09:13
  • Oh, solved: just use the folder the plugin is in, inside that repo. (I have not built the app yet though) – Ben Butterworth Jul 22 '20 at 09:17