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.

Activity

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

        Participants

        @BikonLI

        Issue actions

          Listener will be binded twice while its parent rebuild · Issue #407 · MixinNetwork/flutter-plugins