Skip to content

Commit

Permalink
fix: various things (#557)
Browse files Browse the repository at this point in the history
  • Loading branch information
marfavi authored Dec 7, 2023
1 parent 9db04b1 commit bc0fa26
Show file tree
Hide file tree
Showing 18 changed files with 104 additions and 70 deletions.
1 change: 1 addition & 0 deletions devtools_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
extensions:
8 changes: 8 additions & 0 deletions ios/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
4 changes: 2 additions & 2 deletions ios/Runner/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@
</array>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>UIApplicationSupportsIndirectInputEvents</key>
<true/>
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
<key>UIMainStoryboardFile</key>
Expand All @@ -68,7 +70,5 @@
</array>
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
<key>UIApplicationSupportsIndirectInputEvents</key>
<true/>
</dict>
</plist>
10 changes: 8 additions & 2 deletions lib/core/strings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -162,14 +162,20 @@ abstract final class Strings {
return "You're buying $amount $title tickets";
}

static String paymentConfirmationTopSingle(int amount, String title) {
return "You're buying and swiping $amount $title";
static String paymentConfirmationTopSingle(String title) {
return "You're buying 1 $title";
}

static String paymentConfirmationTopFreeSingle(String title) {
return "You're claiming 1 $title";
}

static String paymentConfirmationBottomPurchase(int price) {
return 'Pay $price,- with...';
}

static String oneCup = '1 cup';

static String amountTickets(int amount) {
return '$amount tickets';
}
Expand Down
3 changes: 3 additions & 0 deletions lib/core/styles/text_style_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ class TextStyleBuilder {
final isMono = _fontFamily == _AnalogFontFamily.mono;

final letterSpacing = _fontFamily == _AnalogFontFamily.body ? 0.25 : null;
const lineHeight = 1.1;
final height = isHeading ? lineHeight : null;
return isMono
? TextStyle(
fontFamily: 'RobotoMono',
Expand All @@ -162,6 +164,7 @@ class TextStyleBuilder {
color: _color,
decoration: _decoration,
letterSpacing: letterSpacing,
height: height,
fontVariations: [
FontVariation('wght', _fontWeight),
if (_fontSize != null) FontVariation('opsz', _fontSize!),
Expand Down
9 changes: 3 additions & 6 deletions lib/core/widgets/components/barista_perks_section.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,9 @@ class _BaristaPerksSectionState extends State<BaristaPerksSection> {
final roleName = widget.userRole.name.capitalize();
return Column(
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
SectionTitle(Strings.perksTitle(roleName)),
UserRoleIndicator(widget.userRole),
],
SectionTitle.withSideWidget(
Strings.perksTitle(roleName),
sideWidget: UserRoleIndicator(widget.userRole),
),
Grid(
gap: GridGap.normal,
Expand Down
17 changes: 8 additions & 9 deletions lib/core/widgets/components/helpers/grid.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ class Grid extends StatelessWidget {

int _columns(bool isSmall) => isSmall && singleColumnOnSmallDevice ? 1 : 2;

int _rows(bool isSmall) => (children.length / _columns(isSmall)).ceil();

@override
Widget build(BuildContext context) {
final isSmall = deviceIsSmall(context);
Expand All @@ -47,15 +49,12 @@ class Grid extends StatelessWidget {
if (children.isEmpty) {
return const SizedBox.shrink();
}
return UnconstrainedBox(
constrainedAxis: Axis.horizontal,
child: LayoutGrid(
columnSizes: List.filled(columns, 1.fr),
rowSizes: List.filled(children.length, auto),
columnGap: horizontalGap,
rowGap: verticalGap,
children: children,
),
return LayoutGrid(
columnSizes: List.filled(columns, 1.fr),
rowSizes: List.filled(_rows(isSmall), auto),
columnGap: horizontalGap,
rowGap: verticalGap,
children: children,
);
}
}
28 changes: 17 additions & 11 deletions lib/core/widgets/components/section_title.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,28 @@ import 'package:coffeecard/core/styles/app_text_styles.dart';
import 'package:flutter/material.dart';

class SectionTitle extends StatelessWidget {
final String title;
final double bottomMargin;
/// A section title no side widget.
const SectionTitle(this.title) : sideWidget = null;

const SectionTitle(this.title) : bottomMargin = 8;
/// A section title with a side widget.
const SectionTitle.withSideWidget(this.title, {required this.sideWidget});

/// Section title for register screens. Has extra bottom margin.
const SectionTitle.register(this.title) : bottomMargin = 16;
final String title;
final Widget? sideWidget;

@override
Widget build(BuildContext context) {
return Container(
margin: EdgeInsets.only(bottom: bottomMargin),
child: Text(
title,
style: AppTextStyle.sectionTitle,
),
final textWidget = Text(title, style: AppTextStyle.sectionTitle);
final sideWidget = this.sideWidget;

return Padding(
padding: const EdgeInsets.only(bottom: 8),
child: (sideWidget == null)
? textWidget
: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [textWidget, sideWidget],
),
);
}
}
4 changes: 3 additions & 1 deletion lib/features/form/presentation/widgets/form.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import 'package:coffeecard/features/form/presentation/bloc/form_bloc.dart';
import 'package:flutter/material.dart' hide FormState;
import 'package:flutter/services.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:gap/gap.dart';

part 'form_text_field.dart';

Expand Down Expand Up @@ -86,7 +87,8 @@ class FormBase extends StatelessWidget {
Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
if (title != null) SectionTitle.register(title!),
if (title != null) SectionTitle(title!),
const Gap(8),
_FormTextField(
inputValidators: inputValidators,
onChanged: (input) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import 'package:coffeecard/core/strings.dart';
import 'package:coffeecard/core/styles/app_text_styles.dart';
import 'package:coffeecard/core/widgets/components/helpers/grid.dart';
import 'package:coffeecard/core/widgets/components/section_title.dart';
import 'package:coffeecard/features/leaderboard/presentation/widgets/statistics_card.dart';
import 'package:coffeecard/features/user/domain/entities/user.dart';
import 'package:coffeecard/features/user/presentation/cubit/user_cubit.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:gap/gap.dart';

class StatisticsSection extends StatelessWidget {
const StatisticsSection();
Expand Down Expand Up @@ -35,8 +34,7 @@ class _YourStatsGrid extends StatelessWidget {
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Text(Strings.statsYourStats, style: AppTextStyle.sectionTitle),
const Gap(8),
const SectionTitle(Strings.statsYourStats),
Grid(
singleColumnOnSmallDevice: false,
gap: GridGap.tightVertical,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ class OccupationForm extends StatelessWidget {
children: [
const Gap(16),
const SectionTitle(Strings.registerOccupationTitle),
const Gap(16),
ClipRRect(
borderRadius: const BorderRadius.all(Radius.circular(24)),
child: Column(
Expand Down
57 changes: 34 additions & 23 deletions lib/features/product/presentation/functions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,18 @@ Future<void> buyModal({

/// Callback that will be run after the purchase modal is closed, but before
/// the receipt overlay is shown.
///
/// [payment] will be null if the purchase was cancelled.
required Future<void> Function(BuildContext, Payment?) callback,
}) async {
final scrimText = (product.price == 0)
? Strings.paymentConfirmationTopSingle(product.amount, product.name)
: Strings.paymentConfirmationTopTickets(product.amount, product.name);
// Find the correct text to show in the scrim.
const free = 0;
const single = 1;
final scrimText = switch ((product.price, product.amount)) {
(free, single) => Strings.paymentConfirmationTopFreeSingle(product.name),
(_, single) => Strings.paymentConfirmationTopSingle(product.name),
_ => Strings.paymentConfirmationTopTickets(product.amount, product.name),
};

// Create a task that will open the purchase modal and wait for the result.
final maybePayment = await showModalBottomSheet<Payment>(
Expand All @@ -44,29 +51,33 @@ Future<void> buyModal({
if (!context.mounted) return;

// Show the receipt overlay if the payment was successful.
return _afterPurchaseModal(context, maybePayment);
}

Future<void> _afterPurchaseModal(BuildContext context, Payment? payment) async {
// Don't do anything if the payment is null or not completed.
if (payment == null || payment.status != PaymentStatus.completed) {
return;
if (maybePayment?.status == PaymentStatus.completed) {
return _afterPurchaseModal(context, maybePayment!, product);
}
}

Future<void> _afterPurchaseModal(
BuildContext context,
Payment payment,
Product product,
) async {
final envState = context.read<EnvironmentCubit>().state;
final singleTicketPurchase = product.amount == 1;

final updateTicketsRequest = context.read<TicketsCubit>().getTickets();
final updateReceiptsRequest = context.read<ReceiptCubit>().fetchReceipts();
final ticketsCubit = context.read<TicketsCubit>();
final receiptCubit = context.read<ReceiptCubit>();

ReceiptOverlay.show(
context: context,
isTestEnvironment: envState is EnvironmentLoaded && envState.env.isTest,
status: Strings.purchased,
productName: payment.productName,
timeUsed: payment.purchaseTime,
).ignore();

// TODO: Explain why we need to await here.
await updateTicketsRequest;
await updateReceiptsRequest;
if (singleTicketPurchase) {
await ticketsCubit.useTicket(product.id);
} else {
ticketsCubit.getTickets();
ReceiptOverlay.show(
context: context,
isTestEnvironment: envState is EnvironmentLoaded && envState.env.isTest,
status: Strings.purchased,
productName: payment.productName,
timeUsed: payment.purchaseTime,
).ignore();
}
await receiptCubit.fetchReceipts();
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:coffeecard/core/widgets/components/card.dart';
import 'package:coffeecard/core/widgets/components/helpers/responsive.dart';
import 'package:coffeecard/features/product/domain/entities/product.dart';
import 'package:coffeecard/features/product/presentation/functions.dart';
import 'package:coffeecard/features/purchase/domain/entities/payment_status.dart';
import 'package:flutter/material.dart';
import 'package:gap/gap.dart';

Expand All @@ -21,7 +22,11 @@ class _BuyTicketsCardState extends State<BuyTicketsCard> {
return buyModal(
context: context,
product: product,
callback: (context, _) async => Navigator.of(context).pop(),
callback: (context, maybePayment) async {
if (maybePayment?.status == PaymentStatus.completed) {
Navigator.of(context).pop();
}
},
);
}

Expand Down
5 changes: 3 additions & 2 deletions lib/features/ticket/presentation/pages/tickets_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:coffeecard/core/strings.dart';
import 'package:coffeecard/core/widgets/components/barista_perks_section.dart';
import 'package:coffeecard/core/widgets/components/scaffold.dart';
import 'package:coffeecard/core/widgets/upgrade_alert.dart';
import 'package:coffeecard/features/product/domain/entities/purchasable_products.dart';
import 'package:coffeecard/features/ticket/presentation/widgets/shop_section.dart';
import 'package:coffeecard/features/ticket/presentation/widgets/tickets_section.dart';
import 'package:coffeecard/features/user/presentation/cubit/user_cubit.dart';
Expand All @@ -22,7 +23,7 @@ class TicketsPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
final user = (context.read<UserCubit>().state as UserLoaded).user;
final hasBaristaPerks = user.hasBaristaPerks;
final perksAvailable = context.read<PurchasableProducts>().perks.isNotEmpty;

return UpgradeAlert(
child: AppScaffold.withTitle(
Expand All @@ -37,7 +38,7 @@ class TicketsPage extends StatelessWidget {
padding: const EdgeInsets.all(16.0),
children: [
const TicketSection(),
if (hasBaristaPerks) BaristaPerksSection(userRole: user.role),
if (perksAvailable) BaristaPerksSection(userRole: user.role),
const ShopSection(),
],
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,9 @@ class _ModalContentState extends State<_ModalContent>
child: SlideAction(
elevation: 0,
text: Strings.useTicket,
textStyle: AppTextStyle.buttonText,
textStyle: AppTextStyle.buttonText.apply(
color: AppColors.white,
),
height: 56,
sliderButtonIcon: const Icon(
Icons.navigate_next,
Expand Down
10 changes: 3 additions & 7 deletions lib/features/ticket/presentation/widgets/tickets_section.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,9 @@ class TicketSection extends StatelessWidget {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
SectionTitle(Strings.ticketsMyTickets),
OpeningHoursIndicator(),
],
const SectionTitle.withSideWidget(
Strings.ticketsMyTickets,
sideWidget: OpeningHoursIndicator(),
),
BlocConsumer<TicketsCubit, TicketsState>(
listenWhen: (previous, current) =>
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/core/widgets/components/tickets/goldens/coffee_card.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit bc0fa26

Please sign in to comment.