How to make a dragable widget scalable? - flutter

In Flutter, how do you make a widget scaleable and dragable at the same time?
A GestureDetector, for some reason, behaves a little strange. For example:
return GestureDetector(
onHorizontalDragUpdate: onHorizontalScroll,
onScaleUpdate: onScale,
behavior: HitTestBehavior.opaque,
child: CustomPaint(
painter: SomeCustomPainter( /* some parameters */ ),
),
);
The above GestureDetector is placed somewhere deep down inside a SingleChildScrollView.
Problem is that onHorizontalScroll triggers most of the time when onScale is supposed to trigger.
In which case (about 9 out of 10 times) the widget doesn't scale.
The only way to reliably make the widget scalable is by removing onHorizontalDargUpate, but then it can't be dragged any more...
So the question now is, how do you make a widget dragable and scalable at the same time? Any advise is very much appreciated. Thank you.

I suggest using the Draggable widget and DragTaregt to drop it in. it is useful and better than creating draggable from scratch. check this link

Related

How to add suggetionbox in web when cursor is on button

I want to show suggestion when cursor is on button or on some widget in flutter web
I share example how I want to show suggestion box but I don't know how to add suggestion box in flutter
You need to wrap widget with Tooltip see example.
flutter tooltip example
Try below code hope its help to you. Used Tooltip Widget
Refer Tooltip here
Test below code here
Tooltip(
message: "Managers",
child: ElevatedButton(
onPressed: () {},
child: Text('OK'),
),
),
Result Screen->
In addition to all the tooltip related recommendations, if they don't quite meet your requirements, there's OverlayEntry It allows to use any widget, but is not super easy to handle, so there's a couple packages out there that do some work with Overlays for you that you might consider.
https://pub.dev/packages/flutter_portal
https://pub.dev/packages/modals
To show overlay entry when hovering over some widget, wrap it with MouseRegion and use its onEnter and onExit methods to show and hide overlay

fuction widgets or class widgets?

I am searching this topic and I must confess, I love the using function widgets for my applications. And in the my flutter experience, I never got any error or any unwanted result with this approach(I mean using function widgets).
But while my search, I couldn't totally understand the reason, why I must use the stateless widgets but not function widgets.
An example; I want to create a page, using scaffold, and appar.
My page must be statefull so I want to use
Scaffold scaffold({String pageTitle, Widget body, Widget floatingActionButton, Widget appBarLeading})=>Scaffold(
appBar: CustomAppBar(pageTitle: pageTitle, leading: appBarLeading),
body: body,
floatingActionButton: floatingActionButton,
floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
backgroundColor: Colors.blueGrey[50],
);
this code and, my custom appbar coming from Stateless Widget.
So what happen if I use this structure for the beginning ?
İf I use the setstate, my appbar creating from to beginning or used from widget three ?
I can understand the reasons why must use stateless widget because it has final variables and this way, it is reused in the program behalf but What happen If I use stateless widgets in my function widgets ?
Please help me for understanding this topic.
Thank you very much.

Flutter: Recognise touch immediately

Is there a way to recognize a touch input immediately in Flutter? Normal buttons of course don't work since they trigger on lift off. The closest thing I could find was using onTapDown by the GestureDetector widget. But this only triggers after a short delay. Thank you for any advice!
You could try wrapping your widget with the Listener widget and use the onPointerDown property.
e.g.
Listener(
child: Scaffold(),
onPointerDown: (_) {},
)

How to produce screenshot animation in flutter?

Somebody please suggest me the best package or any way to provide a screenshot taken effect in flutter. Please don't downvote.If I did anything wrong
One way to achieve the effect you are looking for is having your page in a Stack. One entry of the Stack will be your Scaffold page, and the other one will be a white Container that fills the screen space. Something like this in your page's build method:
#override
Widget build(BuildContext context) => Stack(
children: [
Container(color: Colors.white),
Scaffold(
// The rest of your page
),
],
);
Then, you can wrap your white Container in an AnimatedOpacity widget (check out this Flutter.dev article on how to animate fading widgets), and define an animation such that the white Container fades in and then fades out very quickly, achieving a flash-like effect. In the article I mentioned they also explain how to trigger such an animation programatically.

How to create a floating widget that moves as the page scrolls in Flutter

I want to create a floating widget in the ListView.builder, which will follow the scrolled position as in many web sites or another applications.
I never saw such a widget nor can find. Can anybody share with his experience or give some good idea to how create such a widget?
I suggest you take a look at FloatingActionButton widget.
You can read more about this widget from the official documentation: https://api.flutter.dev/flutter/material/FloatingActionButton-class.html
I found a couple of solution for my question.
First, Flutter already Have a widget called Scrollbar. You can wrap with him some scrollable widgets like:ListView or GridView etc.
It will give you a simple draggable widget with vertical axis on the right side.
This is an example:
Scrollbar(
child: ListView.builder(
itemCount: 50,
itemBuilder: (context, index) => ListTile(title: Text("Item= ${index + 1}"),),),
)
But you can't customize this widget's, for example height or width, and I found another custom created widget, which is added to pub.dev also. The package name is draggable_scrollbar and this was what I need. There are some styled widgets for scrollbar and custom one, that you can customize as you wish.