Home > Back-end >  Can someone help me regarding this error im facing while adding a flutter page in route?
Can someone help me regarding this error im facing while adding a flutter page in route?

Time:10-21


class BMICalculator extends StatelessWidget {
  const BMICalculator({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      theme: ThemeData.dark().copyWith(
        appBarTheme: const AppBarTheme(color: Color(0xFF0A0E21)),
        scaffoldBackgroundColor: const Color(0xFF0A0E21),
      ),
      initialRoute: '/',
      routes: {
        InputPage.routeName: (context) => const InputPage(),
        ResultsPage.routeName: (context) => const ResultsPage(), 
      },
    );
  }
}

The named parameter 'xyz' is required, but theres no corresponding argument. Try adding the required argument.

Can someone guide me on how to tackle this. I dont know what to do and i cant find any solutions anywhere regarding how to nagivate without the error mentioned above

Im adding results page here as well

RESULTS PAGE

class ResultsPage extends StatefulWidget {
  const ResultsPage(
      {required this.bmiResult,
      required this.interpretation,
      required this.resultText,
      super.key});
  static const routeName = '/resultsPage';

  final String? bmiResult;
  final String? resultText;
  final String? interpretation;
  @override
  State<ResultsPage> createState() => _ResultsPageState();
}

class _ResultsPageState extends State<ResultsPage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Center(
          child: Text('BMI Calculator'),
        ),
      ),
      body: SafeArea(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.spaceEvenly,
          crossAxisAlignment: CrossAxisAlignment.stretch,
          children: [
            Expanded(
              child: Container(
                padding: const EdgeInsets.all(15.0),
                alignment: Alignment.bottomCenter,
                child: const Text(
                  'Your Result',
                  style: kTitleTextStyle,
                ),
              ),
            ),
            Expanded(
              flex: 6,
              child: ReusableCard(
                colour: kActiveCardColor,
                cardChild: Column(
                  mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                  crossAxisAlignment: CrossAxisAlignment.center,
                  children: const [
                    Text(
                      'Normal',
                      style: kResultTextStyle,
                    ),
                    Text(
                      '18.3',
                      style: kBMITextStyle,
                    ),
                    Text(
                      'Your res is low. Eat more',
                      style: kBodyTextStyle,
                    ),
                  ],
                ),
              ),
            ),
            BottomButton(
              onTap: () {
                setState(() {
                  Navigator.pop(context);
                });
              },
              buttonTitle: 'RE-CALCULATE',
            ),
          ],
        ),
      ),
    );
  }
}

CodePudding user response:

You can remove required from parameters while all are nullable,

class ResultsPage extends StatefulWidget {
  const ResultsPage(
      {this.bmiResult, this.interpretation, this.resultText, super.key});
  static const routeName = '/resultsPage';

Or you can do like

ResultsPage.routeName: (context) {
  final args = ModalRoute.of(context)?.settings.arguments as Map?;//if you are passing map type data
  return ResultsPage(
    bmiResult: args?["bmiResult"],//use your key
    interpretation: args?["interpretation"],
    resultText: args?["resultText"],
  );
},
  • Related