leoafarias / sidekick

A simple app to make Flutter development more delightful
BSD 3-Clause "New" or "Revised" License
1.57k stars 101 forks source link

feat(project): setting project icon #328

Open charles0122 opened 2 months ago

charles0122 commented 2 months ago

before:

image

after:

image

links:

298

187

charles0122 commented 2 months ago

What I did was to store the String rawData of the svg format file in hive. I am not sure if it is stored correctly. I saw that what is stored in the project is ProjectRef, not FlutterProject.

charles0122 commented 2 months ago

And I don't know if @aguilaair has designed a figma drawing, so I didn't pay attention to the UI design of the change icon.

aguilaair commented 2 months ago

This is great!! I'll review ASAP

charles0122 commented 2 months ago

For this idea, the first thing that comes to my mind is to add an attribute called project-icon in pubspec, but I don't know whether this attribute is only for sidekick. In addition, it is also worth discussing what format of icons to store in pubspec, whether it is a network image, svg raw data, or other formats. If the official flutter also has this plan, I think it is feasible. If not, I think we should also implement this function from sidekick. The inspiration for completing this pr comes from jetBrains. They store icons in svg format in the configuration file generated by IDE, but now we store it in hive. You can also think about whether you can set a directory to access the sidekick configuration, name the folder as .sidekick, etc. This method may be a good choice if you plan to do multi-device synchronization and other network functions in the future.

charles0122 commented 2 months ago

If you're worried about svg being too big in hive, consider limiting the size, or try optimizing svg tags that won't work with flutter rendering

aguilaair commented 2 months ago

I'm not worried about the size of the SVG but I like the idea that the icon is automatically detected on any sidekick install. We don't even need our own property and we can take advantage of another very popular package's property in the yaml:

https://pub.dev/packages/flutter_launcher_icons

we can just look for flutter_icons.image_path

charles0122 commented 2 months ago

This operation looks very good, but it is worth considering that not every flutter project uses this package. What should we do if the project does not use this package?

Also, after a quick look at this package, I think it needs to use image_path in its own project to access the icon. I'm not sure if we can access this icon in this project from sidekick and render it correctly.

As I understand it, the function of this package is that I can use an icon in my Flutter project to automatically generate icons required by other platforms, rather than providing accessible properties for third parties to use.

charles0122 commented 2 months ago

I think the main problem with this solution is that there is no definite property that allows us to get the location of this icon. Not all Flutter projects will use this package, and the default pubspec will not provide this property.

charles0122 commented 2 months ago

Maybe we can try this first to see if it works.

aguilaair commented 2 months ago

Yes, this is not a default property, and we are indeed misusing it because it is not designed to be interacted by other entities. However, if we have permission to see the project we can access the image. We can always have our own property that is used before that:

# Check this first
sidekick:
  banner: some/image/path.png
  icon: some/image/path.png

# Use this as a fallback
flutter_icons:
  image_path: some/image/path.png
charles0122 commented 2 months ago

Have you tested whether it works?

I still think that adding an attribute for sidekick in the project's pubspec is putting the cart before the horse. When a project that doesn't use sidekick appears, that attribute is redundant. We can't unify this attribute like Flutter does.

aguilaair commented 2 months ago

That's like saying that the .fvm is redundant when FVM is not installed; it is true, but it also does not change the usefulness of the config—maybe having a .sidekick would be better. I do not want this to be something the one would have to configure on every computer individually.