我正在尝试按照此SO 评论使用Hive读取 Box 的内容,但出现以下错误:
方法 'listenable' 没有为类型 'Box' 定义
有问题的代码是:
FutureBuilder(
future: Hive.openBox<Contact>('testBox'),
builder: (context, snapshot) {
return ValueListenableBuilder(
valueListenable: Hive.box<Contact>('contacts').listenable(),
builder: (context, Box<Contact> box, _) {
if (box.values.isEmpty) {
return Text('data is empty');
} else {
return ListView.builder(
itemCount: box.values.length,
itemBuilder: (context, index) {
var contact = box.getAt(index);
return ListTile(
title: Text(contact.name),
subtitle: Text(contact.age.toString()),
);
},
);
}
},
);
},
),
Run Code Online (Sandbox Code Playgroud)
pubspec.yaml:
hive: ^1.4.1+1
hive_flutter:
git:
url: git://github.com/hivedb/hive.git
path: hive_flutter
Run Code Online (Sandbox Code Playgroud)
我想要做的是在屏幕加载时列出框的内容。我似乎无法弄清楚我哪里出错了 - 任何指导将不胜感激!
我如何才能看到是什么导致我的小部件不断传播小部件树?我正在使用 Provider 包并遇到小部件不断堆积的问题 - 例如,如果我向主页添加打印语句:
@override
Widget build(BuildContext context) {
print("Home");
Run Code Online (Sandbox Code Playgroud)
然后在应用程序中导航一段时间后,如果我清除调试控制台并加载主页或其下方的任何屏幕,我将获得多个“主页”打印输出,即:
flutter: Home
flutter: Home
flutter: Home
flutter: Home
flutter: Home
flutter: Home
Run Code Online (Sandbox Code Playgroud)
我在应用程序中导航的次数越多,它们堆积的就越多。调试这个的正确方法是什么?
我正在按照教程在上传时通过 Cloud Functions 调整图像大小,但遇到了两个我无法弄清楚的主要问题:
1) 如果上传了 PNG,它会生成大小正确的缩略图,但它们的预览不会在 Firestorage 中加载(加载微调器无限期显示)。它只在我点击“生成新的访问令牌”后显示图像(最初生成的缩略图都没有访问令牌)。
2) 如果上传了 JPEG 或任何其他格式,则 MIME 类型显示为“application/octet-stream”。我不确定如何正确提取扩展名以放入新生成的缩略图的文件名中?
export const generateThumbs = functions.storage
.object()
.onFinalize(async object => {
const bucket = gcs.bucket(object.bucket);
const filePath = object.name;
const fileName = filePath.split('/').pop();
const bucketDir = dirname(filePath);
const workingDir = join(tmpdir(), 'thumbs');
const tmpFilePath = join(workingDir, 'source.png');
if (fileName.includes('thumb@') || !object.contentType.includes('image')) {
console.log('exiting function');
return false;
}
// 1. Ensure thumbnail dir exists
await fs.ensureDir(workingDir);
// 2. Download Source File
await bucket.file(filePath).download({
destination: tmpFilePath …Run Code Online (Sandbox Code Playgroud) 有没有办法只在 Firestore 中存储时间值(没有日期)?我正在尝试在 Flutter 应用程序(营业时间)中实现以下目标:
company [document]
hours [map]
- mon [map]
- open: 08:00 [timestamp...?]
- close: 18:00
- tue [map]
- open: 08:00
- close: 18:00
Run Code Online (Sandbox Code Playgroud)
我想以可用于计算的格式存储它(即,公司今天关闭多长时间)。
我试过使用 TimeStamp 并为每一天 (01/01/2001) 设置一个通用日期,然后只使用 DateFormat('HH:ss') 检索时间,但问题是它然后返回一个字符串,它可以' 不用于计算。
有人可以指出我正确的方向吗?
您如何根据索引更新列表中的特定值?例如,在以下列表中:
0 [
{
first_name: name0,
last_name: lastName0,
}
]
1 [
{
first_name: name1,
last_name: lastName1,
}
]
Run Code Online (Sandbox Code Playgroud)
如何仅更新“lastName1”?目前,我使用了一些使用 ArrayUnion 的 hacky 解决方案,它使用数据比较而不是实际索引(我将值加载到表单中,删除原始值,然后再次重新添加):
// Retrieve data at index, load into form
// Remove that index from List
await Firestore.instance.collection(col).document(doc).updateData({
'people': FieldValue.arrayRemove([person])
});
// Make changes to data via form
// Save back to list
await Firestore.instance.collection(col).document(doc).updateData({
'people': FieldValue.arrayUnion([person])
});
Run Code Online (Sandbox Code Playgroud)
是否有一个函数可以让我指定要更新哪个特定索引的数据?类似(但使用列表,而不是地图):
await Firestore.instance.collection(col).document(doc).updateData({
'people.$index.lastName1': 'newName')
});
Run Code Online (Sandbox Code Playgroud)