带系统(6271):忽略标头X-Firebase-Locale,因为其值为空

0x6upsns  于 2022-11-30  发布在  其他
关注(0)|答案(1)|浏览(121)

我在终端上收到此错误忽略标题X-Firebase-Locale,因为其值为空当用户登录或注册时。用户登录时屏幕不会更改状态。我已启用电子邮件密码登录,请使用SHA-1和SHA-256(从./gradlew signingReport获得)在我的firebase.console为这个应用程序,但仍然,不断从终端收到这个错误,我不知道如何解决这个问题。真的需要你的帮助。
下面是我的代码和目录。

  • 验证日期 *
import 'package:firebase_auth/firebase_auth.dart';
import 'package:twitterclone/models/users.dart';

class AuthService {
  FirebaseAuth auth = FirebaseAuth.instance;

  UserModel? _userFromFirebaseUser(User? user) {
    return user != null ? UserModel(id: user.uid) : null;
  }

  Stream<UserModel?> get user {
    return auth.authStateChanges().map(_userFromFirebaseUser);
  }

  Future signUp(emailSignUp, passwordSignUp) async {
    try {
      User user = (await auth.createUserWithEmailAndPassword(
          email: emailSignUp, password: passwordSignUp) as User);
      _userFromFirebaseUser(user);
    } on FirebaseAuthException catch (e) {
      if (e.code == 'weak-password') {
        print('The password provided is too weak.');
      } else if (e.code == 'email-already-in-use') {
        print('The account already exists for that email.');
      }
    } catch (e) {
      print(e);
    }
  }

  Future signIn(emailSignIn, passwordSignIn) async {
    try {
      User user = (await auth.signInWithEmailAndPassword(
          email: emailSignIn, password: passwordSignIn) as User);
      _userFromFirebaseUser(user);
    } on FirebaseAuthException catch (e) {
      print(e);
    } catch (e) {
      print(e);
    }
  }

  Future signOut() async {
    try {
      return await auth.signOut();
    } catch (e) {
      print(e.toString());
      return null;
    }
  }
}
  • Package .省道 *
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:twitterclone/models/users.dart';
import 'package:twitterclone/screens/auth/welcome.dart';
import 'package:twitterclone/screens/mainscreen/feedscreen.dart';

class Wrapper extends StatelessWidget {
  const Wrapper({Key? key}) : super(key: key);
  @override
  Widget build(BuildContext context) {
    final user = Provider.of<UserModel?>(context);
    if (user == null) {
      print('no user');
      return Welcome();
    }
    print('has user');
    return FeedScreen();
  }
}
  • 用户.dart*
class UserModel {
  final String? id;
  UserModel({this.id});
}
  • 主省道 *
import 'dart:core';
import 'package:flutter/material.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:provider/provider.dart';
import 'package:twitterclone/models/users.dart';
import 'package:twitterclone/services/auth/auth.dart';
import 'package:twitterclone/wrapper/wrapper.dart';

Future<void> main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await Firebase.initializeApp();
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  final Future<FirebaseApp> _initialization = Firebase.initializeApp();

  @override
  Widget build(BuildContext context) {
    return FutureBuilder(
      future: _initialization,
      builder: (context, snapshot) {
        // Check for errors
        if (snapshot.hasError) {
          return Text('Oops, something went error. Try to restart the app.');
        }

        // Once complete, show your application
        if (snapshot.connectionState == ConnectionState.done) {
          return StreamProvider<UserModel?>.value(
            value: AuthService().user,
            initialData: null,
            child: MaterialApp(home: Wrapper()),
          );
        }

        // Otherwise, show something whilst waiting for initialization to complete
        return Text('Loading...');
      },
    );
  }
}
1zmg4dgp

1zmg4dgp1#

我希望你忘了加上ChangeNotifier
class AuthService { ...替换为class AuthService with ChangeNotifier{ ...

相关问题