-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add syncing page after login/register
- Loading branch information
1 parent
550a824
commit 5df591a
Showing
38 changed files
with
998 additions
and
137 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
1.9.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import 'package:dio/dio.dart'; | ||
import 'package:firebase_auth/firebase_auth.dart'; | ||
|
||
/* Base dio HTTP client */ | ||
class HttpClient { | ||
/* Dio Client singleton instance */ | ||
static final HttpClient _singleton = HttpClient._internal(); | ||
|
||
factory HttpClient() { | ||
return _singleton; | ||
} | ||
|
||
HttpClient._internal(); | ||
|
||
/* Get getter for singleton instance */ | ||
Dio get instance => _createDioInstance(); | ||
|
||
Dio _createDioInstance() { | ||
final dio = Dio( | ||
BaseOptions( | ||
baseUrl: 'https://fitnesse-backend.onrender.com/v1', | ||
), | ||
); | ||
|
||
/* Add interceptor to auto-add access token to HTTP requests */ | ||
dio.interceptors.add(InterceptorsWrapper( | ||
onRequest: (options, handler) async { | ||
/* Attach firebase id token to `authorization` header */ | ||
String? token = await _getFirebaseIdToken(); | ||
if (token != null) { | ||
options.headers['authorization'] = 'Bearer $token'; | ||
} | ||
return handler.next(options); | ||
}, | ||
onResponse: (response, handler) { | ||
/* Handle responses */ | ||
return handler.next(response); | ||
}, | ||
onError: (DioException e, handler) { | ||
/* Handle errors */ | ||
return handler.next(e); | ||
}, | ||
)); | ||
|
||
return dio; | ||
} | ||
|
||
/* Get the firebase id token from the current user */ | ||
Future<String?> _getFirebaseIdToken() async { | ||
final user = FirebaseAuth.instance.currentUser; | ||
if (user != null) { | ||
final token = await user.getIdToken(); | ||
return token; | ||
} | ||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* Data model for a user */ | ||
|
||
/* Sex enum matching backend */ | ||
import 'package:realm/realm.dart'; | ||
|
||
part 'user.g.dart'; | ||
|
||
enum Sex { male, female } | ||
|
||
/* Activity level enum matching backend */ | ||
enum ActivityLevel { | ||
sedentary, | ||
lightlyActive, | ||
moderatelyActive, | ||
veryActive, | ||
extremelyActive | ||
} | ||
|
||
/* Weight goal enum matching backend */ | ||
enum WeightGoal { | ||
fastLoss, | ||
moderateLoss, | ||
slowLoss, | ||
maintain, | ||
slowGain, | ||
moderateGain, | ||
fastGain | ||
} | ||
|
||
/* Convert enums to int for storage */ | ||
int _enumToInt(dynamic enumValue) => enumValue.index; | ||
|
||
/* Data model for a user */ | ||
@RealmModel() | ||
class _User { | ||
@PrimaryKey() | ||
late String _id; | ||
late DateTime birthday; | ||
@MapTo('sex') | ||
late int sexIndex; | ||
late int height; | ||
late int weight; | ||
@MapTo('activityLevel') | ||
late int activityLevelIndex; | ||
@MapTo('weightGoal') | ||
late int weightGoalIndex; | ||
late bool useMetric; | ||
late _Goals? goals; | ||
late DateTime createdAt; | ||
late DateTime updatedAt; | ||
|
||
/* Create getters and setters for enum fields */ | ||
Sex get sex => Sex.values[sexIndex]; | ||
set sex(Sex value) => sexIndex = _enumToInt(value); | ||
|
||
ActivityLevel get activityLevel => ActivityLevel.values[activityLevelIndex]; | ||
set activityLevel(ActivityLevel value) => | ||
activityLevelIndex = _enumToInt(value); | ||
|
||
WeightGoal get weightGoal => WeightGoal.values[weightGoalIndex]; | ||
set weightGoal(WeightGoal value) => weightGoalIndex = _enumToInt(value); | ||
} | ||
|
||
/* Data model for macro goals */ | ||
@RealmModel() | ||
class _Goals { | ||
late int calories; | ||
late int protein; | ||
late int fat; | ||
late int carbohydrates; | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.