Comments (5)
@ibrahimEltayfe Thank you very much for sharing your solution!
Dunno why, but it my case it doesn't work - feedback is still misplaced. But I made a workaround this way:
dragAnchorStrategy: (final draggable, final context, final position) {
final responsiveBreakpoints = ResponsiveBreakpoints.of(context);
final mediaQuery = MediaQuery.of(context);
final double widthOffset =
mediaQuery.size.width - responsiveBreakpoints.screenWidth;
final double heightOffset =
mediaQuery.size.height - responsiveBreakpoints.screenHeight;
final RenderBox renderObject = context.findRenderObject()! as RenderBox;
return renderObject.globalToLocal(
Offset(
position.dx - widthOffset / 2,
position.dy - heightOffset / 2,
),
);
},
It's not quite proper, I think, but better, than nothing. And when you are moving your feedback widgets, it's sliding from your finger a little bit (further you move, more it slides).
Maybe it'll be a good idea to leave a report in flutter issues too.
from responsiveframework.
I have the same problem. In my case I'm dragging a chip with some label:
2024-03-28.20.05.32.mov
feedback
appears misplaced in both directions and offset of this misplacement changes on moving.
No big difference with the code above - Chip
as a child of draggable and the same chip as feedback and no onDragCallbacks.
#17 this topic was closed without any solution provided
@rayliverified Could you please help us to resolve this?
from responsiveframework.
Nice, your solution worked fine like this:
Offset adjustPosition(BuildContext context, Offset position){
final RenderBox? renderObject = context.findRenderObject() as RenderBox?;
return renderObject?.globalToLocal(
Offset(
position.dx,
position.dy,
),
) ?? position;
}
without any further calculations, because globalToLocal is converting the global position (coordinates relative to the entire screen) to the coordinates relative to the widget itself. This takes into account any transformations or scaling applied to the widget's layout.
class _HomeState extends State<_Home> {
Offset position = const Offset(0, 0);
Offset currentPos = const Offset(0, 0);
void _onDragUpdate(BuildContext context, DragUpdateDetails details) {
currentPos += details.delta;
}
void _onDragEnd(BuildContext context, DraggableDetails details) {
setState(() {
position = adjustPosition(context, currentPos);
});
}
Offset adjustPosition(BuildContext context, Offset position){
final RenderBox? renderObject = context.findRenderObject() as RenderBox?;
return renderObject?.globalToLocal(position,) ?? position;
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: SafeArea(
child: Stack(
children: [
Positioned(
top: position.dy,
left: position.dx,
child: Draggable(
onDragUpdate: (details) => _onDragUpdate(context, details),
onDragEnd: (details) => _onDragEnd(context, details),
childWhenDragging: const SizedBox.shrink(),
feedback: const Material(child: Text("DRAGGABLE",style: TextStyle(fontSize: 50),)),
child: const Text("DRAGGABLE",style: TextStyle(fontSize: 50),),
),
),
]
),
),
);
}
}
The feedback positioning is working fine without handling its offset, I do not know why the feedback position not working properly on your side, my problem was with placing the item on the scaled screen. but the coordinates coming from the DraggableDetails are fine.
My remaining problem is the scale of the feedback item, I will try to make a calculation for the scale.
Screen.Recording.2024-04-01.at.7.58.29.AM.mov
from responsiveframework.
@ibrahimEltayfe Well, I have some suggestions about the difference. Do you place ResponsiveScaledBox
at home
parameter of MaterialApp
? In my case I use builder
. And when I move it to home - I see the same behavior as you describe - wrong scale. And when return it to builder
- it has wrong position. Flutter team has confirmed the problem, see here: flutter/flutter#146002
from responsiveframework.
Related Issues (20)
- Breakpoint value is null on initial build HOT 6
- nonexistent breakpoint on migration from 0.2.0 -> 1.1.1 HOT 1
- Condition on ResponsiveVisibility requires a value in v1 HOT 2
- When breakpointsLandscape is defined, it will always ignore breakpoints. HOT 1
- [Feature Request]
- [BUGS] Button in ResponsiveRowColumnItem cannot expanded HOT 2
- ResponsiveScaledBox in showDialog does not work properly
- Can we use the new version with GetX package? HOT 1
- Error when using ReorderableListView inside ResponsiveScaledBox ( v1.1.1 and below) HOT 3
- User finger resize
- Font getting squeezed on iPhone 11 with iOS 16.0
- GoogleMap marker's tap area is misplaced on the web
- ResponsiveWrapper is not working HOT 3
- ResponsiveVisibility error HOT 2
- withNoTextScaling not working in letest version HOT 4
- Error null when defaultValue on ResponsiveValue not specified HOT 2
- type 'Null' is not a subtype of type 'double' in type cast HOT 3
- ResponsiveFramework + EasyLoading in builder
- WebView is not clickable when ResponsiveScaledBox is in place HOT 10
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from responsiveframework.