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

fix: #2706 - now we display the "LOG IN!" button only if not logged in #2714

Merged
merged 1 commit into from
Aug 2, 2022
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,7 @@ abstract class AbstractUserPreferences {

/// Color for the header.
Color? getHeaderColor() => null;

/// Additional subtitle, to be displayed outside a [UserPreferencesListTile].
Widget? getAdditionalSubtitle() => null;
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import 'package:provider/provider.dart';
import 'package:smooth_app/data_models/user_management_provider.dart';
import 'package:smooth_app/data_models/user_preferences.dart';
import 'package:smooth_app/database/local_database.dart';
import 'package:smooth_app/generic_lib/buttons/smooth_simple_button.dart';
import 'package:smooth_app/generic_lib/design_constants.dart';
import 'package:smooth_app/generic_lib/dialogs/smooth_alert_dialog.dart';
import 'package:smooth_app/helpers/launch_url_helper.dart';
Expand Down Expand Up @@ -49,9 +50,11 @@ class UserPreferencesAccount extends AbstractUserPreferences {
@override
PreferencePageType? getPreferencePageType() => PreferencePageType.ACCOUNT;

String? _getUserId() => OpenFoodAPIConfiguration.globalUser?.userId;

@override
Widget getTitle() {
final String? userId = OpenFoodAPIConfiguration.globalUser?.userId;
final String? userId = _getUserId();
final String title;

if (userId == null) {
Expand Down Expand Up @@ -119,6 +122,39 @@ class UserPreferencesAccount extends AbstractUserPreferences {

return OpenFoodAPIConfiguration.globalUser != null;
}

@override
Widget? getAdditionalSubtitle() {
if (_getUserId() != null) {
// we are already connected: no "LOGIN" button
return null;
}
final ThemeData theme = Theme.of(context);
final Size size = MediaQuery.of(context).size;
return Container(
margin: EdgeInsets.symmetric(horizontal: size.width / 4),
child: SmoothSimpleButton(
child: Text(
appLocalizations.sign_in,
style: theme.textTheme.bodyText2?.copyWith(
fontSize: 18.0,
fontWeight: FontWeight.bold,
color: theme.colorScheme.onPrimary,
),
),
onPressed: () async {
Navigator.of(
context,
rootNavigator: true,
).push<dynamic>(
MaterialPageRoute<dynamic>(
builder: (BuildContext context) => const LoginPage(),
),
);
},
),
);
}
}

class _UserPreferencesAccountSubTitleSignOut extends StatelessWidget {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import 'package:matomo_tracker/matomo_tracker.dart';
import 'package:provider/provider.dart';
import 'package:smooth_app/data_models/product_preferences.dart';
import 'package:smooth_app/data_models/user_preferences.dart';
import 'package:smooth_app/generic_lib/buttons/smooth_simple_button.dart';
import 'package:smooth_app/generic_lib/design_constants.dart';
import 'package:smooth_app/pages/preferences/abstract_user_preferences.dart';
import 'package:smooth_app/pages/preferences/user_preferences_account.dart';
Expand All @@ -17,7 +16,6 @@ import 'package:smooth_app/pages/preferences/user_preferences_food.dart';
import 'package:smooth_app/pages/preferences/user_preferences_settings.dart';
import 'package:smooth_app/pages/preferences/user_preferences_user_lists.dart';
import 'package:smooth_app/pages/preferences/user_preferences_widgets.dart';
import 'package:smooth_app/pages/user_management/login_page.dart';
import 'package:smooth_app/themes/theme_provider.dart';
import 'package:smooth_app/widgets/smooth_scaffold.dart';

Expand Down Expand Up @@ -55,8 +53,6 @@ class _UserPreferencesPageState extends State<UserPreferencesPage>
Widget build(BuildContext context) {
final AppLocalizations appLocalizations = AppLocalizations.of(context);
final UserPreferences userPreferences = context.watch<UserPreferences>();
final ThemeData theme = Theme.of(context);
final Size size = MediaQuery.of(context).size;

final String appBarTitle;
final List<Widget> children = <Widget>[];
Expand All @@ -77,38 +73,16 @@ class _UserPreferencesPageState extends State<UserPreferencesPage>
];

for (final PreferencePageType type in items) {
children.add(
getUserPreferences(
type: type,
userPreferences: userPreferences,
).getOnlyHeader(),
final AbstractUserPreferences abstractUserPreferences =
getUserPreferences(
type: type,
userPreferences: userPreferences,
);
if (type == PreferencePageType.ACCOUNT) {
children.add(
Container(
margin: EdgeInsets.symmetric(horizontal: size.width / 4),
child: SmoothSimpleButton(
child: Text(
appLocalizations.sign_in,
style: theme.textTheme.bodyText2?.copyWith(
fontSize: 18.0,
fontWeight: FontWeight.bold,
color: theme.colorScheme.onPrimary,
),
),
onPressed: () async {
Navigator.of(
context,
rootNavigator: true,
).push<dynamic>(
MaterialPageRoute<dynamic>(
builder: (BuildContext context) => const LoginPage(),
),
);
},
),
),
);
children.add(abstractUserPreferences.getOnlyHeader());
final Widget? additionalSubtitle =
abstractUserPreferences.getAdditionalSubtitle();
if (additionalSubtitle != null) {
children.add(additionalSubtitle);
}
}
headerAsset = 'assets/preferences/main.svg';
Expand Down