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

Problem using --preview-dart-2 #3

Open
nitrico opened this issue Feb 27, 2018 · 5 comments
Open

Problem using --preview-dart-2 #3

nitrico opened this issue Feb 27, 2018 · 5 comments

Comments

@nitrico
Copy link

nitrico commented Feb 27, 2018

Trying to run this app with Dart 2 causes this

compiler message: lib/main.dart:14:17: Error: A value of type '(#lib1::TodoState, #lib2::TodoAction) → #lib1::TodoState' can't be assigned to a variable of type '(dynamic, dynamic) → dynamic'.
compiler message: Try changing the type of the left hand side, or casting the right hand side to '(dynamic, dynamic) → dynamic'.
compiler message:       new Store(todoAppReducer, initialState: new TodoState.initialState());
compiler message:                 ^
[VERBOSE-2:dart_error.cc(16)] Unhandled exception:
'file:///Users/miguel/Projects/flutter-redux-todo-list/lib/main.dart': error: line 14 pos 17: lib/main.dart:14:17: Error: A value of type '(#lib1::TodoState, #lib2::TodoAction) → #lib1::TodoState' can't be assigned to a variable of type '(dynamic, dynamic) → dynamic'.
Try changing the type of the left hand side, or casting the right hand side to '(dynamic, dynamic) → dynamic'.
      new Store(todoAppReducer, initialState: new TodoState.initialState());
                ^
      new Store(todoAppReducer, initialState: new TodoState.initialState());
                ^

#0      main (file:///Users/miguel/Projects/flutter-redux-todo-list/lib/main.dart:9:14)
#1      _startIsolate.<anonymous closure> (dart:isolate/isolate_patch.dart:279:19)
#2      _RawReceivePortImpl._handleMessage (dart:isolate/isolate_patch.dart:165:12)

I tried to solve it by replacing

final Store store = new Store>(todoAppReducer, initialState: new TodoState.initialState());

with

final Store store =  new Store<TodoState>(todoAppReducer, initialState: new TodoState.initialState());

in main.dart. But then I get this error:

[VERBOSE-2:dart_error.cc(16)] Unhandled exception:
'file:///Users/miguel/Projects/flutter-redux-todo-list/lib/main.dart': error: line 14 pos 28: lib/main.dart:14:28: Error: The top level function has type '(#lib1::TodoState, #lib2::TodoAction) → #lib1::TodoState' that isn't of expected type '(#lib1::TodoState, dynamic) → #lib1::TodoState'.
Change the type of the function or the context in which it is used.
      new Store<TodoState>(todoAppReducer, initialState: new TodoState.initialState());
                           ^
      new Store<TodoState>(todoAppReducer, initialState: new TodoState.initialState());
                           ^

#0      main (file:///Users/miguel/Projects/flutter-redux-todo-list/lib/main.dart:9:14)
#1      _startIsolate.<anonymous closure> (dart:isolate/isolate_patch.dart:279:19)
#2      _RawReceivePortImpl._handleMessage (dart:isolate/isolate_patch.dart:165:12)

Any idea on how to solve it?

@xqwzts
Copy link
Owner

xqwzts commented Feb 27, 2018

Thanks for reporting this @nitrico! The repository pre-dates dart 2 and I haven't tried it with --preview-dart-2 yet, I'll give it a look and update soon.

At a quick glance the culprit is probably todoAppReducer's usage of TodoAction to specify the action parameter's type, replacing that with dynamic might unblock you.

@nitrico
Copy link
Author

nitrico commented Feb 27, 2018

Thank you, for the answer and the project :)

Yes, that's what I've tried after that and now it works fine for iOS (both debug and release) and Android in debug mode but not in release. Weird...

@voodoo
Copy link

voodoo commented Jul 25, 2018

I am wanting to dive deeper into state management but I was unable to get this to work for me. I really like this project structure but I am a flutter/dart noob.

At a quick glance the culprit is probably todoAppReducer's usage of TodoAction to specify the action parameter's type, replacing that with dynamic might unblock you.

Wish I could say that was enough to help me get running w/Dart 2 .

I tried changing the 'method signature' to something like ...

List<Todo> todosReducer(List<Todo> state, action)

Which got me closer (starts to load on iPhone 6)... embarrassingly, I'm not sure if that is stupid but it still does not boot :(

type 'Store<dynamic>' is not a subtype of type 'Store<TodoState>'
Fixed that by declaring it specifically ...

final Store<TodoState> store = new Store<TodoState>(todoAppReducer, initialState: new TodoState.initialState());

... but ...

flutter: Another exception was thrown: NoSuchMethodError: The getter 'store' was called on null.

To my eyes, this app looks like a top notch implementation of a simple redux app, wish I could boot it 👍

@kieth1205
Copy link

The function 'todoAppReducer' has type '(TodoState, TodoAction) → TodoState' that isn't of expected type '(TodoState, dynamic) → TodoState'. This means its parameter or return type does not match what is expected.

=> I get this error. So how to resolve it bro????

@ipcjs
Copy link

ipcjs commented Sep 7, 2020

#6 fix the problem.

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

No branches or pull requests

5 participants