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

The argument type '(#lib1::AppState, dynamic) → #lib1::AppState' can't be assigned to the parameter type '(#lib2::AppState, dynamic) → #lib2::AppState'. #81

Closed
rob-nolan opened this issue Sep 25, 2018 · 4 comments

Comments

@rob-nolan
Copy link

rob-nolan commented Sep 25, 2018

I get the above compiler error when building my app, the error relates to the appReducer parameter in the Store instantiation in main.dart. I've searched and found people having similar issues, but in their case it was always caused by relative paths which I am not using.

I've gone through my code and the docs a number of times and I can't see anything wrong so I think it may be a bug but please correct me if I am missing something.

-main.dart-
class MainApp extends StatelessWidget {
  final store = Store<AppState>(
    appReducer, 
    initialState: new AppState(),
    middleware: []
      ..addAll(createAuthMiddleware())
      ..add(new LoggingMiddleware.printer()),
  );
.
.
.
-app_state.dart-
class AppState {
  final User currentUser;

  AppState({
    this.currentUser,
  });

  AppState copyWith({User currentUser}) {
    return new AppState(
      currentUser: currentUser ?? this.currentUser,
    );
  }

  @override
  String toString() {
    return 'AppState{currentUser: $currentUser}';
  }
}
-auth_actions.dart-
class LogIn {}

class LogInSuccessful {
  final User user;

  LogInSuccessful({ @required this.user});

  @override
  String toString() {
    return 'LogIn{user: $user}';
  }
}

class LogInFail {
  final dynamic error;
  LogInFail(this.error);
  @override
  String toString() {
    return 'LogIn{There was an error logging in: $error}';
  }
}

class LogOut {}

class LogOutSuccessful {
  LogOutSuccessful();
  @override
  String toString() {
    return 'LogOut{user: null}';
  }
}

-app_reducer.dart-
AppState appReducer(AppState state, dynamic action) {
  return new AppState(
    currentUser: authReducer(state.currentUser, action)
  );
}
-auth_reducer.dart-
final authReducer = combineReducers<User>([
  TypedReducer<User, LogInSuccessful>(_logIn),
  TypedReducer<User, LogOut>(_logOut),
]);

User _logIn(User user, dynamic action) {
  return action.user;
}

Null _logOut(User user, dynamic action) {
  return null;
}
-pubspec.yaml-
environment:
  sdk: ">=2.0.0-dev.68.0 <3.0.0"

dependencies:
  flutter:
    sdk: flutter
  redux: ^3.0.0
  flutter_redux: ^0.5.2
flutter --version
Flutter 0.8.2 • channel beta • https://github.com/flutter/flutter.git
Framework • revision 5ab9e70727 (3 weeks ago) • 2018-09-07 12:33:05 -0700
Engine • revision 58a1894a1c
Tools • Dart 2.1.0-dev.3.1.flutter-760a9690c2
@brianegan
Copy link
Owner

Oh boy, this old gem... Do you happen to have a complete project you could share? I wasn't able to reproduce with the code you've pasted :/

@mzaenalmkalbe
Copy link

@brianegan i have the same issue, please check this repo here

@arkanmgerges
Copy link

hi there,
Just an observation, I'm doing a complex project, and I used redux, I've defined my actions as classes, and I never used 'dynamic' in my code in the reducers files.
For example:

final appConnectivityReducer = combineReducers<AppConnectivityState>([
  TypedReducer<AppConnectivityState, ConnectivityUpdatedAction>(_connectivityReducer),
]);

AppConnectivityState _connectivityReducer(
    AppConnectivityState prevState, ConnectivityUpdatedAction action) {
  return prevState.copyWith(
    hasInternetConnection: action.hasInternetConnection,
  );
}

And I did not have such problem.
I don't know if this can help solve your issue by defining classes for the actions that you are using, also this will make your code clearer.

Thanks

@fady94
Copy link

fady94 commented Oct 12, 2018

i have issued this problem and i was trying about a whole day to solve it
change (import "package:flutter_redux/folder/filename.dart") .
to (import "folder/filename.dart")

if you want to go up for a directory use (../)

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