Skip to content

Commit

Permalink
fix: 5028 - no more "forever loop" when logging in (#5039)
Browse files Browse the repository at this point in the history
Impacted file:
* `login_page.dart`: dismissing the "forever loop" widget as soon as the server has answered; refactored
  • Loading branch information
monsieurtanuki committed Feb 13, 2024
1 parent 432e9bb commit 3ae6624
Showing 1 changed file with 84 additions and 102 deletions.
186 changes: 84 additions & 102 deletions packages/smooth_app/lib/pages/user_management/login_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,22 +56,21 @@ class _LoginPageState extends State<LoginPage> with TraceableClientMixin {
password: passwordController.text,
),
);
if (!mounted) {
return;
}
setState(() => _runningQuery = false);

if (_loginResult!.type == LoginResultType.successful) {
AnalyticsHelper.trackEvent(AnalyticsEvent.loginAction);
if (!mounted) {
return;
}

await showInAppReviewIfNecessary(context);
if (_loginResult!.type != LoginResultType.successful) {
return;
}

if (!mounted) {
return;
}
Navigator.pop(context);
} else {
setState(() => _runningQuery = false);
AnalyticsHelper.trackEvent(AnalyticsEvent.loginAction);
await _showInAppReviewIfNecessary(context);
if (!mounted) {
return;
}
Navigator.pop(context);
}

@override
Expand Down Expand Up @@ -263,15 +262,13 @@ class _LoginPageState extends State<LoginPage> with TraceableClientMixin {
),
),
),
onPressed: () {
Navigator.push(
context,
MaterialPageRoute<void>(
builder: (BuildContext context) =>
const ForgotPasswordPage(),
),
);
},
onPressed: () async => Navigator.push(
context,
MaterialPageRoute<void>(
builder: (BuildContext context) =>
const ForgotPasswordPage(),
),
),
child: Text(
appLocalizations.forgot_password,
style: theme.textTheme.bodyMedium?.copyWith(
Expand Down Expand Up @@ -346,90 +343,75 @@ class _LoginPageState extends State<LoginPage> with TraceableClientMixin {
);
}

Future<void> showInAppReviewIfNecessary(BuildContext context) async {
Future<void> _showInAppReviewIfNecessary(BuildContext context) async {
final UserPreferences preferences = context.read<UserPreferences>();
if (!preferences.inAppReviewAlreadyAsked) {
assert(mounted);
final bool? enjoyingApp = await showDialog<bool>(
context: context,
builder: (BuildContext context) {
final AppLocalizations appLocalizations =
AppLocalizations.of(context);
if (preferences.inAppReviewAlreadyAsked) {
return;
}

return SmoothAlertDialog(
body: Text(appLocalizations.app_rating_dialog_title_enjoying_app),
positiveAction: SmoothActionButton(
text: appLocalizations
.app_rating_dialog_title_enjoying_positive_actions,
onPressed: () => Navigator.of(context).pop(true),
),
negativeAction: SmoothActionButton(
text: appLocalizations.not_really,
onPressed: () => Navigator.of(context).pop(false),
),
);
},
);
if (enjoyingApp != null && !enjoyingApp) {
if (!context.mounted) {
return;
}
await showDialog<bool>(
context: context,
builder: (BuildContext context) {
final AppLocalizations appLocalizations =
AppLocalizations.of(context);
final AppLocalizations appLocalizations = AppLocalizations.of(context);

return SmoothAlertDialog(
body: Text(
appLocalizations.app_rating_dialog_title_not_enjoying_app),
positiveAction: SmoothActionButton(
text: appLocalizations.okay,
onPressed: () async {
final String formLink =
UserFeedbackHelper.getFeedbackFormLink();
LaunchUrlHelper.launchURL(formLink, false);
Navigator.of(context).pop();
},
),
negativeAction: SmoothActionButton(
text: appLocalizations.not_really,
onPressed: () => Navigator.of(context).pop(),
),
);
},
);
}
bool? userRatedApp;
if (enjoyingApp != null && enjoyingApp) {
if (!context.mounted) {
return;
}
userRatedApp = await showDialog<bool>(
context: context,
builder: (BuildContext context) {
final AppLocalizations appLocalizations =
AppLocalizations.of(context);
final bool? enjoyingApp = await showDialog<bool>(
context: context,
builder: (BuildContext context) => SmoothAlertDialog(
body: Text(appLocalizations.app_rating_dialog_title_enjoying_app),
positiveAction: SmoothActionButton(
text: appLocalizations
.app_rating_dialog_title_enjoying_positive_actions,
onPressed: () => Navigator.of(context).pop(true),
),
negativeAction: SmoothActionButton(
text: appLocalizations.not_really,
onPressed: () => Navigator.of(context).pop(false),
),
),
);
if (enjoyingApp == null) {
return;
}
if (!context.mounted) {
return;
}
if (!enjoyingApp) {
await showDialog<void>(
context: context,
builder: (BuildContext context) => SmoothAlertDialog(
body: Text(appLocalizations.app_rating_dialog_title_not_enjoying_app),
positiveAction: SmoothActionButton(
text: appLocalizations.okay,
onPressed: () async {
final String formLink = UserFeedbackHelper.getFeedbackFormLink();
LaunchUrlHelper.launchURL(formLink, false);
Navigator.of(context).pop();
},
),
negativeAction: SmoothActionButton(
text: appLocalizations.not_really,
onPressed: () => Navigator.of(context).pop(),
),
),
);
return;
}

return SmoothAlertDialog(
body: Text(appLocalizations.app_rating_dialog_title),
positiveAction: SmoothActionButton(
text: appLocalizations.app_rating_dialog_positive_action,
onPressed: () async => Navigator.of(context).pop(
await ApplicationStore.openAppReview(),
),
),
negativeAction: SmoothActionButton(
text: appLocalizations.ask_me_later_button_label,
onPressed: () => Navigator.of(context).pop(false),
),
);
},
);
}
if (userRatedApp != null && userRatedApp) {
await preferences.markInAppReviewAsShown();
}
final bool? userRatedApp = await showDialog<bool>(
context: context,
builder: (BuildContext context) => SmoothAlertDialog(
body: Text(appLocalizations.app_rating_dialog_title),
positiveAction: SmoothActionButton(
text: appLocalizations.app_rating_dialog_positive_action,
onPressed: () async => Navigator.of(context).pop(
await ApplicationStore.openAppReview(),
),
),
negativeAction: SmoothActionButton(
text: appLocalizations.ask_me_later_button_label,
onPressed: () => Navigator.of(context).pop(),
),
),
);
if (userRatedApp == true) {
await preferences.markInAppReviewAsShown();
}
}
}

0 comments on commit 3ae6624

Please sign in to comment.