google / flutter-desktop-embedding

Experimental plugins for Flutter for Desktop
Apache License 2.0
7.1k stars 607 forks source link

[file_selector] File Selector native dialog does not show on macOS #839

Closed technolion closed 3 years ago

technolion commented 3 years ago

Describe the bug The macOS implementation of the file_selector does not show, when being called. There is no error. The native macOS implementation seems to be called, but it does not show the picker and it never returns. This worked before and has stopped working just recently, possibly after a macOS operating system upgrade.

Versions

macOS 11.2.3
flutter channel beta 2.0.2
file_selector: ^0.8.2
file_selector_macos: ^0.0.4

Example code

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

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Bug Report',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: MyHomePage(title: 'Flutter Bug Report'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);

  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {

  void _launchFileSelector() async {
    final typeGroup = XTypeGroup(label: 'images', extensions: ['jpg', 'png']);
    final file = await openFile(acceptedTypeGroups: [typeGroup]);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(

        title: Text(widget.title),
      ),
      body: Center(

        child: Column(

          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Text(
              'push the button, the file selector should appear.',
            ),
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _launchFileSelector,
        child: Icon(Icons.add),
      ),
    );
  }
}

Doctor Output Please provide the output of flutter doctor -v:

porcupine:Development tom$ flutter doctor -v
[✓] Flutter (Channel beta, 2.0.2, on macOS 11.2.3 20D91 darwin-x64, locale de-DE)
    • Flutter version 2.0.2 at /usr/local/flutter
    • Framework revision 8962f6dc68 (5 days ago), 2021-03-11 13:22:20 -0800
    • Engine revision 5d8bf811b3
    • Dart version 2.12.1

[!] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
    • Android SDK at /Users/tom/Library/Android/sdk
    • Platform android-29, build-tools 29.0.2
    • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1343-b01)
    ✗ Android license status unknown.
      Run `flutter doctor --android-licenses` to accept the SDK licenses.
      See https://flutter.dev/docs/get-started/install/macos#android-setup for more details.

[✓] Xcode - develop for iOS and macOS
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 12.4, Build version 12D4e
    • CocoaPods version 1.10.1

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

[✓] Android Studio (version 3.4)
    • 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 1.8.0_152-release-1343-b01)

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

[✓] Connected device (2 available)
    • macOS (desktop) • macos  • darwin-x64     • macOS 11.2.3 20D91 darwin-x64
    • Chrome (web)    • chrome • web-javascript • Google Chrome 89.0.4389.82

! Doctor found issues in 1 category.
porcupine:Development tom$ 
technolion commented 3 years ago

I just tested on latest Flutter channel master, 2.1.0-13.0.pre.104 where I can still reproduce the problem.

technolion commented 3 years ago

Since Flutter for macOS has been declared Beta, I'd consider this problem a major one. Could you please take a look at it, @stuartmorgan ?

cbenhagen commented 3 years ago

@technolion most likely your app just misses the com.apple.security.files.user-selected.read-only entitlement.

cbenhagen commented 3 years ago

Unfortunately the error message which would have helped you find the cause is only shown when running the project from Xcode:

[OpenSavePanels] ERROR: Unable to display open panel: your app is missing the User Selected File Read app sandbox entitlement. Please ensure that your app's target capabilities include the proper entitlements.
technolion commented 3 years ago

Thank you @cbenhagen ! That did the trick. Sorry @stuartmorgan for making a fuss...