Last active
September 21, 2018 01:44
-
-
Save raveesh-me/bd8a3546c2b53d82c01806913c939ae1 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import 'dart:async'; | |
import 'dart:core'; | |
import 'package:flutter_ritetag/model/client.dart'; | |
import 'package:flutter_ritetag/network/network_calls.dart'; | |
import 'package:meta/meta.dart'; | |
import 'package:shared_preferences/shared_preferences.dart'; | |
import 'user_info.dart'; | |
enum AppLoginState { | |
loggedOut, | |
loggedInTrialActive, | |
loggedInTrialExpired, | |
loggedInProExpired, | |
loggedInProActive, | |
loginSkipped | |
} | |
enum ProWidgetState { trial, pro } | |
class ManagedUserInfo { | |
/*Use [AppLoginState] whenever making recommendations for Login/Login Pro and | |
*you need exact LoginState*/ | |
AppLoginState appLoginState; | |
/*Use [proWidgetState] to decide whether to act as a TrailWidget or as a ProWidget*/ | |
ProWidgetState get proWidgetState => | |
appLoginState == AppLoginState.loggedInProActive || | |
appLoginState == AppLoginState.loggedInTrialActive | |
? ProWidgetState.pro | |
: ProWidgetState.trial; | |
//All the user info | |
UserInfo userInfo; | |
/*Whenever app starts, we begin with a null instance. | |
* We use this null check to initiate the async factory inside | |
* UserInfoManager*/ | |
ManagedUserInfo.nullInstance(); | |
ManagedUserInfo( | |
{@required this.userInfo, | |
@required this.appLoginState, | |
@required this.daysToExpire}); | |
//This is an async factory pattern | |
static Future<ManagedUserInfo> getCurrentState() async { | |
/*...some asynchronous logic for decing the loginState, fetching UserInfo and stuff....*/ | |
return ManagedUserInfo( | |
appLoginState: _tUserInfo.plans.ritetagPlan.isTrial | |
? _tUserInfo.plans.ritetagPlan.isActive | |
? AppLoginState.loggedInTrialActive | |
: AppLoginState.loggedInTrialExpired | |
: _tUserInfo.plans.ritetagPlan.isActive | |
? AppLoginState.loggedInProActive | |
: AppLoginState.loggedInProExpired, | |
riteKey: _tRiteKey, | |
userInfo: _tUserInfo, | |
//QuickDoc: 2018.difference(1945) will return a positive duration | |
daysToExpire: DateTime | |
.now() | |
.difference(_tUserInfo.plans.ritetagPlan.expiration) | |
.inDays, | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment