0
class HomePage extends StatefulWidget {
  final String uid;

  HomePage({Key key, @required this.uid}) : super(key: key);
  final FirebaseUser user;

  HomePage({this.user});

  @override
  _HomePageState createState() => _HomePageState(uid);
}

The default constructor is already defined. Try giving one of the constructors a name.dart(duplicate_constructor)

i want this two construters to pass on any one can help me in his

1 Answers1

0

You're getting the error because you're trying to make two default constructor. Try making the second one a named constructor to fix the issue.

Note : Dart doesn't support's constructor and method overloading. That's why it comes with named methods that makes them more readable and easy to manage.

 class HomePage extends StatefulWidget {
      final String uid;
    
      HomePage({Key key, @required this.uid}) : super(key: key);
      final FirebaseUser user;
    
      HomePage.user({this.user});
    
      @override
      _HomePageState createState() => _HomePageState(uid);
  }
Shubhamhackz
  • 7,333
  • 7
  • 50
  • 71
  • A more conventional naming would be `Homepage.fromUser` instead of `HomePage.user`. Please also note that each constructor will have to initialize all final variables (uid and user). – Thierry Feb 02 '21 at 06:09