Error: Required named parameter 'vinNumber' must be provided

Issue

Basically, I have got three classes, namely getting started, landing page, and vin. The user will be able to navigate from the getting started class to the landing page. I am getting some text or data value from VIN which I need to pass to the landing page and I did create a constructor in landing page class so that i can retrieve value from VIN. But i am receiving an error in the getting started class which do not need data from VIN. What parameter and value do i need to pass to the getting started route. I am receiving following error :

91:41: Error: Required named parameter ‘vinNumber’ must be provided.
Get.to(LandingPage());
:16:3: Context: Found this candidate, but the arguments don’t match.
LandingPage({required this.vinNumber});
^^^^^^^^^^^

**Getting Started class:**

FlatButton(
                    child: Text(
                      'Get a price quote for free!',
                      style: TextStyle(
                        fontSize: 12,
                        fontWeight: FontWeight.bold
                      ),
                    ),
                    shape: RoundedRectangleBorder(
                      borderRadius: BorderRadius.circular(10),
                    ),
                    padding: const EdgeInsets.all(10),
                    color: Colors.green ,
                    textColor: Colors.white,
                    onPressed: () {
                      **Get.to(LandingPage());**
                    },
                  ),
**Landing Page class**
class LandingPage extends StatefulWidget {
   String? vinNumber;

  LandingPage({required this.vinNumber});

    @override
  _LandingPageState createState() => _LandingPageState(vinNumber!);
}

class _LandingPageState extends State<LandingPage> {
   String? vinNumber;
 _LandingPageState(this.vinNumber);

**VIN Class**
    LandingPage(vinNumber:_getVin.text);

Solution

in Landing page you are saying that the vinNumber can be nullable, but also required
You only need to change
LandingPage({required this.vinNumber});
into
LandingPage({this.vinNumber});

Answered By – Giuseppe Colucci

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published