Skip to content

StandardMessageCodec produces Map<dynamic, dynamic> but users expect Map<String, dynamic> #14556

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

Closed
mraleph opened this issue Feb 8, 2018 · 5 comments
Assignees

Comments

@mraleph
Copy link
Member

mraleph commented Feb 8, 2018

Consider for example this code from semantics_service_test (/cc @amirh )

    SystemChannels.accessibility.setMockMessageHandler((Object mockMessage) async {
      final Map<String, dynamic> message = mockMessage;
      log.add(message);
    });

This triggers runtime check failure in Dart 2 mode because Map<dynamic, dynamic> is not a subtype of Map<String, dynamic>.

I have discussed this with @mravn-google and we decided to go by fixing the consumer side, especially because Dart lacks features needed to correctly preserve type arguments across channel boundaries for arbitrary types.

I am gonna handle updating tests in Flutter repo, while @mravn-google team is gonna take care of packages that contain similar issues, e.g. https://github.com/flutter/plugins/blob/master/packages/video_player/lib/video_player.dart#L162-L163

@mraleph mraleph added the dart2 label Feb 8, 2018
mraleph added a commit to mraleph/flutter that referenced this issue Feb 8, 2018
Channels don't preserve Map and List type arguments: Map<String, Object>
arrives as Map<dynamic, dynamic> to the receiver.

In Dart 2 type system dynamic no longer serves as bottom type so
Map<dynamic, dynamic> can't be assign to a variable of type
Map<String, dynamic>.

Issue flutter#14556
mraleph added a commit that referenced this issue Feb 8, 2018
Channels don't preserve Map and List type arguments: Map<String, Object>
arrives as Map<dynamic, dynamic> to the receiver.

In Dart 2 type system dynamic no longer serves as bottom type so
Map<dynamic, dynamic> can't be assign to a variable of type
Map<String, dynamic>.

Issue #14556
@a-siva
Copy link
Contributor

a-siva commented Feb 9, 2018

In addition to the above I also ran into the following runtime errors which needed to be fixed before the video demo comes up in flutter gallery

E/flutter ( 5722): [ERROR:topaz/lib/tonic/logging/dart_error.cc(16)] Unhandled exception:
E/flutter ( 5722): type '_BroadcastSubscription' is not a subtype of type 'StreamSubscription<Map<String, dynamic>>' where
E/flutter ( 5722):   _BroadcastSubscription is from dart:async
E/flutter ( 5722):   StreamSubscription is from dart:async
E/flutter ( 5722):   Map is from dart:core
E/flutter ( 5722):   String is from dart:core
E/flutter ( 5722): 
E/flutter ( 5722): #0      VideoPlayerController.initialize (package:video_player/video_player.dart:191:10)
E/flutter ( 5722): <asynchronous suspension>
E/flutter ( 5722): #1      _VideoDemoState.initState.initController (file:///usr/local/google/home/asiva/workspace/flutter-roll/flutter/examples/flutter_gallery/lib/demo/video_demo.dart:385:24)
E/flutter ( 5722): <asynchronous suspension>
E/flutter ( 5722): #2      _VideoDemoState.initState (file:///usr/local/google/home/asiva/workspace/flutter-roll/flutter/examples/flutter_gallery/lib/demo/video
/flutter ( 5434): [ERROR:topaz/lib/tonic/logging/dart_error.cc(16)] Unhandled exception:
E/flutter ( 5434): type 'List' is not a subtype of type 'List<List<int>>' where
E/flutter ( 5434):   List is from dart:core
E/flutter ( 5434):   List is from dart:core
E/flutter ( 5434):   List is from dart:core
E/flutter ( 5434):   int is from dart:core
E/flutter ( 5434):
E/flutter ( 5434): #0      VideoPlayerController.initialize.eventListener (package:video_player/video_player.dart:176:51)
E/flutter ( 5434): #1      _RootZone.runUnaryGuarded (file:///b/build/slave/Linux_Engine/build/src/third_party/dart/sdk/lib/async/zone.dart:1316:10)
E/flutter ( 5434): #2      _BufferingStreamSubscription._sendData (file:///b/build/slave/Linux_Engine/build/src/third_party/dart/sdk/lib/async/stream_impl.dart:330:11)
E/flutter ( 3775): type '(PlatformException) => void' is not a subtype of type '(Object) => FutureOr'
E/flutter ( 3775): #0      _registerErrorHandler (file:///b/build/slave/Linux_Engine/build/src/third_party/dart/sdk/lib/async/async_error.dart:22:60)
E/flutter ( 3775): #1      _BufferingStreamSubscription.onError (file:///b/build/slave/Linux_Engine/build/src/third_party/dart/sdk/lib/async/stream_impl.dart:146:16)
E/flutter ( 3775): #2      new _BufferingStreamSubscription (file:///b/build/slave/Linux_Engine/build/src/third_party/dart/sdk/lib/async/stream_impl.dart:113:10)
E/flutter ( 3775): #3      new _ControllerSubscription (file:///b/build/slave/Linux_Engine/build/src/third_party/dart/sdk/lib/async/stream_controller.dart)
E/flutter ( 3775): #4      new _BroadcastSubscription (file:///b/build/slave/Linux_Engine/build/src/third_party/dart/sdk/lib/async/broadcast_stream_controller.dart)
E/flutter ( 3775): #5      _BroadcastStreamController._subscribe (file:///b/build/slave/Linux_Engine/build/src/third_party/dart/sdk/lib/async/broadcast_stream_controller.dart:212:46)
E/flutter ( 3775): #6      _ControllerStream._createSubscription (file:///b/build/slave/Linux_Engine/build/src/third_party/dart/sdk/lib/async/stream_controller.dart:817:19)
E/flutter ( 3775): #7      _StreamImpl.listen (file:///b/build/slave/Linux_Engine/build/src/third_party/dart/sdk/lib/async/stream_impl.dart:466:9)
E/flutter ( 3775): #8      VideoPlayerController.initialize (package:video_player/video_player.dart:190:10)
D/MediaPlayer( 5722): setSubtitleAnchor in MediaPlayer
E/flutter ( 5722): [ERROR:topaz/lib/tonic/logging/dart_error.cc(16)] Unhandled exception:
E/flutter ( 5722): 'package:video_player/video_player.dart': error: line 178 pos 40: file:///usr/local/google/home/asiva/.pub-cache/hosted/pub.dartlang.org/video_player-0.2.0/lib/video_player.dart:178:40: Error: A value of type '(dart.core::List<dart.core::int>) → #lib1::DurationRange' can't be assigned to a variable of type '(dynamic) → dynamic'.
E/flutter ( 5722): Try changing the type of the left hand side, or casting the right hand side to '(dynamic) → dynamic'.
E/flutter ( 5722):           buffered: bufferedValues.map(toDurationRange).toList(),
E/flutter ( 5722):                                        ^
E/flutter ( 5722):           buffered: bufferedValues.map(toDurationRange).toList(),
E/flutter ( 5722):                                        ^
E/flutter ( 5722): 
E/flutter ( 5722): #0      _RootZone.runUnaryGuarded (file:///b/build/slave/Linux_Engine/build/src/third_party/dart/sdk/lib/async/zone.dart:1316:10)
E/flutter ( 5722): #1      _BufferingStreamSubscription._sendData (file:///b/build/slave/Linux_Engine/build/src/third_party/dart/sdk/lib/async/stream_impl.dart

Once I worked around these errors by doing local patches in
.pub-cache/hosted/pub.dartlang.org/video_player-0.2.0/lib/video_player.dart
The video demo comes up and works.

@a-siva a-siva added this to the 3: Current Milestone milestone Feb 9, 2018
@mraleph
Copy link
Member Author

mraleph commented Feb 9, 2018

@a-siva would you make PR with your changes - given that you already have it fixed?

a-siva added a commit to a-siva/plugins that referenced this issue Feb 9, 2018
flutter/flutter#14556
(issues encountered when running flutter gallery in strong mode).
@a-siva
Copy link
Contributor

a-siva commented Feb 9, 2018

created PR flutter/plugins#380 for addressing these issues

a-siva added a commit to flutter/plugins that referenced this issue Feb 10, 2018
* Fix signature errors to account for strong mode errors listed in
flutter/flutter#14556
(issues encountered when running flutter gallery in strong mode).

* Fix analyzer warnings.

* Address code review comment.

* Address analyzer lint issues.

* Format error.

* Format.

* Format.
@a-siva
Copy link
Contributor

a-siva commented Feb 15, 2018

All PRs to address this have landed.

@a-siva a-siva closed this as completed Feb 15, 2018
DaveShuckerow pushed a commit to DaveShuckerow/flutter that referenced this issue May 14, 2018
Channels don't preserve Map and List type arguments: Map<String, Object>
arrives as Map<dynamic, dynamic> to the receiver.

In Dart 2 type system dynamic no longer serves as bottom type so
Map<dynamic, dynamic> can't be assign to a variable of type
Map<String, dynamic>.

Issue flutter#14556
ryanheise pushed a commit to ryanheise/background_video_player that referenced this issue Sep 29, 2019
* Fix signature errors to account for strong mode errors listed in
flutter/flutter#14556
(issues encountered when running flutter gallery in strong mode).

* Fix analyzer warnings.

* Address code review comment.

* Address analyzer lint issues.

* Format error.

* Format.

* Format.
@github-actions
Copy link

github-actions bot commented Sep 3, 2021

This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 3, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants