小编Sri*_*ath的帖子

当用户注销时,FirebaseAuth.instance.onAuthStateChanged 不会触发流构建器

我的 Flutter 应用程序包含几个屏幕,如设置、添加产品、详细信息页面。

我在主页的流构建器中使用 FirebaseAuth.instance.onAuthStateChanged 来决定根据 onAuthStateChanged 更改显示登录或主页,如果用户在设置页面中并单击“FirebaseAuth.instance.signOut();”注销” ,应用程序停留在相同的设置页面上,并且不会重定向到我们在主页中使用的流构建器中提到的登录页面,如下所示。

MaterialApp(
          home: StreamBuilder(
            stream: FirebaseAuth.instance.onAuthStateChanged,
            builder: (ctx, snapSot) {
              if (snapSot.hasData) {
                return HomePage();
              } else
                return  LoginScreen();
            },
          ),),)
Run Code Online (Sandbox Code Playgroud)

包版本:

  • 提供者:^4.1.2
  • firebase_auth:^0.16.1

我的期望:

用户在哪个页面中,如果他退出,他必须被带到登录屏幕。由于我正在使用 Streambuilder,并且我已将流源提供为 onAuthStateChanged。

工作场景:

但是,当用户在主页屏幕中单击注销时,它会按预期工作,并且用户将被带到登录页面。

不工作场景:

如果用户在任何其他页面中,它不会重定向到登录页面。单击注销时,我可以在控制台中看到以下日志。

场景:用户导航:登录->首页->应用抽屉->设置页面->退出

I/flutter ( 6186): HomePage
I/flutter ( 6186): appDrawer
I/flutter ( 6186): Settings
I/flutter ( 6186): appDrawer
I/flutter ( 6186): logoutDialog
D/FirebaseAuth( 6186): Notifying id token listeners about a sign-out event.
D/FirebaseAuth( 6186): Notifying auth state listeners about a sign-out …
Run Code Online (Sandbox Code Playgroud)

firebase-authentication flutter

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

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
查看次数