preface: I'm building an application for a building that can navigate a user, one of the ways I am doing this is by using a floor plan of the building and I want to draw a path between nodes in this floor plan to create a route (not with realtime updates). The user enters where they want to be and after my route finding algorithm has outputted a path I want to use that for my line placement.
I have used a library called Photo View to allow me to zoom in and move the image of the floor plan around the screen but I need to draw my route on, and then have it follow the floor plan as if it was part of the image. Realistically I think for the drawing I'd want the canvas size to be relative to the image not the screen (so 0,0 is the top-left corner of the image) but I'm unsure on how to access this.
Am I going down the wrong path using Photo View and should I be using something native to dart/flutter instead?
I also want to add a FAB that I can press to draw my route over the original image but I don't know how to go around this with the child issue
Here's some of what I have so far:
Widget build(BuildContext context) {
return Container(
child: new CustomPaint(
foregroundPainter: RoutePainter(),
child: PhotoView(
imageProvider: AssetImage('assets/images/floor1_temp.png'),
minScale: PhotoViewComputedScale.contained,
maxScale: 1.5,
),
));
}
There is a widget called interactive viewer in the latest flutter sdk.
When you wrap your widget tree with this widget, it will allow you to zoom and pan them no matter the nature of those widgets.
Like This:
Container(
// You just need to wrap your widgets with this.
child: InteractiveViewer(
child : Stack(
children: <Widget>[
// YOUR MAP as an image
Image.asset("your_image.png"),
//Your custom canvas.
CanvasWidget()
],
)
),
),
Related
I'm trying to make an editor using Konva.js.
In the editor I show a smaller draw area which becomes the final image. For this I'm using a group with a clipFunc. This gives a better UX since the transform controls of the transformer can be used "outside" of the canvas (visible part for the user) and allow the user to zoom and drag the draw area around (imagine a frame in Figma).
I want to implement object snapping based on this: https://konvajs.org/docs/sandbox/Objects_Snapping.html. (just edges and center for now) However I want it to be able to work when having multiple elements selected in my Transformer.
The strategy I'm using is basically calculating the snapping based on the .back element created by the transformer. When I know how much to snap I apply it to every node within the transformer.
However when doing it, the items starts jittering when moving the cursor close to the snapping lines.
My previous implementation was having the draw area fill the entire Stage, which I did manage to get working with the same strategy. (no jitter)
I don't really know what the issue is and I hope some of you guys can point me in the right direction.
I created a codepen to illustrate my issue: https://codesandbox.io/s/konva-transformer-snapping-1vwjc2?file=/src/index.ts
i tried to rotate my widget with:
with self.canvas.before:
PushMatrix()
Rotate(origin=self.center, angle=90)
with self.canvas.after:
PopMatrix()
But my widget and the image it contains are in different places, i display the widget position with:
with self.root.ids.background.canvas:
Color(1, 0, 0, 1, mode='rgba')
Rectangle(pos=self.root.ids.ship.pos, size=self.root.ids.ship.size)
also the widget collide method suggest the same finding i have with painting the position.
Doesnt matter if i use Scatter or Image class, both times when i rotate the Image ends up in a different place. Here is an example
i also tried to control the position with:
self.children[0].pos = self.center
here is the complete git repo:
The link to the github repo to be able to test it yourself
i am now using https://github.com/kivy-garden/garden.rotabox for my rotation issue and it works great
I want to transform a Flutter widget based on the progress of a Hero animation.
For example, I'd like to gradually clip an image while moving it to another page (using a Hero animation). In case of using a regular animation, I would just call the .value attribute in order to check the progress of the animation and transform the clipper according to that value, but how can I achieve something similar with a Hero animation?
You don't have to listen to the progress of your hero animation to achieve what you are trying to do.
Child of Hero widgets do not have to be the exact same. You can clip one of the widgets, and leave the other one unclipped. The Hero widget will automatically animate the widget from being unclipped to clipped.
To occupy the whole width or height , I use double.infinity, but going through some of the flutter samples, I have noticed many people use MediaQuery.of(context).size.width or height. I went through the docs but there are no differences mentioned between this two or when to use which one as both allow same feature. Are they specific to particular widgets?
The difference can be summarized into:
I want to be as big as my parent allows (double.infinity)
I want to be as big as the screen (MediaQuery).
Usually, you'll want to use double.infinity, but it's not always possible.
Some Widgets allow their children to be as big as they want to be (Column, ListView, OverflowBox...). In that situation using double.infinity creates a paradox:
The parent allows any size
The child wants the biggest size allowed by the parent
Using MediaQuery in these situations is bad though. You will rarely want to do that unless you're creating a widget similar to Scaffold.
That's where widgets such as IntrinsincHeight comes in handy. These widgets are able to solve the paradox, and therefore have a valid layout.
MediaQuery occupies the space as per the screen size whereas double.infinity occupies the space as parent size. It could be matched with match-parent in Android.
I'm writing an application with kivy that scans a network and based on results it generates bunch of widget like labels and buttons or maybe a layout like Gridview.
I'm trying to position them by pos or center_x and center_y attributes. I can position them perfectly on my laptop but when I try my tablet or other devices with different screen sizes everything goes wrong and all widgets change their position.
My question is:Is there a elegant way to position widgets and layouts that pertain their position on any screen size?
P.S:
it's not working even when i maximize the window.
You have many different options here like::
Query the Window size and position your widget relative to the window using percentages instead of absulute values.
Use specific layout that fits the positioning style you need for you widgets.
Recomended
Use pos_hint in combination with your layouts
specify the widget pos using kivy.metrics.dp which gives you device independent pixels or use metrics.sp/cm/mm/in/...