Skip to content

Listener will be binded twice while its parent rebuild #407

@BikonLI

Description

@BikonLI
class FileDropBox extends StatelessWidget {
  FileDropBox({super.key});

  final controller = Get.put(FileDropController());
  @override
  Widget build(BuildContext context) {
    return DropTarget(
      onDragDone: (details) {
        final paths = details.files.map((file) => file.path).toList();
        debugPrint("onDragDone!!!");
        controller.onFilesDropped(paths);
      },
      child: const SizedBox.expand(),
    );
  }
}

For example, when the stateless widget FileDropBox rebuild, DropTarget will add a new onDragDone listener.
Which Means when I drop file to this widget, it will run onDragDone twice.

When FileDropBox rebuild again, onDragDone will run for three times.

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