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 11 commits into
base: trunk
Choose a base branch
from
Draft
11 changes: 11 additions & 0 deletions packages/at_onboarding_flutter/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
## 6.1.10

- **FEAT** Language support added for:
- Spanish (Latin America)
- Portuguese
- Brazilian Portuguese
- Mandarin
- Cantonese

## 6.1.9

- build[deps]: Upgraded dependencies for the following packages:
- at_client: 3.2.2
- at_client_mobile: 3.2.19
- at_auth: 2.0.7
- at_commons: 5.0.0
- at_utils: 3.0.19

## 6.1.8

- **CHORE**: Updated dependencies
Expand Down
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
37 changes: 28 additions & 9 deletions packages/at_onboarding_flutter/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@ class MyAppState extends State<MyApp> {

bool isChangeLanguage = false;
var _currentLocale = const Locale('en', '');
final frenchLocale = const Locale('fr');
final englishLocale = const Locale('en');
final spanishLocale = const Locale('es');
final portugueseLocale = const Locale('pt');
final brazillianPortugueseLocale = const Locale('pt', 'BR');
final chineseTraditionalLocale = const Locale.fromSubtags(languageCode: 'zh', scriptCode: 'Hant', countryCode: 'HK');
final chineseSimplifiedLocale = const Locale.fromSubtags(languageCode: 'zh', scriptCode: 'Hans', countryCode: 'CN');

@override
Widget build(BuildContext context) {
Expand Down Expand Up @@ -67,9 +74,14 @@ class MyAppState extends State<MyApp> {
GlobalWidgetsLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
],
supportedLocales: const [
Locale('fr'),
Locale('en'),
supportedLocales: [
englishLocale,
frenchLocale,
spanishLocale,
portugueseLocale,
brazillianPortugueseLocale,
chineseTraditionalLocale,
chineseSimplifiedLocale,
],
themeMode: themeMode,
home: Scaffold(
Expand Down Expand Up @@ -177,16 +189,23 @@ class MyAppState extends State<MyApp> {
children: <Widget>[
const Text("Change language:"),
const SizedBox(width: 10),
DropdownButton(
DropdownButton<Locale>(
onChanged: (value) {
setState(() {
value == 'en' ? _currentLocale = const Locale('en') : _currentLocale = const Locale('fr');
_currentLocale = value!;
});
},
value: _currentLocale.languageCode,
items: const [
DropdownMenuItem(value: 'en', child: Text('English')),
DropdownMenuItem(value: 'fr', child: Text('French')),
value: _currentLocale,
items: [
DropdownMenuItem(value: englishLocale, child: const Text('English')),
DropdownMenuItem(value: frenchLocale, child: const Text('French')),
DropdownMenuItem(value: spanishLocale, child: const Text('Spanish')),
DropdownMenuItem(value: portugueseLocale, child: const Text('Portuguese')),
DropdownMenuItem(
value: brazillianPortugueseLocale, child: const Text('Brazilian Portuguese')),
DropdownMenuItem(
value: chineseTraditionalLocale, child: const Text('Chinese (Traditional)')),
DropdownMenuItem(value: chineseSimplifiedLocale, child: const Text('Chinese (Simplified)')),
],
)
],
Expand Down
8 changes: 4 additions & 4 deletions packages/at_onboarding_flutter/example/macos/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,13 @@ SPEC CHECKSUMS:
at_file_saver: 1fc6ed722f17c7a20ce79cce168d1100fcad4b95
biometric_storage: 43caa6e7ef00e8e19c074216e7e1786dacda9e76
device_info_plus: ce1b7762849d3ec103d0e0517299f2db7ad60720
file_selector_macos: 54fdab7caa3ac3fc43c9fac4d7d8d231277f8cf2
file_selector_macos: cc3858c981fe6889f364731200d6232dac1d812d
FlutterMacOS: 8f6f14fa908a6fb3fba0cd85dbd81ec4b251fb24
package_info_plus: fa739dd842b393193c5ca93c26798dff6e3d0e0c
package_info_plus: 12f1c5c2cfe8727ca46cbd0b26677728972d9a5b
path_provider_foundation: 2b6b4c569c0fb62ec74538f866245ac84301af46
share_plus: 36537c04ce0c3e3f5bd297ce4318b6d5ee5fd6cf
share_plus: 1fa619de8392a4398bfaf176d441853922614e89
shared_preferences_foundation: fcdcbc04712aee1108ac7fda236f363274528f78
url_launcher_macos: 5f437abeda8c85500ceb03f5c1938a8c5a705399
url_launcher_macos: c82c93949963e55b228a30115bd219499a6fe404
webview_flutter_wkwebview: 0982481e3d9c78fd5c6f62a002fcd24fc791f1e4

PODFILE CHECKSUM: 353c8bcc5d5b0994e508d035b5431cfe18c1dea7
Expand Down
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';
16 changes: 10 additions & 6 deletions packages/at_onboarding_flutter/lib/at_onboarding_flutter.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
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';
export './localizations/generated/l10n.dart';
export './services/at_onboarding_theme.dart';

// Additional customizations
export 'generated/l10n.dart';
// Core package requirements
export 'src/at_onboarding.dart';
export 'src/at_onboarding_result.dart';
export 'src/services/at_onboarding_config.dart';
export 'src/services/at_onboarding_theme.dart';
export 'src/utils/at_onboarding_app_constants.dart' show RootEnvironment;
Loading
Loading