Issue
Error: The argument type ‘User (where User is defined in <dir>\<project>\lib\pages\home.dart)'
can’t be assigned to the parameter type ‘User (where User is defined in <dir>\<project>\lib\pages\timeline.dart)'.
Code : home.dart
Scaffold buildAuthScreen() {
return Scaffold(
key: _scaffoldKey,
body: PageView(
children: <Widget>[
Timeline(currentUser: currentUser),
ActivityFeed(),
Upload(currentUser: currentUser),
Search(),
Profile(profileId: currentUser?.id),
Code : timeline.dart
class Timeline extends StatefulWidget {
final User currentUser;
Timeline({this.currentUser});
in different pages it working but in timeline i don’t why its showing this error.
Solution
You have two separate classes both named User
in two different files. Even though they have the same class name, they are different classes (even if they have identical implementations).
If they really should be separate classes, you should consider renaming them to be different. If that’s not possible, you can disambiguate them by specifying a library prefix when you import:
import 'timeline.dart' as timeline;
Then you can use timeline.User
to refer specifically to timeline.dart
‘s version.
Answered By – jamesdlin
Answer Checked By – Katrina (FlutterFixes Volunteer)