简体   繁体   English

如何从 flutter 中的 class 中删除或禁用某些对象以在其他页面上使用它

[英]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.在我的 flutter 应用程序中,我制作了一个 class 以在具有相同对象的其他页面上使用它,但在其他页面上,不是所有这些对象。

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".例如:“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; final String? nu_image; . . and remove the required keyword from the constructor.并从构造函数中删除required关键字。 That way you can create instance of this class without all parameters needed.这样,您无需所有参数即可创建此 class 的实例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何禁用flutter中某些页面的bottomnavigationbar? - How to disable bottomnavigationbar some pages in flutter? 如何从 flutter 中的另一个 class 访问 map? - How can I get access to a map from another class in flutter? 如何从 Flutter 中的另一个类访问全局数据? - How can I access global data from another class in Flutter? Flutter:如何从另一个 class 调用方法? - Flutter: how can I call method from another class? 仅当 Flutter 应用程序上的网络时,如何才能禁用某些功能? - How can I disable some functionality only if web on Flutter app? 我如何从不同页面获取数据并使用flutter中的共享首选项将数据呈现到另一个页面中 - How i can get data from the diffrent pages and render that data into another page using shared preferences in flutter 如何禁用 Flutter slider class 以防止用户移动它? - How can I disable the Flutter slider class to prevent a user from moving it? 如何在 Flutter 中使用带有枚举 class 的“in”? - How Can I Use the "in" with enum class in Flutter? 知道应用程序内的信息作为列表存在于另一个 class 中,我如何使用 flutter 中的搜索 - How can i use the search in flutter knowing that the information inside the application is present as a list in another class 如何使用 Flutter 中的 Navigator.pages 从堆栈中删除页面 - How to remove pages from stack using Navigator.pages in Flutter
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM