Skip to content

[FileSelector][web] openFiles never returns when user presses "cancel" in system UI file picker #121328

@ltOgt

Description

@ltOgt

Reproduce

With the following in pubspec.yaml:

environment:
  sdk: '>=2.19.2 <3.0.0'

dependencies:
  flutter:
    sdk: flutter
  file_selector:
  file_selector_web:

and main.dart:

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

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

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

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

class _MyAppState extends State<MyApp> {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      theme: ThemeData.dark(),
      home: Scaffold(
        body: Center(
          child: TextButton(
            child: const Text("OPEN FILES"),
            onPressed: () async {
              try {
                print("opening");
                final r = await openFiles(); // doc: "Returns an empty list if the user cancels the operation."
                print("done: $r");
              } catch (e) {
                print("ERROR: $e");
              }
            },
          ),
        ),
      ),
    );
  }
}
  • start debugging in web
  • press "OPEN FILES" button
  • wait for system UI
  • press "CANCEL" in system UI file picker

Expectation

openFiles returns an empty list after the user presses the "Cancel" button

debug console output:

opening
done: []

Actual

openFiles does not return at all

debug console output:

opening

Compare with selecting a file (works as expected)

  • press "OPEN FILES" button
  • wait for system UI
  • select any file
  • press "Open" in system UI file picker

debug console output:

opening
done: [Instance of 'XFile']

doctor

[✓] Flutter (Channel stable, 3.7.3, on macOS 12.1 21C52 darwin-arm64, locale en-DE)
    • Flutter version 3.7.3 on channel stable at /Users/gian/development/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 9944297138 (2 weeks ago), 2023-02-08 15:46:04 -0800
    • Engine revision 248290d6d5
    • Dart version 2.19.2
    • DevTools version 2.20.1

[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0)
    • Android SDK at /Users/gian/Library/Android/sdk
    • Platform android-33, build-tools 33.0.0
    • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.12+0-b1504.28-7817840)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 13.2.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 13C100
    • CocoaPods version 1.11.3

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

[✓] Android Studio (version 2021.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 11.0.12+0-b1504.28-7817840)

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

[✓] Connected device (2 available)
    • macOS (desktop) • macos  • darwin-arm64   • macOS 12.1 21C52 darwin-arm64
    • Chrome (web)    • chrome • web-javascript • Google Chrome 110.0.5481.177

[✓] HTTP Host Availability
    • All required HTTP hosts are available

• No issues found!

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work listp: file_selectorThe file_selector pluginpackageflutter/packages repository. See also p: labels.platform-webWeb applications specificallyteam-webOwned by Web platform teamtriaged-webTriaged by Web platform team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions