Skip to content

Commit

Permalink
🐛 fix ambigous statement
Browse files Browse the repository at this point in the history
  • Loading branch information
Antoinegtir committed Jul 16, 2023
1 parent 34944a8 commit 5bb492c
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 20 deletions.
1 change: 0 additions & 1 deletion client/lib/common/settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,6 @@ class _SettingsPageState extends State<SettingsPage> {
onTap: () {
state.logoutCallback();
Navigator.pop(context);
Navigator.pop(context);
},
child: ClipRRect(
borderRadius: BorderRadius.circular(10),
Expand Down
20 changes: 14 additions & 6 deletions client/lib/common/splash.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:threads/auth/signup/name.dart';
import 'package:threads/helper/enum.dart';
import 'package:threads/state/auth.state.dart';
import 'package:threads/pages/home.dart';
import 'package:threads/state/auth.state.dart';

class SplashPage extends StatefulWidget {
const SplashPage({super.key});
const SplashPage({Key? key}) : super(key: key);

@override
State<SplashPage> createState() => _SplashPageState();
_SplashPageState createState() => _SplashPageState();
}

class _SplashPageState extends State<SplashPage> {
Expand All @@ -23,6 +23,8 @@ class _SplashPageState extends State<SplashPage> {

bool isAppUpdated = true;

/// Check if current app is updated app or not
/// If app is not updated then redirect user to update app screen
void timer() async {
if (isAppUpdated) {
Future.delayed(const Duration(seconds: 1)).then((_) {
Expand All @@ -32,14 +34,20 @@ class _SplashPageState extends State<SplashPage> {
}
}

Widget _body() {
return Container();
}

@override
Widget build(BuildContext context) {
var state = Provider.of<AuthState>(context);
return Scaffold(
backgroundColor: Colors.black,
body: state.authStatus == AuthStatus.NOT_LOGGED_IN
? const NamePage()
: HomePage(),
body: state.authStatus == AuthStatus.NOT_DETERMINED
? _body()
: state.authStatus == AuthStatus.NOT_LOGGED_IN
? const NamePage()
: const HomePage(),
);
}
}
10 changes: 9 additions & 1 deletion client/lib/state/app.state.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
import 'package:flutter/material.dart';

class AppStates extends ChangeNotifier {
notifyListeners();
bool _isBusy = false;
bool get isbusy => _isBusy;

set isBusy(bool value) {
if (value != _isBusy) {
_isBusy = value;
notifyListeners();
}
}
}
58 changes: 46 additions & 12 deletions client/lib/state/auth.state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import 'package:threads/helper/shared_prefrence_helper.dart';
import 'package:threads/helper/utility.dart';
import 'package:threads/model/user.module.dart';
import 'package:threads/state/app.state.dart';
import '../common/locator.dart';
import 'package:threads/common/locator.dart';
import 'package:path/path.dart' as path;

class AuthState extends AppStates {
Expand All @@ -35,9 +35,6 @@ class AuthState extends AppStates {
user = null;
_profileQuery!.onValue.drain();
_profileQuery = null;
if (isSignInWithGoogle) {
isSignInWithGoogle = false;
}
_firebaseAuth.signOut();
notifyListeners();
await getIt<SharedPreferenceHelper>().clearPreferenceValues();
Expand All @@ -47,17 +44,43 @@ class AuthState extends AppStates {
try {
if (_profileQuery == null) {
_profileQuery = kDatabase.child("profile").child(user!.uid);
_profileQuery!.onValue.listen(_onProfileChanged);
_profileQuery!.onChildChanged.listen(_onProfileUpdated);
}
} catch (error) {}
}

Future<String?> signIn(String email, String password, BuildContext context,
{required GlobalKey<ScaffoldState> scaffoldKey}) async {
try {
isBusy = true;
var result = await _firebaseAuth.signInWithEmailAndPassword(
email: email, password: password);
user = result.user;
userId = user!.uid;
return user!.uid;
} on FirebaseException catch (error) {
if (error.code == 'Email Adress Not found') {
Utility.customSnackBar(scaffoldKey, 'User not found', context);
} else {
Utility.customSnackBar(
scaffoldKey, error.message ?? 'Something went wrong', context);
}
return null;
} catch (error) {
print(error);
Utility.customSnackBar(scaffoldKey, error.toString(), context);

return null;
} finally {
isBusy = false;
}
}

Future<String?> signUp(UserModel userModel, BuildContext context,
{required GlobalKey<ScaffoldState> scaffoldKey,
required String password}) async {
try {
isBusy = true;
var result = await _firebaseAuth.createUserWithEmailAndPassword(
email: userModel.email!,
password: password,
Expand All @@ -76,6 +99,7 @@ class AuthState extends AppStates {
createUser(_userModel!, newUser: true);
return user!.uid;
} catch (error) {
isBusy = false;
Utility.customSnackBar(scaffoldKey, error.toString(), context);
return null;
}
Expand All @@ -86,16 +110,16 @@ class AuthState extends AppStates {
user.userName =
Utility.getUserName(id: user.userId!, name: user.displayName!);
kAnalytics.logEvent(name: 'create_newUser');

user.createAt = DateTime.now().toUtc().toString();
}

kDatabase.child('profile').child(user.userId!).set(user.toJson());
_userModel = user;
isBusy = false;
}

Future<User?> getCurrentUser() async {
try {
isBusy = true;
user = _firebaseAuth.currentUser;
if (user != null) {
await getProfileUser();
Expand All @@ -104,8 +128,10 @@ class AuthState extends AppStates {
} else {
authStatus = AuthStatus.NOT_LOGGED_IN;
}
isBusy = false;
return user;
} catch (error) {
isBusy = false;
authStatus = AuthStatus.NOT_LOGGED_IN;
return null;
}
Expand All @@ -131,15 +157,12 @@ class AuthState extends AppStates {
createUser(_userModel!);
}
}
} catch (error) {
print(error);
}
} catch (error) {}
}

Future<String> _uploadFileToStorage(File file, path) async {
var task = _firebaseStorage.ref().child(path);
var status = await task.putFile(file);
print(status.state.name);

return await task.getDownloadURL();
}
Expand Down Expand Up @@ -177,9 +200,20 @@ class AuthState extends AppStates {
}
}
}
isBusy = false;
});
} catch (error) {
print(error);
isBusy = false;
}
}

void _onProfileChanged(DatabaseEvent event) {
final val = event.snapshot.value;
if (val is Map) {
final updatedUser = UserModel.fromJson(val);
_userModel = updatedUser;
getIt<SharedPreferenceHelper>().saveUserProfile(_userModel!);
notifyListeners();
}
}

Expand Down

0 comments on commit 5bb492c

Please sign in to comment.