小编pad*_*ana的帖子

Flutter Hive 商店颜色

我需要将颜色存储在我的 Hive 数据库中以便在我的电子商务应用程序中检索,它给了我下面的错误,说我需要制作一个适配器,谁能告诉我如何制作颜色适配器?

part 'items_model.g.dart';

@HiveType(typeId: 0)
class Item {
  @HiveField(0)
  final String name;
  @HiveField(1)
  final double price;
  @HiveField(2)
  final String? description;
  @HiveField(3)
  var image;
  @HiveField(4)
  final String id;
  @HiveField(5)
  final String shopName;
  @HiveField(6)
  final List<Category> category;
  @HiveField(7)
  Color? color;
  @HiveField(8)
  int? quantity;
  Item({
    required this.category,
    required this.image,
    required this.name,
    required this.price,
    this.description,
    required this.id,
    required this.shopName,
    this.color,
    required this.quantity,
  });



}
Run Code Online (Sandbox Code Playgroud)

有谁知道如何生成或创建颜色适配器?因为我不知道怎么做

E/flutter ( 4621): [ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: HiveError: Cannot write, unknown type: MaterialColor. Did you forget to register …
Run Code Online (Sandbox Code Playgroud)

dart flutter flutter-hive

3
推荐指数
1
解决办法
1141
查看次数

Flutter Hive:制作多个 openBox

我正在使用 Hive 来制作简单的 CRUD;在Hive Doc about open box 中,我们可以这样声明:

var box = await Hive.openBox<E>('testBox');
Run Code Online (Sandbox Code Playgroud)

我的问题:是否可以制作多个 openBox?我想要这样的东西:

Future _openBox() async {
  var dir = await getApplicationDocumentsDirectory();
  Hive.init(dir.path);
  var box_session = await Hive.openBox("box_session");
  var box_comment = await Hive.openBox("box_comment");
  return await box_session,box_comment;
}
Run Code Online (Sandbox Code Playgroud)

dart flutter flutter-hive

2
推荐指数
1
解决办法
4496
查看次数

Flutter:Hive 方法“get”方法在 null 上调用

我试图在我的应用程序中使用 Hive 作为 Flutter 中共享首选项的替代方案。但是,我不断收到一条错误消息:

I/flutter ( 4004): The method 'get' was called on null.
I/flutter ( 4004): Receiver: null
I/flutter ( 4004): Tried calling: get("counter", defaultValue: 0)

E/flutter ( 4004): [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] 
Unhandled Exception: HiveError: This should not happen. Please open an 
issue on GitHub.
Run Code Online (Sandbox Code Playgroud)

我遵循了pub.dev文档中显示的所有步骤,但是,我没有使用任何步骤TypeAdapters,我只是尝试使用int. 这是我的实现:

var box = Hive.box('box');
int counter;
        
 void initHive() async {
 await openBox();
 getCounter();  //Updated code
 }

Future openBox() async {
var dir = await getApplicationDocumentsDirectory();
Hive.init(dir.path);
box …
Run Code Online (Sandbox Code Playgroud)

flutter flutter-hive

2
推荐指数
1
解决办法
2099
查看次数

Hive 错误未知类型 TimeStamp 。您是否忘记注册适配器?如何为外部包中使用的对象类型生成TypeAdapter?

我的 flutter 应用程序使用 Hive 进行本地数据管理,使用 Firebase 进行云数据存储。

我有一个使用 Firebase 包中的 Timestamp 和 FieldValue 的模式。我还创建了 TypeAdapter 并在主类中为我的自定义模式注册了它。

执行应用程序 Hive 时抛出以下错误:

未处理的异常:配置单元错误:无法写入,未知类型:时间戳。您是否忘记注册适配器?

问题:

如何为内置对象类型(例如Firebase 包中的TimestampFieldValue)创建 TypeAdapter (存在于类中loud_firestore.dart:)?

包裹:

dependencies:

  hive: ^1.4.4

dev_dependencies:

  hive_generator: ^0.7.1

  build_runner: 
Run Code Online (Sandbox Code Playgroud)

示例代码:

主要类别:

Hive.registerAdapter(SampleModalAdapter());
Run Code Online (Sandbox Code Playgroud)

模态代码:

import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:hive/hive.dart';

part 'samplemodal.g.dart';

@HiveType(typeId: 1)
class SampleModal {
  @HiveField(0)
  String id;
  @HiveField(1)
  String title;
  @HiveField(2)
  Timestamp dateTime;
  @HiveField(3)
  FieldValue serverDateTime;
  SampleModal({
    this.id,
    this.title,
    this.dateTime,
    this.serverDateTime,
  });
}
Run Code Online (Sandbox Code Playgroud)

生成的 TypeAdapter 代码:

// GENERATED CODE - …
Run Code Online (Sandbox Code Playgroud)

dart flutter flutter-hive

2
推荐指数
1
解决办法
3508
查看次数

如何通过数据值过滤颤振中的 Hive 数据?

在 Flutter 中,我使用ValueListenableBuilder小部件来获取配置单元数据列表,并尝试按数据值过滤我的数据。

例子:-

Key: 1

name(value) : mydata1

des(value) : mydescription1

value(value) : 1
Run Code Online (Sandbox Code Playgroud)

在这个例子中,我想value(value)通过下拉帮助调用的数据值过滤数据,

喜欢:

if (value.compareTo(1) == 1){
 print('All First Value Data Showing Result');
}
Run Code Online (Sandbox Code Playgroud)

类似的东西:

Key: 1

name(value) : mydata1

des(value) : mydescription1

value(value) : 1
Run Code Online (Sandbox Code Playgroud)

ValueListenableBuilder mycode 图像

database hive dart flutter

2
推荐指数
2
解决办法
4598
查看次数

参数类型“对象?” 无法分配给参数类型“Widget?”

我正在遵循教程,但收到此错误

' 参数类型'对象?' 无法分配给参数类型“Widget?”.dartargument_type_not_assignable'。

我尝试查看文档,但我确实知道如何解决该错误

import 'package:flutter/material.dart';
import 'search.dart';
import 'user_info.dart';

import 'cart.dart';
import 'feed.dart';
import 'home.dart';

class BottomBarScreen extends StatefulWidget {
  @override
  _BottomBarScreenState createState() => _BottomBarScreenState();
}

class _BottomBarScreenState extends State<BottomBarScreen> {
  List<Map<String, Object>> _pages;
  int _selectedPageIndex = 0;

  @override
  void initState() {
    _pages = [
      {
        'page': home(),
     },
      {
        'page': feed(),
      },
      {
        'page': search(),
      },
  {
    'page': cart(),
  },
  {
    'page': user_info(),
  },
];
super.initState();
  }

  void _selectPage(int index) {
    setState(() {
    _selectedPageIndex = index;
   }); …
Run Code Online (Sandbox Code Playgroud)

mobile-development flutter

2
推荐指数
1
解决办法
1万
查看次数

如何删除 Hive Flutter 中的所有框?

我正在使用 Flutter 开发应用程序;它会在本地存储一些数据,所以我决定使用 Hive 包,这是一个非常棒的包来存储数据。所以现在我将在用户按下同步按钮时将所有数据存储在本地。之后,如果用户再次单击同步,我必须删除所有框并存储可能具有或可能不具有相同框名称的数据。
如果单击同步按钮,我不想增加应用程序存储空间,我想删除所有框,然后再次创建框。

flutter flutter-hive

1
推荐指数
3
解决办法
6957
查看次数

哪个队列与 requestAnimationFrame 关联?

今天我在接受采访时被问到这个问题。我无法回答这个问题,面试官说有一个特殊的队列用于 requestAnimationFrame 回调。但我找不到任何这方面的信息。

如果 rAF 有它自己的队列,那么为什么这个队列从未在任何地方被提及?当我们谈论事件循环时,我们只提到宏任务队列和微任务队列?

javascript event-loop requestanimationframe

1
推荐指数
1
解决办法
367
查看次数

控制台中的奇怪结果:将“未定义”附加到输出

我正在尝试完成 Odin 项目并看到一个有趣的控制台错误

function repeat(string, number) {
  var finalst;

  for (i = 0; i < number; i++) {
    finalst += string;

  }
  return finalst;
}
console.log(repeat("hey", 3));
Run Code Online (Sandbox Code Playgroud)

控制台中的结果是“undefinedheyheyhey”。它是如何显示的,为什么?

javascript

0
推荐指数
1
解决办法
57
查看次数