checkIfLoggedIn method
- BuildContext context, {
- required bool isLoggedInMandatory,
Checks if the user is logged in and opens a "please log in" dialog if not.
Implementation
Future<bool> checkIfLoggedIn(
BuildContext context, {
required bool isLoggedInMandatory,
}) async {
if (!isLoggedInMandatory) {
return true;
}
if (ProductQuery.isLoggedIn()) {
return true;
}
final AppLocalizations appLocalizations = AppLocalizations.of(context);
await showDialog<void>(
context: context,
builder: (BuildContext context) => SmoothAlertDialog(
body: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
SvgPicture.asset(
'assets/onboarding/globe.svg',
height: MediaQuery.sizeOf(context).height * .5,
),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 25),
child: Text(
appLocalizations.account_create_message,
style: const TextStyle(fontWeight: FontWeight.bold),
),
),
],
),
actionsAxis: Axis.vertical,
positiveAction: SmoothActionButton(
text: appLocalizations.join_us,
onPressed: () async {
Navigator.of(context).pop(); // remove dialog
await Navigator.of(context, rootNavigator: true).push<dynamic>(
MaterialPageRoute<dynamic>(
builder: (BuildContext context) => const LoginPage(),
),
);
},
),
negativeAction: SmoothActionButton(
text: appLocalizations.cancel,
onPressed: () => Navigator.of(context).pop(),
),
),
);
return false;
}