Flutter how to know on which part from image was tapped - flutter

I have a car image and i want to make user enable to tap on apart of it then the tapped part name will be shown. How can i do it?
Like this image but i want to use car image not a map.

I think the way I'd do this, is use a Stack to overlay a GestureDetector on your image and see what the coordinates are. You could even use a CustomClipper with some custom shapes, or overlay multiple Positioned widgets with separate listeners on it, depending on your needs.
https://api.flutter.dev/flutter/widgets/GestureDetector-class.html
https://api.flutter.dev/flutter/rendering/CustomClipper-class.html

Related

how to navigate to new page when click on path svg in flutter?

I have the following svg image (each circle has a different path)
and my app contains 5 classes,
I want to include it in my app so that when the user clicks on any circle, it goes to another page (navigate to new class) and each circle has a different class than the other
How can this be done in Flutter?
This might be a workaround if there is another way but my first thought is to put your SVG image into a stack widget and place Positioned gesturedetectors over each circle area. Then point each Gesturedetector to each class you have.
There might be more elegant ways to go about it but this might get you going till you have a better solution

Flutter: Only detect gestures within a image

I'm having some trouble with Gesture Detector. I have a set of images that I want to add a GestureDetector to. However, I only want the GestureDetector to be active within a border of the image. As seen in the images below. I have some images with random shapes that are transparent behind the images. I want to make a gesture detector that only detects the inside of these random shapes. The parts that are marked with green. I did this for the circle by taking the local.position of the taping and then checking if it was within a circle with x^2 + y^2 = ... However this can not be done with custom shapes. Could someone help me with an idea of how to solve this? If I just mark the image with a gesturedetector then is it also possible to tap on the transparent part of the image, which I dont want. Thanks
Image
This is not something, you will be able to do natively in Flutter. If you want to extract the exact region of interest, you will need to do image processing to find the right shape. Your best bet to do the image processing live is C/C++.
Dart has the ability to execute native C, take a look at this: https://dart.dev/guides/libraries/c-interop
You should attempt to extract a polygon bounding box of the image areas and then use the polygon path values to draw a path using a CustomPainter.
If you do not need to be exact, try to approximate the shape by a simple polygon path by hand. The user probably will not notice the difference.

Codename One Drag and Drop - Target change background color on Drag Over

I have an Android application with some draggable elements.
There are some some labels that I want do drag over containers. The moment I drag over the container, I want the container background to change its colour.
I am unable to achieve this with DragOverListener from the API.
This is my code:
label.addDragOverListener(l -> {
container.getAllStyles().setBgColor(ColorUtil.YELLOW);
container.getAllStyles().setBgTransparency(255);
});
What happens is that as soon as I start dragging the label, the container changes the colour. But that's not what I want. I want the container to change the colour only when I drag over it.
Is there a way to achieve this?
Many thanks in advance.
The event delivers an X/Y location for the drag which you can use to determine whether to draw the color or not. Generally, this API is designed for refined drawing of this type e.g. drawing a square in the place the dropped component will occupy.

How to animate fullscreen photo transition on swipe, like in Telegram?

When you swipe vertically, image is dragged towards the swipe, with fading out animation of black background.
And after release, it smoothly returns to it's previous position on the screen, like Hero animation does.
How is it possible to recreate such an effect using Flutter? The same scenario, in fullscreen photo view.
photo_view package is desired for fullscreen, so it shouldn't interfere with zooming.
What you need is actually an out-of-the-box widget, and it's surprisingly easy to use. It's called Hero. Basically, you wrap the widget you want to animate like that in a Hero widget, with a specific tag string, and, when you navigate to another screen, you wrap the destination widget in another Hero with the same tag. An effect like the one you shared can be achieved by wrapping two widgets with the same photo with Heroes in different PageRoutes.
Check out this Flutter widget of the week video to get you started, and this Flutter.dev article for a more detailed explanation on Hero widgets.
Edit: I see you are looking for a more specific image-viewer behavior. Then, I suggest you use the photo_view package, which includes many functionalities to visualize images, including the hero transition with swipe-dow-to-dismiss behaviors, pinching to zoom, etc.
I found the solution.
To create such an animation, you should use extended_image package, which has SlideOutPage widget for creation of such transitions.

How can I create a tile, overlay for a scene in Cocos2d?

I'm new to Cocos2d, but I can't seem to find the answer to this. I want to add an image that is mostly transparent as an overlay to my application. The image is overlayed on the app, and does not respond to screen taps. All gestures should "pass through" to the application.
The overlay image should actually be tiled. It's a small image that should repeat both horizontally and vertically.
How can I do this? In fact, this is an overlay that I would like to display for the duration of the entire application-- not just one specific scene. Is there a simple way to do this?
The point of my overlay is that I'd like to create a pseudo-scan line affect for a game which has an "8-bit" tone. The scan lines will be generated by applying the overlay to the game. The overlay is non-interactive and should always exist. So, this isn't a "tile based game", but I do need a tiling affect for this functionality.
You should be able to create a layer in each scene, set the zOrder to something large so that it overlays everything else, and set its isTouchEnabled attribute to NO. You can then add whatever you want to the layer, which could be your patterned image. To change the alpha, just set the opacity attribute of your image. The only issue that I can foresee is that the overlay might disable touch events for layers below it.