Skip to content
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
wants to merge 5 commits into
base: trunk
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions packages/at_onboarding_flutter/example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ PODS:
- Flutter
- webview_flutter_wkwebview (0.0.1):
- Flutter
- FlutterMacOS

DEPENDENCIES:
- at_backupkey_flutter (from `.symlinks/plugins/at_backupkey_flutter/ios`)
Expand All @@ -91,7 +90,7 @@ DEPENDENCIES:
- share_plus (from `.symlinks/plugins/share_plus/ios`)
- shared_preferences_foundation (from `.symlinks/plugins/shared_preferences_foundation/darwin`)
- url_launcher_ios (from `.symlinks/plugins/url_launcher_ios/ios`)
- webview_flutter_wkwebview (from `.symlinks/plugins/webview_flutter_wkwebview/darwin`)
- webview_flutter_wkwebview (from `.symlinks/plugins/webview_flutter_wkwebview/ios`)

SPEC REPOS:
trunk:
Expand Down Expand Up @@ -135,7 +134,7 @@ EXTERNAL SOURCES:
url_launcher_ios:
:path: ".symlinks/plugins/url_launcher_ios/ios"
webview_flutter_wkwebview:
:path: ".symlinks/plugins/webview_flutter_wkwebview/darwin"
:path: ".symlinks/plugins/webview_flutter_wkwebview/ios"

SPEC CHECKSUMS:
at_backupkey_flutter: 2fc3d01138175e41bce8b574387a47544c53e01b
Expand All @@ -159,8 +158,8 @@ SPEC CHECKSUMS:
shared_preferences_foundation: fcdcbc04712aee1108ac7fda236f363274528f78
SwiftyGif: 6c3eafd0ce693cad58bb63d2b2fb9bacb8552780
url_launcher_ios: 5334b05cef931de560670eeae103fd3e431ac3fe
webview_flutter_wkwebview: 0982481e3d9c78fd5c6f62a002fcd24fc791f1e4
webview_flutter_wkwebview: 2a23822e9039b7b1bc52e5add778e5d89ad488d1

PODFILE CHECKSUM: 4e8f8b2be68aeea4c0d5beb6ff1e79fface1d048

COCOAPODS: 1.14.3
COCOAPODS: 1.15.2
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import path_provider_foundation
import share_plus
import shared_preferences_foundation
import url_launcher_macos
import webview_flutter_wkwebview

func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
FileSaverPlugin.register(with: registry.registrar(forPlugin: "FileSaverPlugin"))
Expand All @@ -26,5 +25,4 @@ func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
SharePlusMacosPlugin.register(with: registry.registrar(forPlugin: "SharePlusMacosPlugin"))
SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin"))
UrlLauncherPlugin.register(with: registry.registrar(forPlugin: "UrlLauncherPlugin"))
FLTWebViewFlutterPlugin.register(with: registry.registrar(forPlugin: "FLTWebViewFlutterPlugin"))
}
13 changes: 3 additions & 10 deletions packages/at_onboarding_flutter/example/macos/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ PODS:
- FlutterMacOS
- url_launcher_macos (0.0.1):
- FlutterMacOS
- webview_flutter_wkwebview (0.0.1):
- Flutter
- FlutterMacOS

DEPENDENCIES:
- at_file_saver (from `Flutter/ephemeral/.symlinks/plugins/at_file_saver/macos`)
Expand All @@ -35,7 +32,6 @@ DEPENDENCIES:
- share_plus (from `Flutter/ephemeral/.symlinks/plugins/share_plus/macos`)
- shared_preferences_foundation (from `Flutter/ephemeral/.symlinks/plugins/shared_preferences_foundation/darwin`)
- url_launcher_macos (from `Flutter/ephemeral/.symlinks/plugins/url_launcher_macos/macos`)
- webview_flutter_wkwebview (from `Flutter/ephemeral/.symlinks/plugins/webview_flutter_wkwebview/darwin`)

EXTERNAL SOURCES:
at_file_saver:
Expand All @@ -58,22 +54,19 @@ EXTERNAL SOURCES:
:path: Flutter/ephemeral/.symlinks/plugins/shared_preferences_foundation/darwin
url_launcher_macos:
:path: Flutter/ephemeral/.symlinks/plugins/url_launcher_macos/macos
webview_flutter_wkwebview:
:path: Flutter/ephemeral/.symlinks/plugins/webview_flutter_wkwebview/darwin

SPEC CHECKSUMS:
at_file_saver: 1fc6ed722f17c7a20ce79cce168d1100fcad4b95
biometric_storage: 43caa6e7ef00e8e19c074216e7e1786dacda9e76
device_info_plus: ce1b7762849d3ec103d0e0517299f2db7ad60720
file_selector_macos: 54fdab7caa3ac3fc43c9fac4d7d8d231277f8cf2
FlutterMacOS: 8f6f14fa908a6fb3fba0cd85dbd81ec4b251fb24
package_info_plus: fa739dd842b393193c5ca93c26798dff6e3d0e0c
package_info_plus: d2f71247aab4b6521434f887276093acc70d214c
path_provider_foundation: 2b6b4c569c0fb62ec74538f866245ac84301af46
share_plus: 36537c04ce0c3e3f5bd297ce4318b6d5ee5fd6cf
share_plus: a182a58e04e51647c0481aadabbc4de44b3a2bce
shared_preferences_foundation: fcdcbc04712aee1108ac7fda236f363274528f78
url_launcher_macos: 5f437abeda8c85500ceb03f5c1938a8c5a705399
webview_flutter_wkwebview: 0982481e3d9c78fd5c6f62a002fcd24fc791f1e4

PODFILE CHECKSUM: 353c8bcc5d5b0994e508d035b5431cfe18c1dea7

COCOAPODS: 1.14.3
COCOAPODS: 1.15.2
2 changes: 0 additions & 2 deletions packages/at_onboarding_flutter/example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ dev_dependencies:
flutter_lints: ^4.0.0
flutter_test:
sdk: flutter



# For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec
Expand Down
187 changes: 4 additions & 183 deletions packages/at_onboarding_flutter/lib/at_onboarding.dart
Original file line number Diff line number Diff line change
@@ -1,184 +1,5 @@
import 'dart:io';
library at_onboarding_legacy;

Copy link
Member Author

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

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 packages/at_onboarding_flutter/lib/at_onboarding_flutter.dart
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 packages/at_onboarding_flutter/lib/at_onboarding_result.dart
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;

Copy link
Member Author

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_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';
Loading
Loading