我更新了我的 pubspec.yaml ,并且显示了一些错误。我该如何解决?
错误:
这是我的代码-
import 'package:firebase_auth/firebase_auth.dart';
import 'package:google_sign_in/google_sign_in.dart';
import 'package:apple_sign_in/apple_sign_in.dart';
import 'package:cloud_firestore/cloud_firestore.dart';
import 'dart:async';
class AuthService {
final GoogleSignIn _googleSignIn = GoogleSignIn();
final FirebaseAuth _auth = FirebaseAuth.instance;
final FirebaseFirestore _db = FirebaseFirestore.instance;
// Firebase user one-time fetch
Future<User> get getUser => _auth.currentUser;
// Firebase user a realtime stream
Stream<User> get user => _auth.authStateChanges();
// Determine if Apple Signin is available on device
Future<bool> get appleSignInAvailable => AppleSignIn.isAvailable();
/// Sign in with Apple
Future<User> appleSignIn() async {
try {
final AuthorizationResult appleResult =
await AppleSignIn.performRequests([
AppleIdRequest(requestedScopes: [Scope.email, Scope.fullName])
]);
if (appleResult.error != null) {
// handle errors from Apple
}
final AuthCredential credential =
OAuthProvider(providerId: 'apple.com').credential(
accessToken:
String.fromCharCodes(appleResult.credential.authorizationCode),
idToken: String.fromCharCodes(appleResult.credential.identityToken),
);
UserCredential firebaseResult =
await _auth.signInWithCredential(credential);
User user = firebaseResult.user;
// Update user data
updateUserData(user);
return user;
} catch (error) {
print(error);
return null;
}
}
/// Sign in with Google
Future<User> googleSignIn() async {
try {
GoogleSignInAccount googleSignInAccount = await _googleSignIn.signIn();
GoogleSignInAuthentication googleAuth =
await googleSignInAccount.authentication;
final AuthCredential credential = GoogleAuthProvider.credential(
accessToken: googleAuth.accessToken,
idToken: googleAuth.idToken,
);
UserCredential result = await _auth.signInWithCredential(credential);
User user = result.user;
// Update user data
updateUserData(user);
return user;
} catch (error) {
print(error);
return null;
}
}
/// Anonymous Firebase login
Future<User> anonLogin() async {
UserCredential result = await _auth.signInAnonymously();
User user = result.user;
updateUserData(user);
return user;
}
/// Updates the User's data in Firestore on each new login
Future<void> updateUserData(User user) {
DocumentReference reportRef = _db.collection('reports').doc(user.uid);
return reportRef
.set({'uid': user.uid, 'lastActivity': DateTime.now()}, merge: true);
}
// Sign out
Future<void> signOut() {
return _auth.signOut();
}
}
这是pubspec.yaml-
name: quizapp
description: Realtime Quiz app built with Flutter & Firebase
version: 1.4.0
environment:
sdk: ">=2.7.0 <3.0.0"
dependencies:
flutter:
sdk: flutter
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^0.1.2
firebase_core: ^0.5.1
firebase_analytics: ^6.1.0
cloud_firestore: ^0.14.2
firebase_auth: ^0.18.2
google_sign_in: ^4.5.6
apple_sign_in: ^0.1.0
rxdart: ^0.24.1
provider: ^4.3.2+2
font_awesome_flutter: 8.8.1
dev_dependencies:
flutter_test:
sdk: flutter
flutter:
assets:
- assets/
- assets/covers/
- assets/congrats.gif
# The following line ensures that the Material Icons font is
# included with your application, so that you can use the icons in
# the material Icons class.
uses-material-design: true
# To add assets to your application, add an assets section, like this:
# assets:
# - images/a_dot_burr.jpeg
# - images/a_dot_ham.jpeg
# An image asset can refer to one or more resolution-specific "variants", see
# https://flutter.dev/assets-and-images/#resolution-aware.
# For details regarding adding assets from package dependencies, see
# https://flutter.dev/assets-and-images/#from-packages
# To add custom fonts to your application, add a fonts section here,
# in this "flutter" section. Each entry in this list should have a
# "family" key with the font family name, and a "fonts" key with a
# list giving the asset and other descriptors for the font. For
# example:
# fonts:
# - family: Schyler
# fonts:
# - asset: fonts/Schyler-Regular.ttf
# - asset: fonts/Schyler-Italic.ttf
# style: italic
# - family: Trajan Pro
# fonts:
# - asset: fonts/TrajanPro.ttf
# - asset: fonts/TrajanPro_Bold.ttf
# weight: 700
#
# For details regarding fonts from package dependencies,
# see https://flutter.dev/custom-fonts/#from-packages
请有人帮我保存。
答案 0 :(得分:1)
以此替换您的代码。
get getUser => _auth.currentUser;
和
final AuthCredential credential =
OAuthProvider('apple.com').credential(
accessToken:
String.fromCharCodes(appleResult.credential.authorizationCode),
idToken: String.fromCharCodes(appleResult.credential.identityToken),
);
也
Future<void> updateUserData(User user) {
DocumentReference reportRef = _db.collection('reports').doc(user.uid);
return reportRef
.set({'uid': user.uid, 'lastActivity': DateTime.now()}, SetOptions(merge: true) );
}
答案 1 :(得分:0)
如果您的代码之前未运行过,请切换到抖动的安全通道。搜索安全频道时,您会在此处找到很多说明
答案 2 :(得分:0)
用以下代码替换您的代码:
1。
Future<User> get getUser => _auth.currentUser;
上
Future<User> get getUser => await _auth.currentUser;
final AuthCredential credential =
OAuthProvider(providerId: 'apple.com').credential(
accessToken:
String.fromCharCodes(appleResult.credential.authorizationCode),
idToken: String.fromCharCodes(appleResult.credential.identityToken),
);
上
final AuthCredential credential =
OAuthProvider(providerId: 'apple.com').getCredential(
accessToken:
String.fromCharCodes(appleResult.credential.authorizationCode),
idToken: String.fromCharCodes(appleResult.credential.identityToken),
);