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

Add loading state to subscription button. #978

Merged
merged 2 commits into from
Sep 16, 2023
Merged
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
37 changes: 26 additions & 11 deletions app/lib/sharezone_plus/page/sharezone_plus_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ class _SubscribeSection extends StatelessWidget {
children: [
_Price(),
SizedBox(height: 12),
_SubscribeButton(),
_SubscribeButton(loading: false),
SizedBox(height: 12),
_LegalText(),
],
Expand Down Expand Up @@ -415,17 +415,32 @@ class _Price extends StatelessWidget {
}

class _SubscribeButton extends StatelessWidget {
const _SubscribeButton();
const _SubscribeButton({this.loading = false});

final bool loading;

@override
Widget build(BuildContext context) {
return _CallToActionButton(
text: const Text('Abonnieren'),
onPressed: () async {
final controller = context.read<SharezonePlusPageController>();
await controller.buySubscription();
},
backgroundColor: Theme.of(context).primaryColor,
// When using [GrayShimmer] the text inside the [_CallToActionButton]
// disappears. Using a [Stack] fixes this issue (I don't know why).
return Stack(
alignment: Alignment.center,
children: [
GrayShimmer(
enabled: loading,
child: _CallToActionButton(
text: const Text('Abonnieren'),
onPressed: loading
? null
: () async {
final controller =
context.read<SharezonePlusPageController>();
await controller.buySubscription();
},
backgroundColor: Theme.of(context).primaryColor,
),
)
],
);
}
}
Expand All @@ -445,12 +460,12 @@ class _LegalText extends StatelessWidget {
class _CallToActionButton extends StatelessWidget {
const _CallToActionButton({
required this.text,
required this.onPressed,
this.onPressed,
this.backgroundColor,
});

final Widget text;
final VoidCallback onPressed;
final VoidCallback? onPressed;
final Color? backgroundColor;

@override
Expand Down