diff --git a/lib/buttons.dart b/lib/buttons.dart index 36a05c4..bd2cfe9 100644 --- a/lib/buttons.dart +++ b/lib/buttons.dart @@ -157,7 +157,7 @@ class AppShellDefaultButtons implements AppButtons { IconButton( onPressed: onPressed ?? () => Navigator.pop(context), icon: Icon( - context.appShell().config.appTheme.icons.backButton, + context.login().config.appTheme.icons.backButton, size: 24, ), ); diff --git a/lib/flutter_login_view.dart b/lib/flutter_login_view.dart index 217db89..f0abde8 100644 --- a/lib/flutter_login_view.dart +++ b/lib/flutter_login_view.dart @@ -59,9 +59,9 @@ class FlutterLogin extends InheritedWidget with FlutterLoginSdk { extension AppShellRetrieval on BuildContext { static LoginRepository? _cachedBackend; - FlutterLogin appShell() => FlutterLogin.of(this); - LoginRepository appShellBackend() { - _cachedBackend ??= appShell().repository; + FlutterLogin login() => FlutterLogin.of(this); + LoginRepository loginRepository() { + _cachedBackend ??= login().repository; return _cachedBackend!; } } @@ -90,7 +90,7 @@ extension AppShellTranslate on BuildContext { String translate(String key, {String? defaultValue, List arguments = const []}) { - dynamic translateFunction = appShell().config.translate; + dynamic translateFunction = login().config.translate; if (translateFunction == null) { return _getDefaultTranslation(key, arguments) ?? defaultValue ?? key; } @@ -112,7 +112,7 @@ class LoginMain extends StatelessWidget with NavigateWidgetMixin { Widget _login(context) { return Builder( builder: (context) { - if (context.appShell().users.isLoggedIn(context)) { + if (context.login().users.isLoggedIn(context)) { return child; } diff --git a/lib/plugins/dialog/alert_dialog.dart b/lib/plugins/dialog/alert_dialog.dart index 2ae1ccf..4f1b579 100644 --- a/lib/plugins/dialog/alert_dialog.dart +++ b/lib/plugins/dialog/alert_dialog.dart @@ -278,11 +278,8 @@ class AppShellAlertDialog extends StatelessWidget { mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: buttons.map( (e) { - var buttons = context - .appShell() - .config - .appTheme - .buttons; + var buttons = + context.login().config.appTheme.buttons; var child = Text( context.translate(e.text), ); @@ -319,7 +316,7 @@ class AppShellAlertDialog extends StatelessWidget { child: Align( alignment: Alignment.topRight, child: context - .appShell() + .login() .config .appTheme .buttons @@ -329,7 +326,7 @@ class AppShellAlertDialog extends StatelessWidget { Theme.of(context).textTheme.bodyText2!.color, icon: Icon( context - .appShell() + .login() .config .appTheme .icons diff --git a/lib/plugins/form/fields/obscure_text_input_field.dart b/lib/plugins/form/fields/obscure_text_input_field.dart index 7ee870b..6e2f9c6 100644 --- a/lib/plugins/form/fields/obscure_text_input_field.dart +++ b/lib/plugins/form/fields/obscure_text_input_field.dart @@ -28,7 +28,7 @@ class ObscureTextInputFieldState extends State { @override Widget build(BuildContext context) { - return context.appShell().config.appTheme.inputs.textField( + return context.login().config.appTheme.inputs.textField( onSubmitted: widget.onSubmitted, value: widget.value ?? '', decoration: InputDecoration( @@ -38,8 +38,8 @@ class ObscureTextInputFieldState extends State { }), icon: Icon( showText - ? context.appShell().config.appTheme.icons.passwordHidden - : context.appShell().config.appTheme.icons.passwordVisible, + ? context.login().config.appTheme.icons.passwordHidden + : context.login().config.appTheme.icons.passwordVisible, color: Theme.of(context) .inputDecorationTheme .border diff --git a/lib/plugins/form/inputs/dialog_picker.dart b/lib/plugins/form/inputs/dialog_picker.dart index c624b6a..7c780d3 100644 --- a/lib/plugins/form/inputs/dialog_picker.dart +++ b/lib/plugins/form/inputs/dialog_picker.dart @@ -76,7 +76,7 @@ class DialogPickerInputState extends InputState { showCursor: false, readOnly: true, decoration: InputDecoration( - suffixIcon: context.appShell().config.appTheme.buttons.iconButton( + suffixIcon: context.login().config.appTheme.buttons.iconButton( context: context, onPressed: () async { var result = await onPick.call(context, value); @@ -87,7 +87,7 @@ class DialogPickerInputState extends InputState { }); }, icon: Icon( - context.appShell().config.appTheme.icons.dateTimePicker, + context.login().config.appTheme.icons.dateTimePicker, size: 30, color: Theme.of(context).colorScheme.secondary, ), diff --git a/lib/plugins/form/inputs/radio.dart b/lib/plugins/form/inputs/radio.dart index 34d789f..8f3ab54 100644 --- a/lib/plugins/form/inputs/radio.dart +++ b/lib/plugins/form/inputs/radio.dart @@ -72,7 +72,7 @@ class RadioState extends InputState { ), child: Builder( builder: (context) { - return context.appShell().config.appTheme.buttons.secondaryButton( + return context.login().config.appTheme.buttons.secondaryButton( context: context, child: Text( label, diff --git a/lib/plugins/login/email_password_form.dart b/lib/plugins/login/email_password_form.dart index 08e5b81..3708469 100644 --- a/lib/plugins/login/email_password_form.dart +++ b/lib/plugins/login/email_password_form.dart @@ -38,8 +38,8 @@ class _EmailPasswordFormState extends State { @override Widget build(BuildContext context) { - var shellInputs = context.appShell().config.appTheme.inputs; - var buttons = context.appShell().config.appTheme.buttons; + var shellInputs = context.login().config.appTheme.inputs; + var buttons = context.login().config.appTheme.buttons; var textTheme = Theme.of(context).textTheme; return Column( children: [ diff --git a/lib/plugins/login/forgot_password.dart b/lib/plugins/login/forgot_password.dart index 2dcca8b..59ce69b 100644 --- a/lib/plugins/login/forgot_password.dart +++ b/lib/plugins/login/forgot_password.dart @@ -18,10 +18,10 @@ class _ForgotPasswordState extends State @override Widget build(BuildContext context) => Material( child: Scaffold( - body: context.appShell().screens.getAppshellScreenWrapper( + body: context.login().screens.getAppshellScreenWrapper( context, backgroundImg: - context.appShell().config.loginOptions.backgroundImage, + context.login().config.loginOptions.backgroundImage, child: Column( children: [ Expanded( @@ -34,7 +34,7 @@ class _ForgotPasswordState extends State left: 5, ), child: context - .appShell() + .login() .config .appTheme .buttons @@ -72,7 +72,7 @@ class _ForgotPasswordState extends State padding: EdgeInsets.only(bottom: 20), ), context - .appShell() + .login() .config .appTheme .inputs @@ -120,7 +120,7 @@ class _ForgotPasswordState extends State margin: const EdgeInsets.symmetric(horizontal: 30), padding: const EdgeInsets.only(bottom: 40.0), child: context - .appShell() + .login() .config .appTheme .buttons @@ -138,11 +138,11 @@ class _ForgotPasswordState extends State }); var result = await context - .appShellBackend() + .loginRepository() .forgotPassword(email!); if (result) { - await context.appShell().dialogs.showDialog( + await context.login().dialogs.showDialog( context: context, builder: (ctx) => AppShellAlertDialog .singleButtonIcon( @@ -154,7 +154,7 @@ class _ForgotPasswordState extends State ), icon: Icon( context - .appShell() + .login() .config .appTheme .icons @@ -166,7 +166,7 @@ class _ForgotPasswordState extends State onPressed: () { Navigator.of(ctx).pop(); context - .appShell() + .login() .screens .openLoginScreen(context); }, diff --git a/lib/plugins/login/forgot_password_form.dart b/lib/plugins/login/forgot_password_form.dart index 155ce63..90468df 100644 --- a/lib/plugins/login/forgot_password_form.dart +++ b/lib/plugins/login/forgot_password_form.dart @@ -27,10 +27,10 @@ class _ForgotPasswordFormState extends State Widget build(BuildContext context) { return Material( child: Scaffold( - body: context.appShell().screens.getAppshellScreenWrapper( + body: context.login().screens.getAppshellScreenWrapper( context, backgroundImg: - context.appShell().config.loginOptions.backgroundImage, + context.login().config.loginOptions.backgroundImage, child: Column( children: [ Expanded( @@ -40,7 +40,7 @@ class _ForgotPasswordFormState extends State alignment: Alignment.topLeft, padding: const EdgeInsets.only(top: 27, left: 5), child: context - .appShell() + .login() .config .appTheme .buttons @@ -76,12 +76,7 @@ class _ForgotPasswordFormState extends State const Padding( padding: EdgeInsets.only(bottom: 20), ), - context - .appShell() - .config - .appTheme - .inputs - .textField( + context.login().config.appTheme.inputs.textField( title: context.translate( 'forgot_password.input.email', ), @@ -127,7 +122,7 @@ class _ForgotPasswordFormState extends State margin: const EdgeInsets.symmetric(horizontal: 30), padding: const EdgeInsets.only(bottom: 40.0), child: context - .appShell() + .login() .config .appTheme .buttons @@ -144,11 +139,11 @@ class _ForgotPasswordFormState extends State }); var result = await context - .appShellBackend() + .loginRepository() .forgotPassword(email!); if (result) { - await context.appShell().dialogs.showDialog( + await context.login().dialogs.showDialog( context: context, builder: (ctx) => AppShellAlertDialog.singleButtonIcon( @@ -160,7 +155,7 @@ class _ForgotPasswordFormState extends State ), icon: Icon( context - .appShell() + .login() .config .appTheme .icons diff --git a/lib/plugins/login/login_await_email.dart b/lib/plugins/login/login_await_email.dart index 5e73187..05a4140 100644 --- a/lib/plugins/login/login_await_email.dart +++ b/lib/plugins/login/login_await_email.dart @@ -22,17 +22,17 @@ class _LoginAwaitEmailScreenState extends State with NavigateWidgetMixin { @override void initState() { - context.appShellBackend().addListener(registrateOrMainScreen); + context.loginRepository().addListener(registrateOrMainScreen); super.initState(); } Future registrateOrMainScreen() async { var data = - await (context.appShellBackend().userprofileExists() as FutureOr); - if (context.appShell().config.registrationOptions.registrationMode == + await (context.loginRepository().userprofileExists() as FutureOr); + if (context.login().config.registrationOptions.registrationMode == RegistrationMode.Disabled || data) { - context.appShellBackend().setLoggedIn(EmailPasswordLogin.finalEmail!); + context.loginRepository().setLoggedIn(EmailPasswordLogin.finalEmail!); widget.loginComplete!(); } else { debugPrint('Register'); @@ -78,12 +78,7 @@ class _LoginAwaitEmailScreenState extends State style: TextButton.styleFrom(shape: const CircleBorder()), onPressed: null, child: Icon( - context - .appShell() - .config - .appTheme - .icons - .magicLinkAwaitEmail, + context.login().config.appTheme.icons.magicLinkAwaitEmail, ), ), Container(height: 20), @@ -147,7 +142,7 @@ class _LoginAwaitEmailScreenState extends State barrierColor: Colors.black54, ); await context - .appShellBackend() + .loginRepository() .sendLoginEmail(EmailPasswordLogin.finalEmail!); }, ), diff --git a/lib/plugins/login/login_email_password.dart b/lib/plugins/login/login_email_password.dart index bcb8679..a778826 100644 --- a/lib/plugins/login/login_email_password.dart +++ b/lib/plugins/login/login_email_password.dart @@ -25,10 +25,10 @@ class EmailPasswordLogin extends Login { final void Function()? onPressedForgotPassword; @override - _EmailLoginState createState() => _EmailLoginState(); + EmailLoginState createState() => EmailLoginState(); } -class _EmailLoginState extends LoginState { +class EmailLoginState extends LoginState { String email = ''; String error = ''; String password = ''; @@ -71,23 +71,23 @@ class _EmailLoginState extends LoginState { await prefs.setBool( 'autoLogin', - context.appShell().config.loginOptions.autoLoginMode == + context.login().config.loginOptions.autoLoginMode == AutoLoginMode.defaultOn, ); if (!passwordLess && (EmailPasswordLogin.finalEmail != null) && (EmailPasswordLogin.finalPassword != null)) { - if (!(await context.appShellBackend().login( + if (!(await context.loginRepository().login( EmailPasswordLogin.finalEmail!, EmailPasswordLogin.finalPassword!, ))) { setState(() { - error = context.appShellBackend().getLoginError(); + error = context.loginRepository().getLoginError(); _loading = false; }); } else { - context.appShellBackend().setLoggedIn(EmailPasswordLogin.finalEmail!); + context.loginRepository().setLoggedIn(EmailPasswordLogin.finalEmail!); navigateFadeToReplace( context, (context) => widget.child, @@ -96,7 +96,7 @@ class _EmailLoginState extends LoginState { } } else if (passwordLess && (EmailPasswordLogin.finalEmail != null)) { if (await context - .appShellBackend() + .loginRepository() .sendLoginEmail(EmailPasswordLogin.finalEmail!)) { navigateFadeToReplace( context, @@ -120,13 +120,13 @@ class _EmailLoginState extends LoginState { @override Widget buildLoginPage(BuildContext context) { if (context - .appShell() + .login() .config .loginOptions .loginMethod .contains(LoginMethod.LoginInteractiveWithMagicLink) && !context - .appShell() + .login() .config .loginOptions .loginMethod @@ -170,7 +170,7 @@ class _EmailLoginState extends LoginState { child: Container( child: Column( children: [ - context.appShell().config.appTheme.inputs.textField( + context.login().config.appTheme.inputs.textField( value: EmailPasswordLogin.finalEmail ?? '', onChange: (val, valid) { if (valid) { @@ -206,7 +206,7 @@ class _EmailLoginState extends LoginState { Container( alignment: Alignment.centerRight, child: context - .appShell() + .login() .config .appTheme .buttons @@ -225,9 +225,9 @@ class _EmailLoginState extends LoginState { }, ), ), - if (context.appShell().config.loginOptions.autoLoginMode != + if (context.login().config.loginOptions.autoLoginMode != AutoLoginMode.alwaysOff && - context.appShell().config.loginOptions.autoLoginMode != + context.login().config.loginOptions.autoLoginMode != AutoLoginMode.alwaysOn) ...[ Theme( data: Theme.of(context).copyWith( @@ -243,10 +243,10 @@ class _EmailLoginState extends LoginState { ), ), ), - child: context.appShell().config.appTheme.inputs.checkBox( + child: context.login().config.appTheme.inputs.checkBox( value: autoLogin ?? context - .appShell() + .login() .config .loginOptions .autoLoginMode == @@ -295,20 +295,10 @@ class _EmailLoginState extends LoginState { ), onPressed: _handleLoginPress, ), - if (context - .appShell() - .config - .loginOptions - .loginMethod - .contains( + if (context.login().config.loginOptions.loginMethod.contains( LoginMethod.LoginInteractiveWithMagicLink, ) && - context - .appShell() - .config - .loginOptions - .loginMethod - .contains( + context.login().config.loginOptions.loginMethod.contains( LoginMethod.LoginInteractiveWithUsernameAndPassword, )) ...[ FlutterLogin.of(context) @@ -334,12 +324,12 @@ class _EmailLoginState extends LoginState { ) ], if (context - .appShell() + .login() .config .registrationOptions .registrationMode == RegistrationMode.Enabled) ...[ - context.appShell().config.appTheme.buttons.tertiaryButton( + context.login().config.appTheme.buttons.tertiaryButton( context: context, child: Text( context.translate( diff --git a/lib/plugins/login/login_phone_number.dart b/lib/plugins/login/login_phone_number.dart index a7d9c5f..1206fc8 100644 --- a/lib/plugins/login/login_phone_number.dart +++ b/lib/plugins/login/login_phone_number.dart @@ -3,7 +3,6 @@ import 'package:flutter_login/flutter_login_view.dart'; import 'package:intl_phone_number_input/intl_phone_number_input.dart'; import 'package:shared_preferences/shared_preferences.dart'; import '../../extensions/widget.dart'; -import '../../model/login_user.dart'; import '../form/inputs/validators/phone_number_validator.dart'; import 'login_phone_number_verify.dart'; @@ -42,10 +41,9 @@ class LoginPhoneNumberState extends State Container( alignment: Alignment.topLeft, padding: const EdgeInsets.only(top: 10, left: 5), - child: - context.appShell().config.appTheme.buttons.backButton( - context: context, - ), + child: context.login().config.appTheme.buttons.backButton( + context: context, + ), ), ], Padding( @@ -102,7 +100,7 @@ class LoginPhoneNumberState extends State Padding( padding: const EdgeInsets.only(top: 10), child: context - .appShell() + .login() .config .appTheme .buttons @@ -124,7 +122,7 @@ class LoginPhoneNumberState extends State _loading = true; }); context - .appShellBackend() + .loginRepository() .trySignInWithPhoneNumber( phoneNumber: phoneNumber!, onCodeSent: ( @@ -177,7 +175,7 @@ class LoginPhoneNumberState extends State var prefs = await SharedPreferences.getInstance(); await prefs.setBool('autoLogin', true); if (user != null) { - if (await context.appShellBackend().isRegistrationRequired(user)) { + if (await context.loginRepository().isRegistrationRequired(user)) { widget.navRegistration.call(); } else { widget.navAfterLogin.call(); diff --git a/lib/plugins/login/login_phone_number_verify.dart b/lib/plugins/login/login_phone_number_verify.dart index 2691149..c8b356a 100644 --- a/lib/plugins/login/login_phone_number_verify.dart +++ b/lib/plugins/login/login_phone_number_verify.dart @@ -50,7 +50,7 @@ class LoginPhoneNumberVerifyState extends State top: 10, left: 5, ), - child: context.appShell().config.appTheme.buttons.backButton( + child: context.login().config.appTheme.buttons.backButton( context: context, ), ), @@ -84,7 +84,7 @@ class LoginPhoneNumberVerifyState extends State }), onCompleted: (String code) async { var user = - await context.appShellBackend().signInWithSMSCode( + await context.loginRepository().signInWithSMSCode( widget.verificationId, code, widget.phoneNumber, @@ -131,7 +131,7 @@ class LoginPhoneNumberVerifyState extends State style: Theme.of(context).textTheme.bodyText1, ), ), - context.appShell().config.appTheme.buttons.tertiaryButton( + context.login().config.appTheme.buttons.tertiaryButton( context: context, child: Text( context.translate( @@ -141,7 +141,7 @@ class LoginPhoneNumberVerifyState extends State ), onPressed: () { context - .appShellBackend() + .loginRepository() .trySignInWithPhoneNumber( phoneNumber: widget.phoneNumber, onCodeSent: ( diff --git a/lib/plugins/login/login_registration_buttons.dart b/lib/plugins/login/login_registration_buttons.dart index dec9c2f..207371f 100644 --- a/lib/plugins/login/login_registration_buttons.dart +++ b/lib/plugins/login/login_registration_buttons.dart @@ -90,7 +90,7 @@ class LoginRegistrationButtons extends StatelessWidget List _loginButtons(BuildContext context) { var loginButtons = []; if (context - .appShell() + .login() .config .loginOptions .loginMethod @@ -103,7 +103,7 @@ class LoginRegistrationButtons extends StatelessWidget ); } if (context - .appShell() + .login() .config .loginOptions .loginMethod @@ -126,7 +126,7 @@ class LoginRegistrationButtons extends StatelessWidget ); } if (context - .appShell() + .login() .config .loginOptions .loginMethod diff --git a/lib/plugins/login/login_social_buttons.dart b/lib/plugins/login/login_social_buttons.dart index 5dd4caa..07b3b21 100644 --- a/lib/plugins/login/login_social_buttons.dart +++ b/lib/plugins/login/login_social_buttons.dart @@ -15,7 +15,7 @@ class LoginSocialButtons extends StatelessWidget { @override Widget build(BuildContext context) { var config = FlutterLogin.of(context).config; - var backend = context.appShellBackend(); + var repository = context.loginRepository(); return Column( crossAxisAlignment: CrossAxisAlignment.center, @@ -76,7 +76,7 @@ class LoginSocialButtons extends StatelessWidget { ), ), onPressed: () async { - var user = await backend.signInWithSocial( + var user = await repository.signInWithSocial( SocialLoginBundle( method: method, interactionType: SocialInteractionType.Login, @@ -85,7 +85,7 @@ class LoginSocialButtons extends StatelessWidget { var prefs = await SharedPreferences.getInstance(); await prefs.setBool('autoLogin', true); if (user != null) { - if (await backend.isRegistrationRequired(user)) { + if (await repository.isRegistrationRequired(user)) { navigateRegistration(); } else { navigateLogin(); @@ -102,19 +102,19 @@ class LoginSocialButtons extends StatelessWidget { IconData? _iconDataForSocial(SocialLoginMethod method, BuildContext context) { switch (method) { case SocialLoginMethod.Google: - return context.appShell().config.appTheme.icons.google; + return context.login().config.appTheme.icons.google; case SocialLoginMethod.FaceBook: - return context.appShell().config.appTheme.icons.facebook; + return context.login().config.appTheme.icons.facebook; case SocialLoginMethod.Apple: - return context.appShell().config.appTheme.icons.apple; + return context.login().config.appTheme.icons.apple; case SocialLoginMethod.LinkedIn: - return context.appShell().config.appTheme.icons.linkedIn; + return context.login().config.appTheme.icons.linkedIn; case SocialLoginMethod.Microsoft: - return context.appShell().config.appTheme.icons.microsoft; + return context.login().config.appTheme.icons.microsoft; case SocialLoginMethod.Twitter: - return context.appShell().config.appTheme.icons.twitter; + return context.login().config.appTheme.icons.twitter; case SocialLoginMethod.Custom: - return context.appShell().config.appTheme.icons.customSocial; + return context.login().config.appTheme.icons.customSocial; } } } diff --git a/lib/plugins/login/login_widget.dart b/lib/plugins/login/login_widget.dart index b1b0a84..bb3b59b 100644 --- a/lib/plugins/login/login_widget.dart +++ b/lib/plugins/login/login_widget.dart @@ -36,10 +36,10 @@ abstract class LoginState extends State @override Widget build(BuildContext context) => Scaffold( backgroundColor: Theme.of(context).backgroundColor, - body: context.appShell().screens.getAppshellScreenWrapper( + body: context.login().screens.getAppshellScreenWrapper( context, backgroundImg: - context.appShell().config.loginOptions.backgroundImage, + context.login().config.loginOptions.backgroundImage, child: SizedBox( height: MediaQuery.of(context).size.height, child: Stack( diff --git a/lib/sdk/screen.dart b/lib/sdk/screen.dart index 390dd83..2847b3a 100644 --- a/lib/sdk/screen.dart +++ b/lib/sdk/screen.dart @@ -13,7 +13,7 @@ class ScreenService with NavigateWidgetMixin { String? backgroundImg, }) { var bgImage = - backgroundImg ?? context.appShell().config.appOptions.backgroundImage; + backgroundImg ?? context.login().config.appOptions.backgroundImage; if (bgImage.isNotEmpty) { late AssetImage image; var split = bgImage.split(';'); @@ -54,11 +54,11 @@ class ScreenService with NavigateWidgetMixin { .contains(LoginMethod.LoginInteractiveWithPhoneNumber)) ? ChooseLogin( allowExit: true, - child: context.appShell().app, + child: context.login().app, ) : EmailPasswordLogin( allowExit: true, - child: context.appShell().app, + child: context.login().app, ), ); } diff --git a/lib/sdk/user.dart b/lib/sdk/user.dart index fb4b0b6..20bb699 100644 --- a/lib/sdk/user.dart +++ b/lib/sdk/user.dart @@ -52,14 +52,14 @@ class UserService extends ChangeNotifier { } bool isLoggedIn(BuildContext context) => - context.appShellBackend().isLoggedIn(); + context.loginRepository().isLoggedIn(); Future logout(BuildContext context) => SharedPreferences.getInstance().then( (value) { value .setBool('autoLogin', false) - .then((value) => context.appShellBackend().logout()); + .then((value) => context.loginRepository().logout()); }, ); }