Skip to content

Commit

Permalink
Many changes, next to fix refresh token from stackoverflow example
Browse files Browse the repository at this point in the history
  • Loading branch information
wajeehulhassanvii committed May 2, 2020
1 parent b62b721 commit 6fef510
Show file tree
Hide file tree
Showing 82 changed files with 875 additions and 94,799 deletions.
4 changes: 2 additions & 2 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<application
android:name=".Application"
android:label="dodgecorona"
android:icon="@mipmap/ic_launcher">
android:icon="@mipmap/launcher_icon">
<activity
android:name=".MainActivity"
android:launchMode="singleTop"
Expand Down Expand Up @@ -51,4 +51,4 @@


</application>
</manifest>
</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.wajeehulhassan.dodgecorona

import io.flutter.embedding.android.FlutterActivity

class MainActivity: FlutterActivity() {
}
Binary file modified android/app/src/main/res/drawable/app_icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/dodgecorona_logo_simple.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/dodgecorona_logo_simple_curved.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/in_app_transparent_logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified ios/Runner/Assets.xcassets/AppIcon.appiconset/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified ios/Runner/Assets.xcassets/AppIcon.appiconset/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified ios/Runner/Assets.xcassets/AppIcon.appiconset/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified ios/Runner/Assets.xcassets/AppIcon.appiconset/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified ios/Runner/Assets.xcassets/AppIcon.appiconset/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified ios/Runner/Assets.xcassets/AppIcon.appiconset/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified ios/Runner/Assets.xcassets/AppIcon.appiconset/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified ios/Runner/Assets.xcassets/AppIcon.appiconset/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified ios/Runner/Assets.xcassets/AppIcon.appiconset/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified ios/Runner/Assets.xcassets/AppIcon.appiconset/[email protected]
Binary file modified ios/Runner/Assets.xcassets/AppIcon.appiconset/[email protected]
Binary file modified ios/Runner/Assets.xcassets/AppIcon.appiconset/[email protected]
Binary file modified ios/Runner/Assets.xcassets/AppIcon.appiconset/[email protected]
2 changes: 2 additions & 0 deletions lib/bloc/map/maps_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ class MapsBloc extends Bloc<MapsEvent, MapsState> {
Response response;
Map<String, dynamic> decodedJsonData;

// TODO change server to check if the users location is latest and within certain time
try {
response = await dio.post(
"/getuserswithindiameter",
Expand Down Expand Up @@ -177,6 +178,7 @@ class MapsBloc extends Bloc<MapsEvent, MapsState> {
}
}

// TODO again check if the interaction happened within certain time
if (listOfInteractedUsers.length > 0) {
dio.post(
'/interactedusers',
Expand Down
207 changes: 98 additions & 109 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import 'package:get/get.dart';
import 'package:get_it/get_it.dart';
import 'package:trackcorona/presentation/screens/about_page.dart';
import 'package:trackcorona/presentation/screens/account_settings_page.dart';
import 'package:trackcorona/presentation/screens/feedback_page.dart';
import 'package:trackcorona/presentation/screens/how_to_use_page.dart';
import 'package:trackcorona/presentation/screens/landing_page.dart';
import 'package:trackcorona/presentation/screens/login_page.dart';
Expand All @@ -22,160 +23,149 @@ void main() async {
// setupLocator is getIt instance
try {
WidgetsFlutterBinding.ensureInitialized();
setupLocator();
await setupLocator();
} catch (e) {
log(e);
}


runApp(MyApp());
}

class MyApp extends StatelessWidget {
// This widget is the root of your application.

@override
Widget build(BuildContext context){


return FutureBuilder(
future: _checkLogin(),
builder: (BuildContext context, AsyncSnapshot<bool> snapshot){
var user = snapshot.data; //
print("snapshot1"+snapshot.toString()); //
print("snapshot.data" + snapshot.data.runtimeType.toString());
print("snapshot.data" + snapshot.data.toString());// th
// islogin=true means jwt isn't revoked
if(GetPlatform.isWeb){

return MaterialApp(
navigatorKey: Get.key,
title: 'Flutter Demo',
Widget build(BuildContext context) {
if (GetPlatform.isWeb) {
return MaterialApp(
navigatorKey: Get.key,
title: 'Flutter Demo',
// initialRoute: '/map',
routes: {
routes: {
// '/': (context) => LandingPage(),
'/login': (context) => LoginPage(),
'/registration': (context) => RegistrationPage(),
'/map': (context) => MapPage(),
'/accountsettings': (context) => AccountSettingsPage(),
'/resetpage': (context) => ResetPasswordPage(),
'/aboutpage': (context) => AboutPage(),
'/howtousepage': (context) => HowToUsePage(),
},
theme: ThemeData(
primarySwatch: Colors.grey,
textTheme: TextTheme(),
),
home:LandingPage()
);
} else {
if (snapshot.data==true){
log('inside isLoggedIn true');
LoginPage.route: (context) => LoginPage(),
RegistrationPage.route: (context) => RegistrationPage(),
MapPage.route: (context) => MapPage(),
AccountSettingsPage.route: (context) => AccountSettingsPage(),
ResetPasswordPage.route: (context) => ResetPasswordPage(),
AboutPage.route: (context) => AboutPage(),
HowToUsePage.route: (context) => HowToUsePage(),
FeedbackPage.route: (context) => FeedbackPage(),
LandingPage.route: (context) => LandingPage(),
},
theme: ThemeData(
primarySwatch: Colors.grey,
textTheme: TextTheme(),
),
home: LandingPage());
} else {

PushNotificationService pushNotificationService = PushNotificationService();
pushNotificationService.initialise();

return FutureBuilder(
future: _checkLogin(),
builder: (BuildContext context, AsyncSnapshot<bool> snapshot) {
var user = snapshot.data; //
print(snapshot); //
print(snapshot.data);// this is your user instance
/// is because there is user already logged
return MaterialApp(
navigatorKey: Get.key,
title: 'Flutter Demo',
print("snapshot1" + snapshot.toString()); //
print("snapshot.data" + snapshot.data.runtimeType.toString());
print("snapshot.data" + snapshot.data.toString()); // th
// islogin=true means jwt isn't revoked

if (snapshot.data == true) {
log('inside isLoggedIn true');
var user = snapshot.data; //
print(snapshot); //
print(snapshot.data); // this is your user instance
/// is because there is user already logged
return MaterialApp(
navigatorKey: Get.key,
title: 'Flutter Demo',
// initialRoute: '/map',
routes: {
// '/': (context) => LandingPage(),
'/login': (context) => LoginPage(),
'/registration': (context) => RegistrationPage(),
'/map': (context) => MapPage(),
'/accountsettings': (context) => AccountSettingsPage(),
'/resetpage': (context) => ResetPasswordPage(),
'/aboutpage': (context) => AboutPage(),
'/howtousepage': (context) => HowToUsePage(),
},
theme: ThemeData(
primarySwatch: Colors.grey,
textTheme: TextTheme(),
),
home:MapPage()
);

} else {
/// other way there is no user logged.
return MaterialApp(
navigatorKey: Get.key,
title: 'Flutter Demo',
routes: {
LoginPage.route: (context) => LoginPage(),
RegistrationPage.route: (context) => RegistrationPage(),
MapPage.route: (context) => MapPage(),
AccountSettingsPage.route: (context) => AccountSettingsPage(),
ResetPasswordPage.route: (context) => ResetPasswordPage(),
AboutPage.route: (context) => AboutPage(),
HowToUsePage.route: (context) => HowToUsePage(),
FeedbackPage.route: (context) => FeedbackPage(),
LandingPage.route: (context) => LandingPage(),
},
theme: ThemeData(
primarySwatch: Colors.grey,
textTheme: TextTheme(),
),
home: MapPage());
} else {
/// other way there is no user logged.
return MaterialApp(
navigatorKey: Get.key,
title: 'Flutter Demo',
// initialRoute: '/login',
routes: {
// '/': (context) => LandingPage(),
'/login': (context) => LoginPage(),
'/registration': (context) => RegistrationPage(),
'/map': (context) => MapPage(),
'/accountsettings': (context) => AccountSettingsPage(),
'/resetpage': (context) => ResetPasswordPage(),
'/aboutpage': (context) => AboutPage(),
'/howtousepage': (context) => HowToUsePage(),
},
theme: ThemeData(
primarySwatch: Colors.grey,
textTheme: TextTheme(),
),
home:LoginPage()
);

}
} // else if not web

}
);
routes: {
LoginPage.route: (context) => LoginPage(),
RegistrationPage.route: (context) => RegistrationPage(),
MapPage.route: (context) => MapPage(),
AccountSettingsPage.route: (context) => AccountSettingsPage(),
ResetPasswordPage.route: (context) => ResetPasswordPage(),
AboutPage.route: (context) => AboutPage(),
HowToUsePage.route: (context) => HowToUsePage(),
FeedbackPage.route: (context) => FeedbackPage(),
LandingPage.route: (context) => LandingPage(),
},
theme: ThemeData(
primarySwatch: Colors.grey,
textTheme: TextTheme(),
),
home: LoginPage());
}
});
}
}

Future<bool> _checkLogin() async {

Future<bool> _checkLogin() async{
getIt = GetIt.instance;
SharedPreferencesManager sharedPreferenceManager =
await SharedPreferencesManager.getInstance();


PushNotificationService pushNotificationService=PushNotificationService();
pushNotificationService.initialise();
SharedPreferencesManager sharedPreferenceManager= getIt<SharedPreferencesManager>();

var isLoggedIn = false;
String storedAccessToken;

try{
try {
storedAccessToken = sharedPreferenceManager.getString('access_token');
if (storedAccessToken == null){
return isLoggedIn;
if (storedAccessToken == null) {
log('storedAccessToken is null');
return isLoggedIn;
}
}catch(e){
} catch (e) {
log('no access token');
return isLoggedIn;

}

Response checkLoginResponse= Response();
Response checkLoginResponse = Response();

Dio dio = await ApiProvider().getDioHttpClient();
checkLoginResponse = await dio.get('/checklogin');

log('after >>>>>> checkLoginResponse = await dio.get(\'/checklogin\')');
Map<String, dynamic> decodedJsonData;

log('dio checklogin done');

//-----

try {

if (checkLoginResponse.statusCode == 200) {
log('yes logged in but better to check the content returned');
isLoggedIn=true;
isLoggedIn = true;
log('going to login screen');
}

decodedJsonData = jsonDecode(checkLoginResponse.toString());
bool isRevoked = decodedJsonData['is_jwt_revoked'];
log(isLoggedIn.toString());
if(isRevoked){
isLoggedIn=false;
if (isRevoked) {
isLoggedIn = false;
} else {
isLoggedIn=true;
isLoggedIn = true;
}
return isLoggedIn;
} catch (e) {
Expand All @@ -186,4 +176,3 @@ class MyApp extends StatelessWidget {
//-----
}
}

Loading

0 comments on commit 6fef510

Please sign in to comment.