class - How can I access global data from another class in Flutter?
问题描述
I have a simple class like;
import 'dart:io';
class IDCardClass {
File frontImageFile;
File backImageFile;
}
From front_test.dart
class I need to assign a data to frontImageFile
and back_test.dart
class I need to assign a data to backImageFile
.
In my home.dart
or another ***.dart
class I need to get frontImageFile
and backImageFile
to show it to user.
My question is How can I access global data from another class in Flutter?
解决方案
使变量static
像这样:
class IDCardClass {
static File frontImageFile;
static File backImageFile;
}
只需将该类导入另一个类并访问变量。
import 'package:your_projectname/your_folder/IDCardClass.dart';
.....
var imageFile = IDCardClass.frontImageFile;
.....
推荐阅读
- mysql - 使用 NodeJs 查询我的 mySQL 时出现“无法设置未定义的属性‘长度’”错误
- python - 将非转义转义字符添加到 python bytearray
- html - 滚动条未在 HTML 文档的右侧显示完整内容
- jquery - 如何隐藏下拉列表中除最大值之外的所有选项?
- php - 即使我在设置 Google Indexing API 后收到“OK”和“200”状态,也没有看到任何招聘结果
- kubernetes - Kubernetes仪表板节点端口不工作
- javascript - 扩展 Angular 材质数据表标题行以匹配行内容宽度?
- python-3.x - 如何在熊猫中舍入日期和时间
- c# - .net core 3 preview 8 升级后的 React SPA / Embedded Identity Server 问题
- r - R错误:“哪个”的参数不合逻辑