Skip to content

Commit

Permalink
fix: GraphQL late initialisation Error
Browse files Browse the repository at this point in the history
  • Loading branch information
abhibhaw authored and nayakastha committed Nov 8, 2021
1 parent f2b31b6 commit 272caa1
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 33 deletions.
20 changes: 10 additions & 10 deletions aptiche/lib/services/net/authservice.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import 'package:aptiche/views/home/homescreen.dart';
import 'package:aptiche/views/login/logincontroller.dart';
import 'package:aptiche/views/login/loginscreen.dart';
import 'package:aptiche/views/splashscreen/splashscreen.dart';
import 'package:aptiche/widgets/snackbar.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
Expand Down Expand Up @@ -38,14 +37,16 @@ class AuthService extends GetxController {
smsCode: smsCode,
);
await FirebaseAuth.instance.signInWithCredential(authCredential);
await _graphQL.initGraphQL(await getUserToken());
print(await _graphQL.checkUserbyPhone(
phoneNo: FirebaseAuth.instance.currentUser!.phoneNumber));
/* if (await _graphQL.checkUserbyPhone(phoneNo: phoneNo.value) == 'null') {
await _graphQL.initGraphQL(getUserToken().toString());
// print(await _graphQL.checkUserbyPhone(
// phoneNo: FirebaseAuth.instance.currentUser!.phoneNumber));
if (await _graphQL.checkUserbyPhone(
phoneNo: FirebaseAuth.instance.currentUser!.phoneNumber) ==
'null') {
await Get.off<dynamic>(() => const DataEntryScreen());
} else {
await Get.off<dynamic>(() => const SplashScreen());
} */
}
} catch (error) {
print(error);
/* CustomLoaders().customSnackBar(
Expand All @@ -55,12 +56,11 @@ class AuthService extends GetxController {
}
}

Future<String?> getUserToken() async {
String getUserToken() {
if (FirebaseAuth.instance.currentUser != null) {
// ignore: unnecessary_await_in_return
return await FirebaseAuth.instance.currentUser!.getIdToken(true);
return FirebaseAuth.instance.currentUser!.getIdToken(true).toString();
} else {
return Future<String>.value('');
return '';
}
}
}
10 changes: 5 additions & 5 deletions aptiche/lib/utils/bindings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ import 'package:get/instance_manager.dart';
class HomeBinding implements Bindings {
@override
void dependencies() {
Get.put<RemoteConfigService>(RemoteConfigService());
Get.put<GraphQLService>(GraphQLService());
Get.put<AuthService>(AuthService());
Get.put<LoginController>(LoginController());
Get.put<ThirdPartyServices>(ThirdPartyServices());
Get.lazyPut(() => RemoteConfigService());
Get.lazyPut(() => GraphQLService());
Get.lazyPut(() => AuthService());
Get.lazyPut(() => LoginController());
Get.lazyPut(() => ThirdPartyServices());
Get.lazyPut<DataEntryController>(() => DataEntryController(), fenix: true);
Get.lazyPut<HomeController>(() => HomeController(), fenix: true);
Get.lazyPut<QuizController>(() => QuizController(), fenix: true);
Expand Down
2 changes: 1 addition & 1 deletion aptiche/lib/utils/query.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const String getUserbyPhone = r'''
name
rollNo
email
phoneNo
phoneNo
}
}
''';
Expand Down
6 changes: 3 additions & 3 deletions aptiche/lib/views/login/logincontroller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ class LoginController extends GetxController {
//await FirebaseAuth.instance.signInWithCredential(authResult);
CustomLoaders().customSnackBar('Authentication Successful',
'User Verified with mobile number $phoneNo');
print(await _graphQL.checkUserbyPhone(phoneNo: phoneNo.value));
/* if (await _graphQL.checkUserbyPhone(phoneNo: phoneNo.value) == 'null') {
// print(await _graphQL.checkUserbyPhone(phoneNo: phoneNo.value));
if (await _graphQL.checkUserbyPhone(phoneNo: phoneNo.value) == 'null') {
await Get.off<dynamic>(() => const DataEntryScreen());
} else {
await Get.off<dynamic>(() => const SplashScreen());
} */
}
};

final PhoneVerificationFailed verificationFailed =
Expand Down
19 changes: 13 additions & 6 deletions aptiche/lib/views/splashscreen/splashscreen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,18 @@ class SplashScreen extends StatefulWidget {

class _SplashScreenState extends State<SplashScreen>
with TickerProviderStateMixin {
final GraphQLService _graphQLService = Get.find();
final AuthService _authService = Get.find();
@override
void initState() {
super.initState();
final GraphQLService _graphQLService = Get.find();
final AuthService _authService = Get.find();
if (FirebaseAuth.instance.currentUser != null) {
final String token = _authService.getUserToken();
print(token);
_graphQLService.initGraphQL(token);
}
}

@override
Widget build(BuildContext context) {
Expand Down Expand Up @@ -51,11 +61,8 @@ class _SplashScreenState extends State<SplashScreen>
status == AnimationStatus.completed) {
await GetStorage().initStorage;
final Widget route = await _authService.handleAuth();
if (FirebaseAuth.instance.currentUser != null) {
await _graphQLService
.initGraphQL(await _authService.getUserToken());
}
await Get.to<dynamic>(

await Get.off<dynamic>(
() => route,
);
}
Expand Down
16 changes: 8 additions & 8 deletions aptiche/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ packages:
name: analyzer
url: "https://pub.dartlang.org"
source: hosted
version: "1.7.2"
version: "1.7.1"
archive:
dependency: transitive
description:
Expand All @@ -35,7 +35,7 @@ packages:
name: async
url: "https://pub.dartlang.org"
source: hosted
version: "2.8.1"
version: "2.6.1"
awesome_dropdown:
dependency: "direct main"
description:
Expand Down Expand Up @@ -63,7 +63,7 @@ packages:
name: charcode
url: "https://pub.dartlang.org"
source: hosted
version: "1.3.1"
version: "1.2.0"
cli_util:
dependency: transitive
description:
Expand Down Expand Up @@ -463,7 +463,7 @@ packages:
name: meta
url: "https://pub.dartlang.org"
source: hosted
version: "1.7.0"
version: "1.3.0"
nm:
dependency: transitive
description:
Expand Down Expand Up @@ -554,7 +554,7 @@ packages:
name: petitparser
url: "https://pub.dartlang.org"
source: hosted
version: "4.3.0"
version: "4.1.0"
platform:
dependency: transitive
description:
Expand Down Expand Up @@ -636,7 +636,7 @@ packages:
name: test_api
url: "https://pub.dartlang.org"
source: hosted
version: "0.4.2"
version: "0.3.0"
typed_data:
dependency: transitive
description:
Expand Down Expand Up @@ -734,7 +734,7 @@ packages:
name: xml
url: "https://pub.dartlang.org"
source: hosted
version: "5.3.0"
version: "5.1.2"
yaml:
dependency: transitive
description:
Expand All @@ -743,5 +743,5 @@ packages:
source: hosted
version: "3.1.0"
sdks:
dart: ">=2.14.0 <3.0.0"
dart: ">=2.13.0 <3.0.0"
flutter: ">=2.0.0"

0 comments on commit 272caa1

Please sign in to comment.