flutter-plugins icon indicating copy to clipboard operation
flutter-plugins copied to clipboard

[desktop_drop] after a drag and drop the app doesn't rebuild itself until it is selected on macOS

Open stephane-archer opened this issue 11 months ago • 3 comments

https://github.com/user-attachments/assets/f9952e15-f2b4-4e00-90c6-c8b156d20e5f

after a drag and drop the app doesn't rebuild itself until it is selected on macOS

Expected results

I expect the app to react to the drag and drop and rebuild itself to give immediate feedback to the user.

Actual results

the app doesn't rebuild itself after a drag and drop on macOS

[✓] Flutter (Channel stable, 3.24.5, on macOS 15.1 24B83 darwin-x64, locale en-GB)
    • Flutter version 3.24.5 on channel stable at /Users/fractale/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision dec2ee5c1f (5 weeks ago), 2024-11-13 11:13:06 -0800
    • Engine revision a18df97ca5
    • Dart version 3.5.4
    • DevTools version 2.37.3

[!] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    • Android SDK at /Users/fractale/Library/Android/sdk
    ✗ cmdline-tools component is missing
      Run `path/to/sdkmanager --install "cmdline-tools;latest"`
      See https://developer.android.com/studio/command-line for more details.
    ✗ Android license status unknown.
      Run `flutter doctor --android-licenses` to accept the SDK licenses.
      See https://flutter.dev/to/macos-android-setup for more details.

[✓] Xcode - develop for iOS and macOS (Xcode 16.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 16B40
    • CocoaPods version 1.16.2

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2022.2)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b802.4-9586694)

[✓] VS Code (version 1.96.0)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.102.0

[✓] Connected device (2 available)
    • macOS (desktop) • macos  • darwin-x64     • macOS 15.1 24B83 darwin-x64
    • Chrome (web)    • chrome • web-javascript • Google Chrome 131.0.6778.141
    ! Error: Browsing on the local area network for Melimelo. Ensure the device is unlocked and attached with a cable or associated with the same local area network as this Mac.
      The device must be opted into Developer Mode to connect wirelessly. (code -27)

[✓] Network resources
    • All expected network resources are available.

! Doctor found issues in 1 category.

I use a DropTarget from desktop_drop-0.5.0

stephane-archer avatar Dec 19 '24 13:12 stephane-archer

I tried it with the example and it worked as expected. The video is as follows

https://github.com/user-attachments/assets/5ea9703b-3580-4b89-b048-004ced806a86

Could you provide some reproducible code ,so that we can find out why the problem occurs?

boyan01 avatar Dec 19 '24 15:12 boyan01

@boyan01 I can't explain what is happening. this doesn't happen every time. If I start playing with another window it doesn't work but if I only play with the finder and the app it works as expected. Can you observe the same behavior on your side?

https://github.com/user-attachments/assets/81130749-a964-4ac4-9fd1-c9fbcde11202

stephane-archer avatar Dec 20 '24 13:12 stephane-archer

Here is the code for reproducing the issue. just drop folder to the app

import 'dart:async';

import 'package:desktop_drop/desktop_drop.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';

void main() {
  runApp(const ProviderScope(child: MyApp()));
}

final favoriteFoldersProvider = StateProvider<int>(
  (ref) => 0,
);

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return const MaterialApp(
      home: MyHomePage(),
    );
  }
}

class MyHomePage extends ConsumerWidget {
  const MyHomePage({super.key});

  @override
  Widget build(BuildContext context, WidgetRef ref) {
    final favoriteFolders = ref.watch(favoriteFoldersProvider);
    return Scaffold(
      appBar: AppBar(),
      body: DropTarget(
        onDragDone: (dropDoneDetails) async {
          await _processDroppedFiles(
            dropDoneDetails,
            ref,
          );
        },
        child: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              Text(favoriteFolders.toString()),
            ],
          ),
        ),
      ),
    );
  }

  static Future<void> _processDroppedFiles(
    DropDoneDetails dropDoneDetails,
    WidgetRef ref,
  ) async {
    var files = dropDoneDetails.files;
    final filePaths = files.map((e) {
      return e.path;
    });
    if (filePaths.isEmpty) {
      return;
    }
    var favoriteFolders = ref.read(favoriteFoldersProvider.notifier);
    for (var i = 0; i < filePaths.length; i++) {
      favoriteFolders.update((state) {
        return state + 1;
      });
    }
  }
}

stephane-archer avatar Dec 20 '24 14:12 stephane-archer