In my flutter app, I made a class to use it on other pages that have the same objects, but on other pages, not all those objects on it.
class ListItem extends StatelessWidget {
const ListItem(
{Key? key,
required this.nu_image,
required this.en_text,
required this.ja_text,
required this.ja_image,
required this.sound,
required this.color})
: super(key: key);
final String nu_image;
final Color color;
final String en_text;
final String ja_text;
final String ja_image;
final String sound;
How can I remove or disable it to use it on other pages has those objects on it? for examble: "ja_image". Thanks in advance...
CodePudding user response:
If I understand correctly you simply need a question mark ? after data type like so final String? nu_image;
. and remove the required
keyword from the constructor. That way you can create instance of this class without all parameters needed.