@@ -13,14 +13,15 @@ import 'package:super_drag_and_drop/super_drag_and_drop.dart';
1313import 'package:tmail_ui_user/features/composer/presentation/styles/web/drop_zone_widget_style.dart' ;
1414import 'package:tmail_ui_user/main/localizations/app_localizations.dart' ;
1515
16+ typedef OnSuperFileDrop = void Function (List <FileInfo > fileInfos);
1617
1718class LocalFileDropZoneWidget extends StatelessWidget {
1819
1920 final ImagePaths imagePaths;
2021 final double ? width;
2122 final double ? height;
2223 final EdgeInsetsGeometry margin;
23- final void Function ( List < FileInfo > fileInfos) ? onSuperDrop;
24+ final OnSuperFileDrop ? onSuperDrop;
2425
2526 const LocalFileDropZoneWidget ({
2627 super .key,
@@ -31,38 +32,20 @@ class LocalFileDropZoneWidget extends StatelessWidget {
3132 this .onSuperDrop,
3233 });
3334
35+ static final allowedFormats = Formats .standardFormats.where ((format) {
36+ return format != Formats .plainText
37+ && format != Formats .htmlText
38+ && format != Formats .uri
39+ && format != Formats .fileUri;
40+ }).cast <SimpleFileFormat >().toList ();
41+
3442 @override
3543 Widget build (BuildContext context) {
36- final allowedFormats = Formats .standardFormats.where ((format) {
37- return format != Formats .plainText
38- && format != Formats .htmlText
39- && format != Formats .uri
40- && format != Formats .fileUri;
41- }).cast <SimpleFileFormat >().toList ();
42-
4344 return DropRegion (
4445 formats: allowedFormats,
4546 onDropOver: (_) => DropOperation .copy,
46- onPerformDrop: (performDropEvent) async {
47- final items = performDropEvent.session.items;
48- final listFileInfo = await Future .wait (items.map (
49- (item) async {
50- final dataReaderFile = await item.dataReader? .getFileFuture (
51- SimpleFileFormat (mimeTypes: item.platformFormats)
52- );
53- final bytes = await dataReaderFile? .readAll ();
54- return FileInfo (
55- fileName: dataReaderFile? .fileName ?? await item.dataReader? .getSuggestedName () ?? '' ,
56- fileSize: bytes? .length ?? 0 ,
57- bytes: bytes,
58- isInline: item.platformFormats.firstOrNull? .startsWith (Constant .imageType),
59- type: item.platformFormats.firstOrNull,
60- );
61- },
62- ));
63-
64- onSuperDrop? .call (listFileInfo);
65- },
47+ onPerformDrop: _onFileDrop,
48+ hitTestBehavior: HitTestBehavior .opaque,
6649 child: SizedBox (
6750 width: width,
6851 height: height,
@@ -101,6 +84,27 @@ class LocalFileDropZoneWidget extends StatelessWidget {
10184 ),
10285 );
10386 }
87+
88+ Future <void > _onFileDrop (PerformDropEvent performDropEvent) async {
89+ final items = performDropEvent.session.items;
90+ final listFileInfo = await Future .wait (items.map (
91+ (item) async {
92+ final dataReaderFile = await item.dataReader? .getFileFuture (
93+ SimpleFileFormat (mimeTypes: item.platformFormats)
94+ );
95+ final bytes = await dataReaderFile? .readAll ();
96+ return FileInfo (
97+ fileName: dataReaderFile? .fileName ?? await item.dataReader? .getSuggestedName () ?? '' ,
98+ fileSize: bytes? .length ?? 0 ,
99+ bytes: bytes,
100+ isInline: item.platformFormats.firstOrNull? .startsWith (Constant .imageType),
101+ type: item.platformFormats.firstOrNull,
102+ );
103+ },
104+ ));
105+
106+ onSuperDrop? .call (listFileInfo);
107+ }
104108}
105109
106110extension _DataReaderExtension on DataReader {
0 commit comments