Home > Mobile >  Error: Required named parameter 'vinNumber' must be provided
Error: Required named parameter 'vinNumber' must be provided

Time:06-10

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);

CodePudding user response:

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});

CodePudding user response:

Provide the vin number to your widget, like this:

 onPressed: () {
   Get.to(LandingPage(vinNumer: 'anyNumerYouWant' ));
 },
  • Related