-
-
Notifications
You must be signed in to change notification settings - Fork 50
Open
Description
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)),
],
),
),
],
),
),
);
}
}Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels