小编you*_*low的帖子

应用程序在后台时不会触发 firebaseMessagingBackgroundHandler

我假设我遵循了在 flutter 中处理来自 firebase 的后台通知的所有步骤。我创建了一个顶级函数,希望在收到通知时触发该函数。但是,该函数永远不会被触发。

这是我的主页小部件中存在但在类之外的顶级后台处理程序函数:

Future<void> firebaseMessagingBackgroundHandler(RemoteMessage message) async {
  WidgetsFlutterBinding.ensureInitialized();
  await Firebase.initializeApp();
  // ignore: avoid_print
  print('A background message just showed up :  ${message.messageId}');

  // update SQLite
  var result = await PageService.instance
      .add(PageService.instance.convertToPage(message.data));
  print('added to db: ${result}');
}
Run Code Online (Sandbox Code Playgroud)

这是我的主页初始化状态,它调用一个函数来初始化 firebase 消息:

@override
  void initState() {
    super.initState();

    _initializeFirebaseMessaging();
  }
Run Code Online (Sandbox Code Playgroud)

这里也是在主页类中定义的 _initializeFirebaseMessaging 函数:

void _initializeFirebaseMessaging() {
    FirebaseMessaging.onBackgroundMessage(firebaseMessagingBackgroundHandler);

    FirebaseMessaging.onMessage.listen((RemoteMessage message) async {
      print('new notification arrived');
      RemoteNotification? notification = message.notification;
      AndroidNotification? android = message.notification?.android;

      // update SQLite
      var result = await …
Run Code Online (Sandbox Code Playgroud)

push-notification firebase flutter firebase-cloud-messaging

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

无论框装饰背景颜色如何,更改子按钮元素的颜色

我正在构建一个登陆页面,该页面有一个徽标,然后在其下方有一个登录和登录按钮。我使用了一个盒子装饰来指定背景颜色,因为我对渐变方案非常讲究。但是,我意识到它可能会对我的容器小部件产生某种“绝对”影响,因为我似乎无法更改小部件内按钮的颜色。我是 flutter UI 的新手,我可能错误地分层了小部件,但任何帮助将不胜感激!这是着陆页的代码:

import 'package:flutter/material.dart';
import 'package:zefyr/common_widgets/cutom_elevated_button.dart';

class LandingPage extends StatelessWidget {
  const LandingPage({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
      decoration: const BoxDecoration(
         gradient : LinearGradient(
             begin: Alignment(0.1705881804227829,-0.7394942045211792),
             end: Alignment(0.7395344376564026,0.7999715805053711),
             colors: [Color.fromRGBO(212, 7, 248, 1),Color.fromRGBO(141, 6, 248, 1)]
         ),
        image: DecorationImage(
          image: AssetImage('assets/images/zefyr_logo.png'),
        ),
       ),
      child: Column(
          crossAxisAlignment: CrossAxisAlignment.center,
          children: const <Widget>[
            SizedBox(height: 450,),
            CustomElevatedButton(
              bgColor: Colors.white,
              textColor: Colors.pinkAccent,
              onPressed: null,
              height: 62,
              text: "Sign Up",
            ),
            SizedBox(height: 12,),
            CustomElevatedButton(
              bgColor: Colors.white,
              textColor: Colors.pinkAccent, …
Run Code Online (Sandbox Code Playgroud)

user-interface dart flutter

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

从推送通知 flutter_local_notification 包导航到屏幕

我正在使用 flutter_local_notification 包来处理来自第三方服务器的通知(不是 firebase 云消息传递)。因为我使用的是 firebase 但不是 firebase 消息传递,所以我使用的是 flutter-local_notification 包的 onSelectNotification 函数。

这是我传递给 onSelectNotification 的函数:

static _selectNotification(String payload, StreamChatClient client, RemoteMessage message) {
    debugPrint('notification payload: $payload');

    if(payload.contains('livestream')) {
      Utils.db.getLiveRoom(payload.split(":")[1]).then((liveRoom) {
        Navigator.push(
          NavigationService.navigatorKey.currentContext!,
          MaterialPageRoute<void>(builder: (context) => LiveRoomChat(liveRoom: liveRoom)),
        );
      });
    }
    else {
      List<String> ids = message.data['channel_id'].toString().split('_');
      String receiverId = '';
      if(ids[0] == Utils.user?.uid) {
        receiverId = ids[1];
      }
      else {
        receiverId = ids[0];
      }

      Navigator.push(
        NavigationService.navigatorKey.currentContext!,
        MaterialPageRoute<void>(builder: (context) => MessageApi(
            sourceType: Utils.friends.containsKey(receiverId) ? SourceType.friends : SourceType.justMet,
            receiverId: receiverId,
            channelId: …
Run Code Online (Sandbox Code Playgroud)

push-notification flutter flutter-local-notification

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

如何确保一部手机只有一个账户可以登录flutter应用

大家好,我正在 flutter 中构建一个应用程序,并使用 firebase 作为后端。我允许用户使用他们的电话号码(然后是密码)注册并登录应用程序。但是,我想为注册/登录流程添加一层额外的唯一性。

我的意思是,我只想从一台设备访问最多一个帐户。如果人员 A 在手机 A 上创建帐户,则他们只能使用手机 A 上的应用程序。人员 A 不应该能够通过手机 B 登录其帐户。

我不认为短信二因素就足够了,因为人 A 可以与人 B 共享二因素代码。然后,人 B 将能够在电话 B 上登录人 A 的帐户,因为他们有人 A 的电话号码和二因素代码。

有没有办法为在 firebase 上运行的 flutter 应用程序实现此功能?

authentication dart firebase firebase-authentication flutter

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