Skip to content

DropZoneView does not respect new values for the callbacks fields like onDropFiles #102

@rafalbednarczuk

Description

@rafalbednarczuk

Hi!
The issue is that if I want to change DropZoneView's callbacks like onDropFiles by updating the widget tree with a new instance of DropZoneView with new callbacks, then it doesn't update its callbacks, instead it's using the callbacks of the first DropZoneView widget ignoring updates.

Environment:

Running on flutter web, chrome, macOS
Flutter 3.24.0 • channel stable • https://github.com/flutter/flutter.git
Framework • revision 80c2e84975 (8 months ago) • 2024-07-30 23:06:49 +0700
Engine • revision b8800d88be
Tools • Dart 3.5.0 • DevTools 2.37.2

I made reproducible sample, where each build currentNumber is changed, but onDropFiles callback still prints the firstNumber as current number. So first callback value is used and then newer updated again.
The correct behavior, would be to remove previous callback and use the new one instead.

import 'dart:math' show Random;

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

void main() => runApp(const MyApp());

class MyApp extends StatefulWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  String message1 = 'Drop something here';
  int? firstNumber;

  @override
  Widget build(BuildContext context) {
    final currentNumber = Random().nextInt(1000000);
    print("number:$currentNumber");
    firstNumber ??= currentNumber;
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: Text("title"),
        ),
        body: Column(
          children: [
            OutlinedButton(
                onPressed: () {
                  setState(() {});
                },
                child: Text("Rebuild")),
            Expanded(
              child: Stack(
                children: [
                  DropzoneView(
                    onDropFiles: (files) {
                      print(
                          'Zone 1:$currentNumber:$firstNumber drop multiple: $files');
                    },
                  ),
                  Center(child: Text(message1)),
                ],
              ),
            ),
          ],
        ),
      ),
    );
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions