Skip to content

draggable feedback location #17

Closed
Closed

Description

@wph144

hi, thanks for great package
I am using ReorderableWrap of 'reorderables' package.
I found feedback's location is wrong when using responsive_framework package.
More generally, there are same problem when using Draggable widget.
following is minimal reproducible application.

import 'package:flutter/material.dart';
import 'package:responsive_framework/responsive_framework.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
// This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      builder: (context, widget) {
        return ResponsiveWrapper.builder(
          BouncingScrollWrapper.builder(context, widget),
          maxWidth: 1200,
          minWidth: 350,
          debugLog: false,
          defaultScale: true,
          breakpoints: [
            ResponsiveBreakpoint.resize(350, name: MOBILE, scaleFactor: 0.8),
            ResponsiveBreakpoint.autoScale(800, name: TABLET, scaleFactor: 1.4),
            ResponsiveBreakpoint.autoScale(1000, name: TABLET, scaleFactor: 1.4),
            const ResponsiveBreakpoint.resize(1200, name: DESKTOP),
            const ResponsiveBreakpoint.autoScale(2460, name: "4K"),
          ],
          mediaQueryData: MediaQuery.of(context).copyWith(textScaleFactor: 1),
          background: Container(),
        );
      },
      home: DraggableExample(),
    );
  }
}

class DraggableExample extends StatefulWidget {
  @override
  DraggableExampleState createState() => DraggableExampleState();
}

class DraggableExampleState extends State<DraggableExample> with SingleTickerProviderStateMixin {

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Column(
        children: [
          Spacer(),
          Row(
            children: [
              Spacer(),
              Draggable(
                feedback: Container(
                  width: 60,
                  height: 60,
                  color: Colors.red,
                ),
                child: Container(
                  width: 60,
                  height: 60,
                  color: Colors.red,
                ),
              ),
            ],
          ),
          SizedBox(height: MediaQuery.of(context).padding.bottom,),
        ],
      )
    );
  }
}

If item is on top-left, there are no or small difference, on right-bottom there are big difference.
I intentionally put scale factor apart from 1.0

Can you help me?

Activity

  1. rayliverified commented on Sep 1, 2020

    @rayliverified
    Contributor

    Thanks for reporting this issue.
    I'm going to look into if it is possible to overwrite the root level MediaQuery parameters.
    Some framework widgets fetch their layout from the root screen metrics directly which means they are not getting the right metrics.

  2. gcostaapps commented on Sep 19, 2020

    @gcostaapps

    Could you try using this build with the MediaQuery parameter? It was used to fix MediaQuery for entire app.

    builder: (BuildContext context, Widget widget) =>
                    DevicePreview.appBuilder(
                  context,
                  Builder(builder: (BuildContext context) {
                    return MediaQuery(
                    data: MediaQuery.of(context),
                    child: ResponsiveWrapper.builder(MainView()),
                      maxWidth: 2460,
                      minWidth: 480,
                      defaultScale: true,
                      breakpoints: <ResponsiveBreakpoint>[
                        const ResponsiveBreakpoint.resize(480, name: MOBILE),
                        const ResponsiveBreakpoint.autoScale(600, name: TABLET),
                        const ResponsiveBreakpoint.autoScale(1000,
                            name: TABLET, scaleFactor: 1.2),
                        const ResponsiveBreakpoint.resize(1200, name: DESKTOP),
                        const ResponsiveBreakpoint.autoScale(2460, name: '4K'),
                      ],
                      background: Container(color: const Color(0xFFF5F5F5)),
                    ),
    
  3. wph144 commented on Sep 19, 2020

    @wph144
    Author

    I tried below, but I still have same problem.
    It seems that I already used MediaData on MaterialApp level with 'mediaQueryData parameter of ResponsiveWrapper.builder method'.
    DevicePreview is just helper and not related to this issue, right?
    (i have compile error, so I cannot try right now, aloisdeniel/flutter_device_preview#67)

    class MyApp extends StatelessWidget {
      @override
      Widget build(BuildContext context) {
        return MaterialApp(
          builder: (context, widget) {
            return MediaQuery(
              data: MediaQuery.of(context),
              child: ResponsiveWrapper.builder(
                BouncingScrollWrapper.builder(context, widget),
                maxWidth: 1200,
                minWidth: 350,
                debugLog: false,
                defaultScale: true,
                breakpoints: [
                  ResponsiveBreakpoint.resize(350, name: MOBILE, scaleFactor: 0.8),
                  ResponsiveBreakpoint.autoScale(800, name: TABLET, scaleFactor: 1.4),
                  ResponsiveBreakpoint.autoScale(1000, name: TABLET, scaleFactor: 1.4),
                  const ResponsiveBreakpoint.resize(1200, name: DESKTOP),
                  const ResponsiveBreakpoint.autoScale(2460, name: "4K"),
                ],
    //            mediaQueryData: MediaQuery.of(context).copyWith(textScaleFactor: 1),
                background: Container(),
              ),
            );
          },
          home: DraggableExample(),
        );
      }
    }
    

    Thanks for reply :)

  4. bounty1342 commented on Sep 23, 2020

    @bounty1342

    @searchy2 Might be related to this one, but I have issue with ReorderableListView. Should I open a new issue ?
    Depending on the location of the click, it throw the widget off.

  5. rayliverified commented on Sep 23, 2020

    @rayliverified
    Contributor

    It's most likely related to this issue.

    The problem/solution is in passing a transformed composited tap target.

    Not sure on the exact implementation but I can point you in the right direction if you are interested in taking a look.

  6. bounty1342 commented on Sep 24, 2020

    @bounty1342

    Found this :

    https://medium.com/flutter/how-to-float-an-overlay-widget-over-a-possibly-transformed-ui-widget-1d15ca7667b6

    So wrapping the parent widget with a CompositedTransformTarget to get reference to the cordinate sytem and then wrap the child with CompositedTransformFollower to follow it.
    This seems way to easy to actually work 😁

  7. cyrilOrderoo commented on Nov 30, 2020

    @cyrilOrderoo

    Same problem, very complicated to use draggable on tablet. When moving, the draggable is moved away from the cursor. I have the problem only on iOS, everything works on android. Do you have any news on the issue ? Thanks

  8. bounty1342 commented on Dec 29, 2020

    @bounty1342

    Hi @searchy2,
    Having issues with dragg and drop, but also with other package like flutter_intro.
    Do you have any update on a fix ?

  9. wph144 commented on Jan 22, 2021

    @wph144
    Author

    any progress?

  10. wph144 commented on Jan 24, 2021

    @wph144
    Author

    I resolved with workaround (simple but some boilerplate codes)
    If you use the widget that internally use OverlayEntry to make draggable feedback, Responsive framework package can generate coordination problem. e.g., ReorderableWrap, Draggable, LongPressDraggable, etc.
    That widget may have parameter onDragStarted, onDragEnded, feedback. (or other name)

    Offset dragPosition = Offset.zero;   // member variable or variable in model
    Widget feedback;                              // member variable or variable in model
    
    Listener(
      onPointerDown: (details) {
        dragPosition = details.localPosition;
        setState(() {});                                           // or some other notify method
      },
      onPointerMove: (details) {
        dragPosition = details.localPosition;
        setState(() {});
      },
      child: Stack(
        children: [
          LongPressDraggable(
            feedback: const SizedBox(),
            onDragStarted() {
              // your another logic
              feedback = buildYourFeedbackWidget();
              setState(() {});
            },
            onDragEnd(_) {                  // or cancel? anyway when drag ended with any reason
              // your another logic
              feedback = null;
              setState(() {});
            },
            // some other your logics on LongPressDraggable
          ),
          Visibility(
            visible: feedback != null && dragPosition != null,
            child: Positioned(
              left: dragPosition.dx - 40,          // 40 can be changed to your amount
              top: dragPosition.dy - 40,
              child: IgnorePointer(
                child: Opacity(
                  opacity: 0.7,
                  child: feedback,
                ),
              ),
            ),
          )
        ]
      ),
    
  11. infobkm commented on Mar 15, 2022

    @infobkm

    no updates for this issue for over a year? I really like this plugin but I can't use it because my app is based on a form with a reorderable list..

  12. gozluc84 commented on May 21, 2022

    @gozluc84

    no updates for this issue for over a year? I really like this plugin but I can't use it because my app is based on a form with a reorderable list..

    0.2.0 version released but issue still present.. :( no workaround?

  13. TimBaumgart commented on Jan 11, 2023

    @TimBaumgart

    Any updates on this? I was trying to find a workaround by disabling autoscaling for some widgets where I use ReorderableListView, but could not get it to work. Does anyone know how to do this? Just wrapping my widget with another ResponsiveWrapper did not work.

  14. TimBaumgart commented on Jan 12, 2023

    @TimBaumgart

    I found a solution that is working for me. I am calculating a transform-matrix, which depends on the current pointer location, and apply it to the proxy decorator. Here is my Code:

    class ReorderableList extends StatefulWidget {
      @override
      State<ReorderableList> createState() => _ReorderableListState();
    }
    
    class _ReorderableListState extends State<ReorderableList> {
      double pointerHeightScaleFactor = 0;
    
      @override
      Widget build(BuildContext context) {
        return Listener(
          onPointerMove: (event) {
            pointerHeightScaleFactor =
                (event.position.dy / ResponsiveWrapper.of(context).screenHeight);
          },
          child: SliverReorderableList(
            proxyDecorator: (child, index, animation) {
              ResponsiveWrapperData data = ResponsiveWrapper.of(context);
              double widthOffset = data.scaledWidth - data.screenWidth;
              double heightOffset = data.scaledHeight - data.screenHeight;
              return Transform.translate(
                offset: Offset(
                  widthOffset,
                  heightOffset * pointerHeightScaleFactor,
                ),
                child: Material(
                  child: child,
                  elevation: 8,
                ),
              );
            },
          ),
        );
      }
    }
    

    This approach is not 100% correct, I think, but it fits my needs. It might break, if your draggable has a variable x-offset.

  15. WillianSalceda commented on May 18, 2023

    @WillianSalceda

    @rayliverified Why this issue is being closed, even though it still unfixed?

    @TimBaumgart is a workaround, not a fix. But still, it does not work with the current newest version of the package. scaledWidth and scaledHeight doesn't exist, for instance.

  16. Eerey commented on Jan 29, 2024

    @Eerey

    It also seems to conflict with Draggable.
    Similar issue with that. It seems like the globalToLocal-calculation or something like that is not correct.

  17. egonbeermat commented on Feb 22, 2024

    @egonbeermat

    Same issue here, when using LongPressDraggable inside ResponsiveScaledBox, the DraggableDetails.offset returned from onDragEnd are not in the correct scaled coordinate system. Whilst it might not be possible to override or alter this, a workaround or an additional method inside responsive_framework to convert would be handy.

  18. elkSal commented on Mar 6, 2024

    @elkSal

    Facing same issue with ReorderableListView, when dragging, the item overflows and become bigger than original size.
    Quick dirty solution is to use internal padding as follows

    ReorderableListView(
                      padding:
                          const EdgeInsets.symmetric(horizontal: 30, vertical: 20),
    

    This puts some padding around the list view item so that on drag, it doesn't overflow screen width.

    No solution yet?

  19. LosDanieloss commented on Jul 23, 2025

    @LosDanieloss

    For anyone interested issues is still present mid 2025.

    reorder_problem_example.mp4

    My minimal repro sample can be found at: https://github.com/LosDanieloss/responsive_framework_reorder_problem_example

    My repro sample uses CustomScrollView & SliverReorderableList but same applies when using ReorderableListView

    I saw that Flutter team did some changes to how draggable position is calculated.
    I'm referencing flutter/flutter#145647 which was reverted and merged once again in flutter/flutter#149040.
    Everything suggests that those changes were introduced in Flutter v3.22.0 but I'm running v3.29.0 and still have problems. That's why I'm here.

    > flutter --version
    
    Flutter 3.29.0 • channel stable • https://github.com/flutter/flutter.git
    Framework • revision 35c388afb5 (5 months ago) • 2025-02-10 12:48:41 -0800
    Engine • revision f73bfc4522
    Tools • Dart 3.7.0 • DevTools 2.42.2
    

    reactive_framework v1.5.1

    PS. since this one is close l'll create a new one

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions