-
Notifications
You must be signed in to change notification settings - Fork 32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore: separate atkey upload to a service in at_onboarding_flutter #939
Draft
XavierChanth
wants to merge
5
commits into
trunk
Choose a base branch
from
at_onboarding_flutter_layers
base: trunk
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
0c032ed
chore: mv internals to lib/src
XavierChanth cbed8c6
chore: update imports to include src in path
XavierChanth efed7eb
refactor: extract atkeys file upload service from home widget
XavierChanth 7ba3433
Merge branch 'trunk' into at_onboarding_flutter_layers
XavierChanth b400685
fix: bugs
XavierChanth File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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 |
---|---|---|
@@ -1,184 +1,5 @@ | ||
import 'dart:io'; | ||
library at_onboarding_legacy; | ||
|
||
import 'package:at_onboarding_flutter/at_onboarding_result.dart'; | ||
import 'package:at_onboarding_flutter/localizations/generated/l10n.dart'; | ||
import 'package:at_onboarding_flutter/screen/at_onboarding_activate_screen.dart'; | ||
import 'package:at_onboarding_flutter/screen/at_onboarding_intro_screen.dart'; | ||
import 'package:at_onboarding_flutter/screen/at_onboarding_reset_screen.dart'; | ||
import 'package:at_onboarding_flutter/screen/at_onboarding_start_screen.dart'; | ||
import 'package:at_onboarding_flutter/services/at_onboarding_config.dart'; | ||
import 'package:at_onboarding_flutter/services/at_onboarding_theme.dart'; | ||
import 'package:at_onboarding_flutter/services/onboarding_service.dart'; | ||
import 'package:at_onboarding_flutter/utils/at_onboarding_app_constants.dart'; | ||
import 'package:flutter/material.dart'; | ||
|
||
class AtOnboarding { | ||
/// Using this function to get onboard atsing. | ||
/// | ||
/// @param context The build context. | ||
/// @param config The config for the onboard | ||
/// @param isSwitchingAtsign True - alway show UI for add new atsign. False - check onboard if existing atsing. Default is false | ||
/// @param atsign The atsign name when change the primary atsign. | ||
/// | ||
/// Return [AtOnboardingResult] | ||
static Future<AtOnboardingResult> onboard({ | ||
required BuildContext context, | ||
required AtOnboardingConfig config, | ||
bool isSwitchingAtsign = false, | ||
String? atsign, | ||
}) async { | ||
AtOnboardingConstants.setApiKey(config.appAPIKey ?? | ||
(AtOnboardingConstants.rootEnvironment.apikey ?? '')); | ||
AtOnboardingConstants.rootDomain = | ||
config.domain ?? AtOnboardingConstants.rootEnvironment.domain; | ||
|
||
/// Initial Setup | ||
await _initialSetup(context); | ||
|
||
/// user sharing is not supported on Android, iOS and Linux. | ||
if (Platform.isAndroid || Platform.isIOS || Platform.isLinux) { | ||
config.showPopupSharedStorage = false; | ||
} | ||
|
||
if (config.theme == null) { | ||
final defaultConfig = config.copyWith( | ||
theme: AtOnboardingTheme(), | ||
); | ||
config = defaultConfig; | ||
} | ||
|
||
if (!isSwitchingAtsign || (atsign ?? '').trim().isNotEmpty) { | ||
if ((atsign ?? '').trim().isNotEmpty) { | ||
await changePrimaryAtsign(atsign: atsign!); | ||
} | ||
|
||
//Check if existing an atsign => return onboard success | ||
// ignore: use_build_context_synchronously | ||
AtOnboardingResult? result; | ||
if (context.mounted) { | ||
result = await showDialog( | ||
context: context, | ||
barrierDismissible: false, | ||
builder: (_) => AtOnboardingStartScreen( | ||
config: config, | ||
), | ||
); | ||
} | ||
|
||
if (result is AtOnboardingResult) { | ||
return result; | ||
} | ||
|
||
return AtOnboardingResult.cancelled(); | ||
} | ||
|
||
if (context.mounted) { | ||
final result = await Navigator.push( | ||
context, | ||
MaterialPageRoute( | ||
builder: (BuildContext context) { | ||
return AtOnboardingIntroScreen( | ||
config: config, | ||
); | ||
}, | ||
), | ||
); | ||
|
||
if (result is AtOnboardingResult) { | ||
//Update primary atsign after onboard success | ||
if (result.status == AtOnboardingResultStatus.success && | ||
result.atsign != null) { | ||
await changePrimaryAtsign(atsign: result.atsign!); | ||
} | ||
return result; | ||
} | ||
} | ||
|
||
return AtOnboardingResult.cancelled(); | ||
} | ||
|
||
static Future<AtOnboardingResult> activateAccount({ | ||
required BuildContext context, | ||
required AtOnboardingConfig config, | ||
}) async { | ||
/// Initial Setup | ||
await _initialSetup(context); | ||
|
||
if (context.mounted) { | ||
final result = await Navigator.push( | ||
context, | ||
MaterialPageRoute( | ||
builder: (BuildContext context) { | ||
return AtOnboardingActivateScreen( | ||
hideReferences: false, | ||
config: config, | ||
); | ||
}, | ||
), | ||
); | ||
|
||
if (result is AtOnboardingResult) { | ||
return result; | ||
} | ||
} | ||
|
||
return AtOnboardingResult.cancelled(); | ||
} | ||
|
||
static Future<bool> changePrimaryAtsign({required String atsign}) async { | ||
return await OnboardingService.getInstance() | ||
.changePrimaryAtsign(atsign: atsign); | ||
} | ||
|
||
static Future<AtOnboardingResetResult> reset({ | ||
required BuildContext context, | ||
required AtOnboardingConfig config, | ||
}) async { | ||
/// Initial Setup | ||
await _initialSetup(context); | ||
|
||
if (context.mounted) { | ||
final result = await Navigator.push(context, | ||
MaterialPageRoute(builder: (BuildContext context) { | ||
return AtOnboardingResetScreen(config: config); | ||
})); | ||
|
||
if (result is AtOnboardingResetResult) { | ||
return result; | ||
} | ||
} | ||
|
||
return AtOnboardingResetResult.cancelled; | ||
} | ||
|
||
Future<bool> enableUsingSharedStorage() async { | ||
if (Platform.isAndroid || Platform.isIOS || Platform.isLinux) { | ||
throw UnsupportedError('user sharing not supported'); | ||
} | ||
|
||
final result = | ||
await OnboardingService.getInstance().enableUsingSharedStorage(); | ||
return result; | ||
} | ||
|
||
Future<bool> disableUsingSharedStorage() async { | ||
if (Platform.isAndroid || Platform.isIOS || Platform.isLinux) { | ||
throw UnsupportedError('user sharing not supported'); | ||
} | ||
|
||
final result = | ||
await OnboardingService.getInstance().disableUsingSharedStorage(); | ||
return result; | ||
} | ||
|
||
static Future<void> _initialSetup(BuildContext context) async { | ||
/// Configure Localization | ||
const AppLocalizationDelegate _delegate = AppLocalizationDelegate(); | ||
final currentLocal = Localizations.localeOf(context); | ||
if (_delegate.isSupported(currentLocal)) { | ||
_delegate.load(currentLocal); | ||
} else { | ||
_delegate.load(const Locale.fromSubtags(languageCode: 'en')); | ||
} | ||
} | ||
} | ||
@Deprecated( | ||
"This is a legacy export and will be removed in a future version: use at_onboarding_flutter.dart instead") | ||
export 'src/at_onboarding.dart'; |
15 changes: 10 additions & 5 deletions
15
packages/at_onboarding_flutter/lib/at_onboarding_flutter.dart
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 |
---|---|---|
@@ -1,10 +1,15 @@ | ||
library at_onboarding_flutter; | ||
|
||
export './utils/at_onboarding_app_constants.dart' show RootEnvironment; | ||
// Re-export some important external dependencies | ||
export 'package:at_backupkey_flutter/at_backupkey_flutter.dart'; | ||
export './at_onboarding.dart'; | ||
export 'services/at_onboarding_config.dart'; | ||
export 'at_onboarding_result.dart'; | ||
export 'package:at_client_mobile/at_client_mobile.dart'; | ||
|
||
// Core package requirements | ||
export 'src/at_onboarding.dart'; | ||
export 'src/at_onboarding_result.dart'; | ||
export 'src/utils/at_onboarding_app_constants.dart' show RootEnvironment; | ||
export 'src/services/at_onboarding_config.dart'; | ||
|
||
// Additional customizations | ||
export './localizations/generated/l10n.dart'; | ||
export './services/at_onboarding_theme.dart'; | ||
export 'src/services/at_onboarding_theme.dart'; |
76 changes: 4 additions & 72 deletions
76
packages/at_onboarding_flutter/lib/at_onboarding_result.dart
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 |
---|---|---|
@@ -1,73 +1,5 @@ | ||
/// The status of onboard's result | ||
/// | ||
/// Values include: success, error, cancel | ||
/// | ||
enum AtOnboardingResultStatus { | ||
success, //Authenticate success | ||
error, //Authenticate error | ||
cancel, //User canceled | ||
} | ||
library at_onboarding_result_legacy; | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. moved to src/at_onboarding_result |
||
enum AtOnboardingResetResult { | ||
cancelled, | ||
success, | ||
} | ||
|
||
/// The result returned after onboard | ||
class AtOnboardingResult { | ||
/// Status of result | ||
AtOnboardingResultStatus status; | ||
|
||
/// The message returned when onboard failed | ||
String? message; | ||
|
||
/// The error code returned when onboard failed | ||
String? errorCode; | ||
|
||
/// The atSign returned when onboard successfully | ||
String? atsign; | ||
|
||
AtOnboardingResult._({ | ||
required this.status, | ||
this.message, | ||
this.errorCode, | ||
this.atsign, | ||
}); | ||
|
||
/// Create instance with success status | ||
/// | ||
/// [atsign] The name of atSign | ||
/// | ||
factory AtOnboardingResult.success({ | ||
required String atsign, | ||
}) { | ||
return AtOnboardingResult._( | ||
status: AtOnboardingResultStatus.success, | ||
atsign: atsign, | ||
); | ||
} | ||
|
||
/// Create instance with error status | ||
/// | ||
/// [message] The message returned when onboard failed | ||
/// | ||
/// [errorCode] The error code returned when onboard failed | ||
/// | ||
factory AtOnboardingResult.error({ | ||
String? message, | ||
String? errorCode, | ||
}) { | ||
return AtOnboardingResult._( | ||
status: AtOnboardingResultStatus.error, | ||
message: message, | ||
errorCode: errorCode, | ||
); | ||
} | ||
|
||
/// Create instance with cancel status | ||
factory AtOnboardingResult.cancelled() { | ||
return AtOnboardingResult._( | ||
status: AtOnboardingResultStatus.cancel, | ||
); | ||
} | ||
} | ||
@Deprecated( | ||
"This is a legacy export and will be removed in a future version: use at_onboarding_flutter.dart instead") | ||
export 'src/at_onboarding_result.dart'; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
moved to src/at_onboarding.dart