简体   繁体   中英

How can I remove or disable some objects from class in flutter to use it on another pages

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...

If I understand correctly you simply need a question mark? after data type like so final String? nu_image; 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM