Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

type 'String' is not a subtype of type 'List<dynamic>' in desktop #452

Closed
wants to merge 4 commits into from
Closed

Conversation

ebwood
Copy link

@ebwood ebwood commented Oct 19, 2020

Describe the bug

when using file_picker in mac or windows desktop with go_flutter_desktop, choosing a file causes the error: type 'String' is not a subtype of type 'List' in type cast.

Issue details

Platform: Mac, Windows

Error Log

flutter: [MethodChannelFilePicker] Unsupported operation. Method not found. The exception thrown was: type 'String' is not a subtype of type 'List' in type cast
[ERROR:flutter/lib/ui/ui_dart_state.cc(166)] Unhandled Exception: type 'String' is not a subtype of type 'List' in type cast
#0 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:161:41)

#1 MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:334:12)
#2 MethodChannel.invokeListMethod (package:flutter/src/services/platform_channel.dart:347:40)
#3 FilePickerIO._getPath (package:file_picker/src/file_picker_io.dart:79:47)
#4 FilePickerIO.pickFiles (package:file_picker/src/file_picker_io.dart:29:7)
#5 _HomePageState.filePicker (package:rename_lanhu/home_page.dart:230:57)
#6 _HomePageState.build... (package:rename_lanhu/home_page.dart:107:59)
#7 _InkResponseState._handleTap (package:flutter/src/material/ink_well.dart:992:19)
#8 _InkResponseState.build. (package:flutter/src/material/ink_well.dart:1098:38)
#9 GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:184:24)
#10 TapGestureRecognizer.handleTapUp (package:flutter/src/gestures/tap.dart:524:11)
#11 BaseTapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:284:5)
#12 BaseTapGestureRecognizer.handlePrimaryPointer (package:flutter/src/gestures/tap.dart:219:7)
#13 PrimaryPointerGestureRecognizer.handleEvent (package:flutter/src/gestures/recognizer.dart:477:9)
#14 PointerRouter._dispatch (package:flutter/src/gestures/pointer_router.dart:78:12)
#15 PointerRouter._dispatchEventToRoutes. (package:flutter/src/gestures/pointer_router.dart:124:9)
#16 _LinkedHashMapMixin.forEach (dart:collection-patch/compact_hash.dart:377:8)
#17 PointerRouter._dispatchEventToRoutes (package:flutter/src/gestures/pointer_router.dart:122:18)
#18 PointerRouter.route (package:flutter/src/gestures/pointer_router.dart:108:7)
#19 GestureBinding.handleEvent (package:flutter/src/gestures/binding.dart:220:19)
#20 GestureBinding.dispatchEvent (package:flutter/src/gestures/binding.dart:200:22)
#21 GestureBinding._handlePointerEvent (package:flutter/src/gestures/binding.dart:158:7)
#22 GestureBinding._flushPointerEventQueue (package:flutter/src/gestures/binding.dart:104:7)
#23 GestureBinding._handlePointerDataPacket (package:flutter/src/gestures/binding.dart:88:7)
#24 _rootRunUnary (dart:async/zone.dart:1206:13)
#25 _CustomZone.runUnary (dart:async/zone.dart:1100:19)
#26 _CustomZone.runUnaryGuarded (dart:async/zone.dart:1005:7)
#27 _invoke1 (dart:ui/hooks.dart:267:10)
#28 _dispatchPointerDataPacket (dart:ui/hooks.dart:176:5)

Flutter Version details

[✓] Flutter (Channel stable, 1.22.2, on Mac OS X 10.15.3 19D76, locale zh-Hans-CN)
[✓] Xcode - develop for iOS and macOS (Xcode 11.3.1)
[!] Android Studio (version 4.1)
✗ Flutter plugin not installed; this adds Flutter specific functionality.
✗ Dart plugin not installed; this adds Dart specific functionality.
[✓] VS Code (version 1.50.1)
[!] Connected device
! No devices available

Solutions:

The problem only occurs in desktop like mac or windows(haven't tested in linux).
In library file file_picker_io.dart line79,

final List<Map> result = await _channel.invokeListMethod(type, {
        'allowMultipleSelection': allowMultipleSelection,
        'allowedExtensions': allowedExtensions,
        'allowCompression': allowCompression,
        'withData': withData,
      });

when running in desktop, _channel.invokeListMethod returns the path of file(String type instead of List).

So my solution is changing the method to invokeMethod then check what type result is.

// ... other contents including in file_picker_io.dart
final result = await _channel.invokeMethod(type, {
        'allowMultipleSelection': allowMultipleSelection,
        'allowedExtensions': allowedExtensions,
        'allowCompression': allowCompression,
        'withData': withData,
      });

      if (result == null) {
        return null;
      }

      if (result is String) {
        return FilePickerResult([PlatformFile(path: result)]);
      }
      if (result is List) {
        return FilePickerResult(
            result.map((file) => PlatformFile.fromMap(file)).toList());
      }
      return null;

@miguelpruivo
Copy link
Owner

Hi, this will be fixed along #382. Thank you!

@kechkibet
Copy link

Hi @miguelpruivo ,
Is there any ETA on this or temporary solution?

@miguelpruivo
Copy link
Owner

@kechkibet I thought I'd be able to get this done last weekend, but it wasn't impossible. Maybe on the next.

@dipulkhatri
Copy link

@miguelpruivo Any update on this issue. Thanks.

@Elena-FrontendDev
Copy link

Hi, this will be fixed along #382. Thank you!

Hi, I'm hope everything is ok and we will see this update soon.

@miguelpruivo
Copy link
Owner

Hi, this should be fixed now in the latest version 2.1.4 since #382 has been closed.

Thank you!

@ebwood
Copy link
Author

ebwood commented Dec 23, 2020

@miguelpruivo No, it's not fixed.It looks like go-flutter can't detect JSONMethodCodec.

go-flutter: handling message on channel miguelruivo.flutter.plugins.filepicker failed: failed to decode incoming message: failed to decode method name: invalid message value type

@miguelpruivo
Copy link
Owner

@FakenMaster I'm sorry to hear that, but if this is an issue, how could others have it working somehow? When do you experience it?

@ebwood
Copy link
Author

ebwood commented Dec 23, 2020

I test the newest file_picker library again in a new project, it works perfectly。So the problem is my old project, maybe some cache problems.
Thanks for your work! @miguelpruivo

@miguelpruivo
Copy link
Owner

@FakenMaster glad to know! Happy Christmas.

@ebwood
Copy link
Author

ebwood commented Dec 23, 2020

@miguelpruivo You too!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants