How to modify plugins Dart code 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:

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

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.

With the git reposity of the desired plugin here
Clone it.
Make your modification
Submit a pull request.
And done

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.

It's worth stating that for quick testing / debugging, you can actually modify the code directly in your .pub-cache, e.g. .pub-cache/hosted/pub.dartlang.org/video_player-2.3.0/lib/video_player.dart. For it to take effect, you must fully restart your app, a hot reload won't work.

Related

Removing Swift Packages from Source Control XCode

I recently added some Swift Packages to my Xcode 11.3 project manually by dropping them onto the Project Navigator. This allows me to edit out some errors in the source.
By doing this, Xcode automatically adds these to Source Control.
I can't seem to find any way to remove them from Source Control from within Xcode. I would prefer to retain these as dependencies but commit them to my own source control and ignore master/remote.
Fetch and Refresh Status from Git yields:
This behaviour is instructed by Apple here: Editing a Package Dependency as a Local Package
To add the Swift package as local package to your project:
Check out your package dependency’s source code from its Git
repository.
Open your app’s Xcode project or workspace.
Select the Swift package’s folder in Finder and drag it into the
Project navigator. This action adds your dependency’s Swift package as
a local package to your project.
Make changes to the local package and your app, then verify them by
building and running your app.
When you’re done editing the local package, push your changes to its
remote Git repository.
When the changes have made it into the package’s next release, remove
the local package from your project, and update the package dependency
to the new version.
Step 5 here is broken. I don't have write access to that repo.
Other things I tried.
I've tried deleting Clean, Rebuild and deleting Derived Data
I've tried this SO answer however Blueprint.xcscmblueprint doesn't exist.
The problem you seem to be trying to solve is: You want to make changes to package source files in a maintainable way, and these are not your packages.
Clearly, of itself, that is a complete non-starter. These files don't belong to you, in any sense whatever. And as soon as a new version comes down from the remote repo, your changes will be overwritten anyway.
This sort of thing is always an issue when you rely on third-party code, especially in a dependency architecture like pods or packages. If there's a problem with the code, you can't fix it; it isn't your code.
One option is to create an Issue at GitHub and try to get the owners of the code to fix whatever the problem is.
Another possibility is to try to write "shim" code in your code, such as to fix whatever the issue is by plastering it over somehow.
Alternatively, since this package repo is presumably at GitHub, you can fork the repo. Now it is your package, and you can set up a dependency on that and make changes and push them up to your fork. Of course, the original ("upstream") repo may change, but then you will reconcile those changes with yours as a separate operation.
Still another possibility, of course, is to abandon the notion of package management and dependency entirely and just incorporate the desired source files directly into your project. Now they are yours and you can do with them what you like. (Be careful of copyright issues, of course. You may still have to give credit where credit is due.)
Download the third party library once. Make your changes. Create a patch file. Put the patch file in your source code control. This is followed by lots of manual work when yo want to switch to a different version of the third party library.

You must add a shared scheme in AppCenter

I wish to setup AppCenter BuildConfiguration for my GitLab iOS xCode Project.
I get the following error saying that I must add a shared scheme:
I follow the steps here to generate a scheme for my workspace: https://learn.microsoft.com/en-us/appcenter/build/troubleshooting/ios#no-scheme
The final step says: Add the .xcscheme file to source control and pushed to your remote repository so that App Center can access it.
Question:
Where is this .xcscheme file located whenever it is generated as I cant seem to find it?
What folder etc should it be in?
Try to share it here, in the "scheme editor". Then see if it shows up in our version control.
Else, apply any change to your scheme, you should then see file changes in your version control like this. Make sure that the file type is not added to your ignore list (e.g. git ignore).

How I can rename swift package

Is there some easy way to rename Swift Package?
I tried some standard ways but there wasn't result in finding quickly solution
Please help me, thanks in advance
Sorry guys i put it badly.
more description:
I have created SP in the my workspace a some time ago and now there are a lot links (imports of this package) around all project and now I want to rename this package. Special tool not avalible for this and i was looking some ather way to avoing a lot of routine work
Go into your Package.swift file and change any instance of your old name to your new name. Hit save, then your xcode project should update itself.
Sadly it doesn't look like there's a good way to do this, and when it's come up I've ended up making a new package with the correct name, moving all the code into it, and updating references to the old package to point to the new one.
Unfortunately I only found a manual way to do it.
These are the steps that I did to change OldName to NewName:
To change the package name that shown on Xcode, you can rename the root folder on your Finder
If your project are currently open, A popup will appear, you can just close the xcode.
Then you can re-open your package.swift file again.
Last, Rename the folder inside your Sources and Tests folder to the
new name. Also adjust your file name too.
I just renamed my package, which was easier than expected. As previously described, you have to do it manually.
Open your package in Xcode (not in a project)
Open the package.swift file and change the name everywhere
In your Sources folder is another folder with your package's name, rename that, too
If you don't use Git, that's pretty much it. If you do, you can commit your files (which will be a lot, because you renamed a parent folder) and change your repository's name. You probably have to clone it again, so there won't be any errors in the future.
After everything is renamed, you need to update your project(s). If you added your package locally, just search for all the import statements and change the name to your package's new name. If you added it via Github, remove the package dependency, add it again and then search for all the import statements and update them accordingly.

Xcode not able to find project file

In my Xcode project there are other projects linked but somehow its not able to read the sub project.
As you can see MobiResourceManager.xcodeproj is shown in red. And thus the classes which uses headers inside it gives error. But I am not able to understand why its not able to show the project. Sometimes it doesn't show MobiResourceManager.xcodeproj in red but even then the classes using its header gives error of HeaderName.h not found.
The problem that I am facing is happening only in my system. I tried cleaning, deleting-installing Xcode, cloning the repository again but nothing works.
All the project file shown in the screen shot are sub project inside one main project.
Probably that red file was removed or moved somewhere else. Open Finder, locate the missing xcodeproj, then remove this one in Xcode and drag&drop the located one. If that red xcodeproj is inside your repository (what I suspect) then do not select to copy it to the destination.
If you cannot locate that red file, it means it is not added to the repository. For example, it could mean that you need to install it with git submodules or another way - depends on the project configuration.
Are you using the workspace? if yes then please open that file not xcode project file

Adding a dependency to a repository with Xcode 6.1

I'm new to programming on iOS and I'm running into a roadblock with adding dependencies to my repository.
When I drag and drop a framework into the project directory and reference everything, I can build the project no problem. The issue is when I commit my project to the repository, the framework files do not get copied over. I can see that they are located in their original directory in some other location. Xcode merely references these files instead of adding them to the project directory.
So my question is, how do you add a framework or dependency to a project directory and commit it alongside your project to your repository?
Note I'm using SVN, however a Version Management System agnostic solution works for me.
In your case, or most cases people just download the framework and add it from there directly though it works in their machines, but will not work in other machine, because of absolute path added to the Header Search Paths settings in Build Settings.
In case of Third Party frameworks are as follows, will work for any case. Add the relative path rather than absolute path, though you don't set it, it is automatically added while you add a framework. So what are the steps? See below
Step 1
Create a folder named framework inside your svn/git folder of your project, and put all the frameworks inside the folder..
Step 2
Now add the framework, from the framework folder as you were doing earlier.
Step 3
Check your Header Search Paths in Build Settings. You will see entry for your framework header path. It should look something like
/Users/username/ProjectFolder/Project/frameworks/myframework/framework.h
Change the above entry by
$(SRCROOT)/frameworks/myframework/framework.h
Doing the above will automatically change this /Users/username/ProjectFolder/Project/ part of your path according to any system you clone the project. And it will work automatically.
Note - Before performing the steps, remove all old Header entries, which has absolute path.
Hope it helps.
Cheers.

Resources