android - How to pass data from stateful widget to Dialog Box?
问题描述
I want to pass the input taken from a user in stateful widget to the stateless DialogBox. I am a beginner and it is my first code.
the input will be taken in texfield in stateful widget and output will be displayed in Dialogbox
解决方案
嗯...请尝试阅读文档(Dart)
Flutter 是用 Dart 编写的,所以这就是我要开始的地方。
现在,回答您的问题,对于您的情况,为了将信息传递给无状态对话框,最简单的方法是使用构造函数。然后,当您调用 Dialogue Widget 时,您只需将此信息直接传递给它。
像这样:
class StatelessDialogue extends StatelessWidget{
final String informationToPass;
StatelessDialogue({@required this.informationToPass});
@override
Widget build(BuildContext context){
return AlertDialog(
contentPadding: EdgeInsets.all(20),
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(25)),
content: Text(this.informationToPass)
);
}
}
@required是 Dart 中的一个属性,用于向 IDE 指示该参数informationToPass是必需的,以便对话小部件工作。
推荐阅读
- java - 遍历二维数组
- javascript - Sequelize - 使用 es6 和模块运行迁移
- python - .get() 在空的 Tkinter 条目小部件上返回什么
- php - 如何在 GitHub 存储库中包含 Composer
- flutter - 悬停时显示/隐藏下拉菜单 Flutter for web
- ruby-on-rails - 捆绑更新轨道上的不兼容依赖项
- javascript - javascript 无法从 Python 烧瓶转换为对象 JSON 只能将其视为字符串
- scipy - Scipy最小化函数约束声明问题
- html - PSD to bootstrap - 请建议保持 HTML 与大 PSD 相同
- javascript - JSON 文件中的 HTML 标记显示为纯文本而不是真正的 HTML 标记