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

display snackbar when app update is available #559

Draft
wants to merge 11 commits into
base: main
Choose a base branch
from
Draft
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
26 changes: 15 additions & 11 deletions lib/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import 'package:coffeecard/features/authentication/presentation/cubits/authentic
import 'package:coffeecard/features/environment/presentation/cubit/environment_cubit.dart';
import 'package:coffeecard/features/product/presentation/cubit/product_cubit.dart';
import 'package:coffeecard/features/redirection/redirection_router.dart';
import 'package:coffeecard/features/upgrader/presentation/cubit/upgrader_cubit.dart';
import 'package:coffeecard/features/user/presentation/cubit/user_cubit.dart';
import 'package:coffeecard/service_locator.dart';
import 'package:flutter/material.dart';
Expand All @@ -26,19 +27,22 @@ class App extends StatelessWidget {
BlocProvider.value(value: sl<EnvironmentCubit>()..getConfig()),
BlocProvider(create: (_) => sl<UserCubit>()),
BlocProvider.value(value: sl<ProductCubit>()),
BlocProvider(create: (_) => sl<UpgraderCubit>()..load()),
],
child: MainRedirectionRouter(
navigatorKey: _navigatorKey,
child: MaterialApp(
title: Strings.appTitle,
theme: analogTheme,
child: ScaffoldMessenger(
child: MainRedirectionRouter(
navigatorKey: _navigatorKey,
home: BlocBuilder<EnvironmentCubit, EnvironmentState>(
builder: (_, state) {
return (state is EnvironmentError)
? SplashErrorPage(errorMessage: state.message)
: const SplashLoadingPage();
},
child: MaterialApp(
title: Strings.appTitle,
theme: analogTheme,
navigatorKey: _navigatorKey,
home: BlocBuilder<EnvironmentCubit, EnvironmentState>(
builder: (_, state) {
return (state is EnvironmentError)
? SplashErrorPage(errorMessage: state.message)
: const SplashLoadingPage();
},
),
),
),
),
Expand Down
13 changes: 11 additions & 2 deletions lib/core/api_uri_constants.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,19 @@
// ignore_for_file: avoid-global-state
class ApiUriConstants {
static Uri shiftyUrl = Uri.parse('https://analogio.dk/shiftplanning');
static const String apiVersion = '1';
static const String minAppVersion = '2.1.0';
static Uri analogIOGitHub = Uri.parse('https://github.com/AnalogIO/');

static const String minAppVersion = '2.1.0';

// Upgrader
static const String androidId = 'dk.analog.digitalclipcard';
static const String iOSBundle = 'DK.AnalogIO.DigitalCoffeeCard';

static const String playStoreUrl =
'https://play.google.com/store/apps/details?id=$androidId';
static const String appStoreUrl =
'https://apps.apple.com/us/app/cafe-analog/id1148152818';

// Mobilepay
static Uri mobilepayAndroid =
Uri.parse('market://details?id=dk.danskebank.mobilepay');
Expand Down
2 changes: 1 addition & 1 deletion lib/core/external/external_url_launcher.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ class ExternalUrlLauncher {
);

Future<void> launchUrlExternalApplication(
Uri url,
BuildContext context,
Uri url,
) async {
if (await canLaunch(url)) {
final _ = launch(url);
Expand Down
21 changes: 21 additions & 0 deletions lib/core/external/platform_service.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import 'dart:io';

import 'package:coffeecard/core/models/platform_type.dart';
import 'package:package_info_plus/package_info_plus.dart';

class PlatformService {
PlatformType platformType() {
if (Platform.isAndroid) {

Check warning on line 8 in lib/core/external/platform_service.dart

View check run for this annotation

Codecov / codecov/patch

lib/core/external/platform_service.dart#L7-L8

Added lines #L7 - L8 were not covered by tests
return PlatformType.android;
}

if (Platform.isIOS) {

Check warning on line 12 in lib/core/external/platform_service.dart

View check run for this annotation

Codecov / codecov/patch

lib/core/external/platform_service.dart#L12

Added line #L12 was not covered by tests
return PlatformType.iOS;
}

return PlatformType.unknown;
}

Future<String> currentVersion() async =>
PackageInfo.fromPlatform().then((info) => info.version);

Check warning on line 20 in lib/core/external/platform_service.dart

View check run for this annotation

Codecov / codecov/patch

lib/core/external/platform_service.dart#L19-L20

Added lines #L19 - L20 were not covered by tests
}
5 changes: 5 additions & 0 deletions lib/core/models/platform_type.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
enum PlatformType {
android,
iOS,
unknown,
}
5 changes: 5 additions & 0 deletions lib/core/strings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,11 @@ abstract final class Strings {
static String almost(String time) => 'almost $time';
static String moreThan(String time) => 'more than $time';

// Upgrader
static const upgraderUpdateAvailable = 'An update is available, click ';
static const upgraderHere = 'here';
static const upgraderToDownload = ' to download it';

// Errors
static const error = 'Error';
static const cantLaunchUrl = 'The app can not launch the Url';
Expand Down
73 changes: 38 additions & 35 deletions lib/core/widgets/pages/home_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import 'package:coffeecard/features/receipt/presentation/pages/receipts_page.dar
import 'package:coffeecard/features/settings/presentation/pages/settings_page.dart';
import 'package:coffeecard/features/ticket/presentation/cubit/tickets_cubit.dart';
import 'package:coffeecard/features/ticket/presentation/pages/tickets_page.dart';
import 'package:coffeecard/features/upgrader/presentation/widgets/upgrader.dart';
import 'package:coffeecard/service_locator.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
Expand Down Expand Up @@ -123,42 +124,44 @@ class _HomePageState extends State<HomePage> {

@override
Widget build(BuildContext context) {
return Provider(
create: (BuildContext context) => widget.products,
child: MultiBlocProvider(
providers: [
BlocProvider(
create: (_) => sl<TicketsCubit>()..getTickets(),
),
BlocProvider(
create: (_) => sl<ReceiptCubit>()..fetchReceipts(),
),
BlocProvider(
create: (_) => sl<LeaderboardCubit>()..loadLeaderboard(),
),
BlocProvider(
create: (_) => sl<OpeningHoursCubit>()..getOpeninghours(),
),
],
child: PopScope(
onPopInvoked: (_) => onWillPop(),
child: Scaffold(
backgroundColor: AppColors.background,
body: LazyIndexedStack(
index: _currentPageIndex,
children: _bottomNavAppFlows,
return Upgrader(
child: Provider(
create: (BuildContext context) => widget.products,
child: MultiBlocProvider(
providers: [
BlocProvider(
create: (_) => sl<TicketsCubit>()..getTickets(),
),
BlocProvider(
create: (_) => sl<ReceiptCubit>()..fetchReceipts(),
),
BlocProvider(
create: (_) => sl<LeaderboardCubit>()..loadLeaderboard(),
),
BlocProvider(
create: (_) => sl<OpeningHoursCubit>()..getOpeninghours(),
),
bottomNavigationBar: BottomNavigationBar(
items: _pages.map((p) => p.bottomNavigationBarItem).toList(),
currentIndex: _currentPageIndex,
onTap: onBottomNavTap,
type: BottomNavigationBarType.fixed,
backgroundColor: AppColors.primary,
selectedItemColor: AppColors.white,
unselectedItemColor: AppColors.white.withOpacity(0.5),
selectedFontSize: 12,
unselectedLabelStyle: AppTextStyle.bottomNavBarLabel,
selectedLabelStyle: AppTextStyle.bottomNavBarLabel,
],
child: PopScope(
onPopInvoked: (_) => onWillPop(),
child: Scaffold(
backgroundColor: AppColors.background,
body: LazyIndexedStack(
index: _currentPageIndex,
children: _bottomNavAppFlows,
),
bottomNavigationBar: BottomNavigationBar(
items: _pages.map((p) => p.bottomNavigationBarItem).toList(),
currentIndex: _currentPageIndex,
onTap: onBottomNavTap,
type: BottomNavigationBarType.fixed,
backgroundColor: AppColors.primary,
selectedItemColor: AppColors.white,
unselectedItemColor: AppColors.white.withOpacity(0.5),
selectedFontSize: 12,
unselectedLabelStyle: AppTextStyle.bottomNavBarLabel,
selectedLabelStyle: AppTextStyle.bottomNavBarLabel,
),
),
),
),
Expand Down
22 changes: 0 additions & 22 deletions lib/core/widgets/upgrade_alert.dart

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ class CreditsPage extends StatelessWidget {
name: Strings.github,
onTap: () =>
sl<ExternalUrlLauncher>().launchUrlExternalApplication(
ApiUriConstants.analogIOGitHub,
context,
ApiUriConstants.analogIOGitHub,
),
),
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ class ContributorCard extends StatelessWidget {
Widget build(BuildContext context) {
return Tappable(
onTap: () => sl<ExternalUrlLauncher>().launchUrlExternalApplication(
Uri.parse(contributor.githubUrl),
context,
Uri.parse(contributor.githubUrl),
),
child: DecoratedBox(
decoration: const BoxDecoration(
Expand Down
10 changes: 5 additions & 5 deletions lib/features/login/presentation/pages/login_page_base.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import 'package:coffeecard/core/styles/app_text_styles.dart';
import 'package:coffeecard/core/widgets/components/helpers/responsive.dart';
import 'package:coffeecard/core/widgets/components/scaffold.dart';
import 'package:coffeecard/core/widgets/images/analog_logo.dart';
import 'package:coffeecard/core/widgets/upgrade_alert.dart';
import 'package:coffeecard/features/login/presentation/widgets/login_input_hint.dart';
import 'package:coffeecard/features/upgrader/presentation/widgets/upgrader.dart';
import 'package:flutter/material.dart';
import 'package:gap/gap.dart';

Expand All @@ -28,10 +28,10 @@ class LoginPageBase extends StatelessWidget {

@override
Widget build(BuildContext context) {
return UpgradeAlert(
child: AppScaffold.withoutTitle(
resizeToAvoidBottomInset: resizeToAvoidBottomInset,
body: Column(
return AppScaffold.withoutTitle(
resizeToAvoidBottomInset: resizeToAvoidBottomInset,
body: Upgrader(
child: Column(
children: [
Expanded(
child: Column(
Expand Down
20 changes: 10 additions & 10 deletions lib/features/purchase/data/repositories/mobilepay_service.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import 'dart:io';

import 'package:coffeecard/core/api_uri_constants.dart';
import 'package:coffeecard/core/errors/failures.dart';
import 'package:coffeecard/core/extensions/either_extensions.dart';
import 'package:coffeecard/core/external/external_url_launcher.dart';
import 'package:coffeecard/core/external/platform_service.dart';
import 'package:coffeecard/core/models/platform_type.dart';
import 'package:coffeecard/features/purchase/data/repositories/payment_handler.dart';
import 'package:coffeecard/features/purchase/domain/entities/payment.dart';
import 'package:coffeecard/features/purchase/domain/entities/payment_status.dart';
Expand Down Expand Up @@ -56,8 +56,8 @@
// MobilePay not installed, send user to appstore
if (buildContext.mounted) {
await externalUrlLauncher.launchUrlExternalApplication(
url,
buildContext,
url,
);
}

Expand All @@ -68,12 +68,12 @@
}

Uri _getAppStoreUri() {
if (Platform.isAndroid) {
return ApiUriConstants.mobilepayAndroid;
} else if (Platform.isIOS) {
return ApiUriConstants.mobilepayIOS;
} else {
throw UnsupportedError('Unsupported platform');
}
final platformService = PlatformService();

Check warning on line 71 in lib/features/purchase/data/repositories/mobilepay_service.dart

View check run for this annotation

Codecov / codecov/patch

lib/features/purchase/data/repositories/mobilepay_service.dart#L71

Added line #L71 was not covered by tests

return switch (platformService.platformType()) {
PlatformType.android => ApiUriConstants.mobilepayAndroid,
PlatformType.iOS => ApiUriConstants.mobilepayIOS,
PlatformType.unknown => throw UnsupportedError('Unsupported platform'),

Check warning on line 76 in lib/features/purchase/data/repositories/mobilepay_service.dart

View check run for this annotation

Codecov / codecov/patch

lib/features/purchase/data/repositories/mobilepay_service.dart#L73-L76

Added lines #L73 - L76 were not covered by tests
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ class AboutSection extends StatelessWidget {

void privacyPolicyTapCallback(BuildContext context) {
sl<ExternalUrlLauncher>().launchUrlExternalApplication(
ApiUriConstants.privacyPolicyUri,
context,
ApiUriConstants.privacyPolicyUri,
);
}

void provideFeedbackTapCallback(BuildContext context) {
sl<ExternalUrlLauncher>().launchUrlExternalApplication(
ApiUriConstants.feedbackFormUri,
context,
ApiUriConstants.feedbackFormUri,
);
}

Expand Down
37 changes: 17 additions & 20 deletions lib/features/ticket/presentation/pages/tickets_page.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
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';
Expand All @@ -25,26 +24,24 @@ class TicketsPage extends StatelessWidget {
final user = (context.read<UserCubit>().state as UserLoaded).user;
final perksAvailable = context.read<PurchasableProducts>().perks.isNotEmpty;

return UpgradeAlert(
child: AppScaffold.withTitle(
title: Strings.ticketsPageTitle,
body: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Expanded(
child: ListView(
controller: scrollController,
shrinkWrap: true,
padding: const EdgeInsets.all(16.0),
children: [
const TicketSection(),
if (perksAvailable) BaristaPerksSection(userRole: user.role),
const ShopSection(),
],
),
return AppScaffold.withTitle(
title: Strings.ticketsPageTitle,
body: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Expanded(
child: ListView(
controller: scrollController,
shrinkWrap: true,
padding: const EdgeInsets.all(16.0),
children: [
const TicketSection(),
if (perksAvailable) BaristaPerksSection(userRole: user.role),
const ShopSection(),
],
),
],
),
),
],
),
);
}
Expand Down
Loading
Loading