So I'm working on this quiz app, and I just create a class for my question and answers. But vscode keeps telling me that there are errors. Can someone please help me?
Here is the main.dart
import 'package:flutter/material.dart'; import 'question.dart'; void main() { runApp(HomePage()); } class HomePage extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( debugShowCheckedModeBanner: false, home: Scaffold( backgroundColor: Colors.grey[900], body: SafeArea( child: Padding( padding: EdgeInsets.symmetric(horizontal: 10.0), child: Quizzler(), ), ), ), ); } } class Quizzler extends StatefulWidget { @override QuizzlerState createState() => QuizzlerState(); } class QuizzlerState extends State<Quizzler> { List<Widget> scoreKeeper = []; List<Domande> domandeBank = [ Domande(d: 'Il sole è una stella', r: true), Domande(d: 'Il latte è verde', r: false), Domande(d: 'Il mare è blu', r: true), ]; int qNumber = 0; @override Widget build(BuildContext context) { return Column( mainAxisAlignment: MainAxisAlignment.spaceBetween, crossAxisAlignment: CrossAxisAlignment.stretch, children: <Widget>[ Expanded( flex: 5, child: Padding( padding: const EdgeInsets.all(10.0), child: Center( child: Text( domandeBank[qNumber].domande, style: TextStyle(color: Colors.white), textAlign: TextAlign.center, ), ), ), ), Expanded( child: Padding( padding: const EdgeInsets.all(10.0), child: TextButton( style: TextButton.styleFrom(padding: EdgeInsets.zero), child: Container( color: Colors.green, height: 50, width: double.infinity, child: Center( child: Text( "True", style: TextStyle(color: Colors.white), ), ), ), onPressed: () { setState(() { bool risCorretta = domandeBank[qNumber].risposte; if (risCorretta == true) { scoreKeeper.add( Icon( Icons.check, color: Colors.green, ), ); } else { scoreKeeper.add( Icon( Icons.close, color: Colors.red, ), ); } qNumber++; }); }, ), ), ), Expanded( child: Padding( padding: const EdgeInsets.all(10.0), child: TextButton( style: TextButton.styleFrom(padding: EdgeInsets.zero), child: Container( color: Colors.red, height: 50, width: double.infinity, child: Center( child: Text( "False", style: TextStyle(color: Colors.white), ), ), ), onPressed: () { setState(() { bool risCorretta = domandeBank[qNumber].risposte; if (risCorretta == false) { scoreKeeper.add( Icon( Icons.check, color: Colors.green, ), ); } else { scoreKeeper.add( Icon( Icons.close, color: Colors.red, ), ); } qNumber++; }); }, ), ), ), Row( children: scoreKeeper, ), ], ); } } And here is the question.dart class
class Domande { String domande; bool risposte; Domande({String d, bool r}) { domande = d; risposte = r; } } And the errors i get:
Non-nullable instance field 'domande' must be initialized. Try adding an initializer expression, or add a field initializer in this constructor, or mark it 'late'. Non-nullable instance field 'risposte' must be initialized. Try adding an initializer expression, or add a field initializer in this constructor, or mark it 'late'. The parameter 'd' can't have a value of 'null' because of its type, but the implicit default value is 'null'. Try adding either an explicit non-'null' default value or the 'required' modifier. The parameter 'r' can't have a value of 'null' because of its type, but the implicit default value is 'null'. Try adding either an explicit non-'null' default value or the 'required' modifier.