rand dart fix
This commit is contained in:
@@ -35,7 +35,7 @@ class _MyAppState extends State<MyApp> {
|
||||
@override
|
||||
void dispose() {
|
||||
_auth.close();
|
||||
_userChanged?.cancel();
|
||||
_userChanged.cancel();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,19 +1,8 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
void setTargetPlatformForDesktop({TargetPlatform platform}) {
|
||||
TargetPlatform targetPlatform;
|
||||
if (platform != null) {
|
||||
targetPlatform = platform;
|
||||
}
|
||||
if (targetPlatform == null) {
|
||||
if (Platform.isMacOS) {
|
||||
targetPlatform = TargetPlatform.iOS;
|
||||
} else if (Platform.isLinux || Platform.isWindows) {
|
||||
targetPlatform = TargetPlatform.android;
|
||||
}
|
||||
}
|
||||
targetPlatform = platform;
|
||||
debugDefaultTargetPlatformOverride = targetPlatform;
|
||||
}
|
||||
|
||||
@@ -72,7 +72,7 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
|
||||
final _user = await _auth.loginGoogle(
|
||||
idToken: event.idToken, accessToken: event.accessToken);
|
||||
if (_user != null) {
|
||||
if (saveUser != null) saveUser(_user);
|
||||
saveUser(_user);
|
||||
yield LoggedInState(_user);
|
||||
} else {
|
||||
yield LoggedOutState();
|
||||
@@ -82,37 +82,25 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
|
||||
Stream<AuthState> _mapGuestToState(LoginGuest event) async* {
|
||||
yield AuthLoadingState();
|
||||
final _user = await _auth.startAsGuest();
|
||||
if (_user != null) {
|
||||
if (saveUser != null) saveUser(_user);
|
||||
yield LoggedInState(_user);
|
||||
} else {
|
||||
yield LoggedOutState();
|
||||
saveUser(_user);
|
||||
yield LoggedInState(_user);
|
||||
}
|
||||
}
|
||||
|
||||
Stream<AuthState> _mapCheckToState(CheckUser event) async* {
|
||||
yield AuthLoadingState();
|
||||
final _user = await _auth.currentUser();
|
||||
if (_user != null) {
|
||||
if (saveUser != null) saveUser(_user);
|
||||
yield LoggedInState(_user);
|
||||
} else {
|
||||
yield LoggedOutState();
|
||||
saveUser(_user);
|
||||
yield LoggedInState(_user);
|
||||
}
|
||||
}
|
||||
|
||||
Stream<AuthState> _mapCreateToState(CreateAccount event) async* {
|
||||
yield AuthLoadingState();
|
||||
try {
|
||||
AuthUser _user = await _auth.createAccount(event.username, event.password,
|
||||
displayName: event?.displayName, photoUrl: event?.photoUrl);
|
||||
if (_user != null) {
|
||||
if (saveUser != null) saveUser(_user);
|
||||
yield LoggedInState(_user);
|
||||
} else {
|
||||
yield AuthErrorState('Error creating user!');
|
||||
}
|
||||
} catch (e) {
|
||||
displayName: event.displayName, photoUrl: event.photoUrl);
|
||||
saveUser(_user);
|
||||
yield LoggedInState(_user);
|
||||
} catch (e) {
|
||||
yield AuthErrorState('Email already exists!');
|
||||
}
|
||||
}
|
||||
@@ -120,18 +108,14 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
|
||||
Stream<AuthState> _mapLoginToState(LoginEvent event) async* {
|
||||
yield AuthLoadingState();
|
||||
final _user = await _auth.login(event.username, event.password);
|
||||
if (_user != null) {
|
||||
if (saveUser != null) saveUser(_user);
|
||||
yield LoggedInState(_user);
|
||||
} else {
|
||||
yield AuthErrorState('Username or Password Incorrect!');
|
||||
saveUser(_user);
|
||||
yield LoggedInState(_user);
|
||||
}
|
||||
}
|
||||
|
||||
Stream<AuthState> _mapLogoutToState(LogoutEvent event) async* {
|
||||
yield AuthLoadingState();
|
||||
await _auth.logout();
|
||||
if (deleteUser != null) deleteUser();
|
||||
deleteUser();
|
||||
yield LoggedOutState();
|
||||
}
|
||||
|
||||
@@ -142,20 +126,16 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
|
||||
Stream<AuthState> _mapEditInfoToState(EditInfo event) async* {
|
||||
yield AuthLoadingState();
|
||||
await _auth.editInfo(
|
||||
displayName: event?.displayName, photoUrl: event?.photoUrl);
|
||||
displayName: event.displayName, photoUrl: event.photoUrl);
|
||||
final _user = await _auth.currentUser();
|
||||
if (saveUser != null) saveUser(_user);
|
||||
saveUser(_user);
|
||||
yield LoggedInState(_user);
|
||||
}
|
||||
|
||||
Stream<AuthState> _mapUpdateToState(UpdateUser event) async* {
|
||||
if (event?.user != null) {
|
||||
if (saveUser != null) saveUser(event.user);
|
||||
yield LoggedInState(event.user);
|
||||
} else {
|
||||
yield LoggedOutState();
|
||||
saveUser(event.user);
|
||||
yield LoggedInState(event.user);
|
||||
}
|
||||
}
|
||||
|
||||
Stream<AuthState> _mapForgotPasswordToState(ForgotPassword event) async* {
|
||||
await _auth.forgotPassword(event.email);
|
||||
|
||||
@@ -2,7 +2,6 @@ import 'dart:convert';
|
||||
import 'dart:io';
|
||||
|
||||
import '../../classes/index.dart';
|
||||
import '../../utils/directory.dart';
|
||||
import '../mobile/sdk.dart';
|
||||
import '../rest_api/client.dart';
|
||||
import 'impl.dart';
|
||||
@@ -35,12 +34,8 @@ class FBAuth implements FBAuthImpl {
|
||||
},
|
||||
onSave: (data) async {
|
||||
try {
|
||||
if (data == null) {
|
||||
await _saveFile.delete();
|
||||
} else {
|
||||
await _saveFile.writeAsString(json.encode(data));
|
||||
}
|
||||
} catch (e) {}
|
||||
await _saveFile.writeAsString(json.encode(data));
|
||||
} catch (e) {}
|
||||
},
|
||||
);
|
||||
}
|
||||
@@ -50,10 +45,7 @@ class FBAuth implements FBAuthImpl {
|
||||
}
|
||||
|
||||
Future _loadFile() async {
|
||||
if (_saveFile == null) {
|
||||
final dir = await PathUtils.getDocumentDir();
|
||||
_saveFile = File('${dir.path}/fb_auth.json');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
bool get useClient => isDesktop || useRestClient;
|
||||
|
||||
@@ -115,8 +115,8 @@ class FBAuth implements FBAuthImpl {
|
||||
Future editInfo({String displayName, String photoUrl}) async {
|
||||
final _user = _auth.currentUser;
|
||||
final _info = UserProfile();
|
||||
if (displayName != null) _info.displayName = displayName;
|
||||
if (photoUrl != null) _info.photoURL = photoUrl;
|
||||
_info.displayName = displayName;
|
||||
_info.photoURL = photoUrl;
|
||||
try {
|
||||
await _user.updateProfile(_info);
|
||||
} catch (e) {
|
||||
|
||||
@@ -94,8 +94,8 @@ class FbSdk implements FBAuthImpl {
|
||||
Future editInfo({String displayName, String photoUrl}) async {
|
||||
final _user = await _auth.currentUser();
|
||||
final _info = UserUpdateInfo();
|
||||
if (displayName != null) _info.displayName = displayName;
|
||||
if (photoUrl != null) _info.photoUrl = photoUrl;
|
||||
_info.displayName = displayName;
|
||||
_info.photoUrl = photoUrl;
|
||||
try {
|
||||
await _user.updateProfile(_info);
|
||||
} catch (e) {
|
||||
|
||||
@@ -43,18 +43,16 @@ class FbClient implements FBAuthImpl {
|
||||
@override
|
||||
Future<AuthUser> currentUser() async {
|
||||
FirestoreJsonAccessToken token = await _loadToken();
|
||||
if (token != null) {
|
||||
var result = await http.post(
|
||||
'https://identitytoolkit.googleapis.com/v1/accounts:lookup?key=${app.apiKey}',
|
||||
body: json.encode({
|
||||
"idToken": token?.idToken,
|
||||
"returnSecureToken": true,
|
||||
}),
|
||||
);
|
||||
token = await _saveToken(result);
|
||||
return _getUser(token);
|
||||
}
|
||||
return null;
|
||||
var result = await http.post(
|
||||
'https://identitytoolkit.googleapis.com/v1/accounts:lookup?key=${app.apiKey}',
|
||||
body: json.encode({
|
||||
"idToken": token.idToken,
|
||||
"returnSecureToken": true,
|
||||
}),
|
||||
);
|
||||
token = await _saveToken(result);
|
||||
return _getUser(token);
|
||||
return null;
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -63,16 +61,15 @@ class FbClient implements FBAuthImpl {
|
||||
final result = await http.post(
|
||||
'https://identitytoolkit.googleapis.com/v1/accounts:update?key=${app.apiKey}',
|
||||
body: json.encode({
|
||||
"idToken": token?.idToken,
|
||||
if (displayName != null) ...{
|
||||
'displayName': displayName,
|
||||
},
|
||||
if (photoUrl != null) ...{
|
||||
'photoUrl': photoUrl,
|
||||
},
|
||||
"idToken": token.idToken,
|
||||
...{
|
||||
'displayName': displayName,
|
||||
},
|
||||
...{
|
||||
'photoUrl': photoUrl,
|
||||
},
|
||||
"deleteAttribute": [
|
||||
if (displayName == null) 'DISPLAY_NAME',
|
||||
if (photoUrl == null) 'PHOTO_URL',
|
||||
|
||||
],
|
||||
"returnSecureToken": true,
|
||||
}),
|
||||
@@ -126,7 +123,7 @@ class FbClient implements FBAuthImpl {
|
||||
var result = await http.post(
|
||||
'https://identitytoolkit.googleapis.com/v1/accounts:sendOobCode?key=${app.apiKey}',
|
||||
body: json.encode({
|
||||
"idToken": token?.idToken,
|
||||
"idToken": token.idToken,
|
||||
"requestType": 'VERIFY_EMAIL',
|
||||
}),
|
||||
);
|
||||
@@ -169,12 +166,12 @@ class FbClient implements FBAuthImpl {
|
||||
final _user = FirebaseUser(item, token.idToken);
|
||||
if (_user.uid == token.localId) {
|
||||
final _auth = AuthUser(
|
||||
displayName: _user?.displayName,
|
||||
email: _user?.email,
|
||||
isAnonymous: _user?.isAnonymous ?? true,
|
||||
isEmailVerified: _user?.isEmailVerified ?? false,
|
||||
displayName: _user.displayName,
|
||||
email: _user.email,
|
||||
isAnonymous: _user.isAnonymous ?? true,
|
||||
isEmailVerified: _user.isEmailVerified ?? false,
|
||||
photoUrl: _user.photoUrl,
|
||||
uid: _user?.uid,
|
||||
uid: _user.uid,
|
||||
);
|
||||
_onAuthChanged.add(_auth);
|
||||
return _auth;
|
||||
@@ -185,11 +182,9 @@ class FbClient implements FBAuthImpl {
|
||||
|
||||
Future<FirestoreJsonAccessToken> _loadToken() async {
|
||||
final _data = await onLoad();
|
||||
if (_data != null) {
|
||||
final token = FirestoreJsonAccessToken(_data, DateTime.now());
|
||||
return token;
|
||||
}
|
||||
return null;
|
||||
final token = FirestoreJsonAccessToken(_data, DateTime.now());
|
||||
return token;
|
||||
return null;
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
@@ -24,7 +24,7 @@ class FirebaseUser {
|
||||
}).toList();
|
||||
}
|
||||
|
||||
bool get isAnonymous => email == null || email.isEmpty;
|
||||
bool get isAnonymous => email.isEmpty;
|
||||
|
||||
bool get isEmailVerified => json['emailVerified'];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user