From 0340edd49d114dbf23213985a4eb55abb3c12158 Mon Sep 17 00:00:00 2001 From: Alessandro Liparoti Date: Sun, 5 Nov 2023 16:23:25 +0100 Subject: [PATCH] use external browser --- lib/screens/BottomBarMatch.dart | 103 ++++++++++++++++++-------------- lib/screens/UserPage.dart | 20 ++++--- 2 files changed, 70 insertions(+), 53 deletions(-) diff --git a/lib/screens/BottomBarMatch.dart b/lib/screens/BottomBarMatch.dart index 24bd571..4c3a78c 100644 --- a/lib/screens/BottomBarMatch.dart +++ b/lib/screens/BottomBarMatch.dart @@ -13,18 +13,17 @@ import 'package:flutter_gen/gen_l10n/app_localizations.dart'; import '../state/MatchesState.dart'; class BottomBarMatch extends StatelessWidget { - - static Widget? getBottomBar(BuildContext context, String matchId, - MatchStatus? matchStatus) { + static Widget? getBottomBar( + BuildContext context, String matchId, MatchStatus? matchStatus) { // https://docs.google.com/document/d/1PpHh-8blyMYH7ePtU-XIBU289guZX847eBfHz_yqPJ0/edit# var match = context.read().getMatch(matchId); - if (match == null || matchStatus == null) - return null; + if (match == null || matchStatus == null) return null; var isFull = match.isFull(); - var isGoing = match.isUserGoing(context.read().getLoggedUserDetails()); + var isGoing = + match.isUserGoing(context.read().getLoggedUserDetails()); var bottomBar; @@ -47,8 +46,8 @@ class BottomBarMatch extends StatelessWidget { break; case MatchStatus.to_rate: if (isGoing) { - var stillToVote = context.read() - .getStillToVote(matchId, context.read().currentUserId!); + var stillToVote = context.read().getStillToVote( + matchId, context.read().currentUserId!); if (stillToVote != null && stillToVote.isNotEmpty) bottomBar = RatePlayersBottomBar(matchId: matchId); } @@ -70,8 +69,13 @@ class BottomBarMatch extends StatelessWidget { final String? subText; final Widget? button; - const BottomBarMatch({Key? key, required this.matchId, required this.text, - this.subText, this.button}) : super(key: key); + const BottomBarMatch( + {Key? key, + required this.matchId, + required this.text, + this.subText, + this.button}) + : super(key: key); @override Widget build(BuildContext context) { @@ -96,8 +100,7 @@ class BottomBarMatch extends StatelessWidget { ], ), ), - if (button != null) - button! + if (button != null) button! ], ), )); @@ -137,11 +140,12 @@ class GenericBottomBar extends StatelessWidget { } class JoinMatchBottomBar extends StatelessWidget { - final String matchId; final bool enabled; - const JoinMatchBottomBar({Key? key, required this.matchId, required this.enabled}) : super(key: key); + const JoinMatchBottomBar( + {Key? key, required this.matchId, required this.enabled}) + : super(key: key); @override Widget build(BuildContext context) { @@ -151,71 +155,82 @@ class JoinMatchBottomBar extends StatelessWidget { return Container(); } - return BottomBarMatch(matchId: matchId, - text: AppLocalizations.of(context)!.spotsLeft(match.getSpotsLeft()), - subText: match.price != null ? - formatCurrency(match.price!.getTotalPrice()) : null, - button: enabled ? JoinButton(matchId: matchId) : JoinButtonDisabled() - ); + return BottomBarMatch( + matchId: matchId, + text: AppLocalizations.of(context)!.spotsLeft(match.getSpotsLeft()), + subText: match.price != null + ? formatCurrency(match.price!.getTotalPrice()) + : null, + button: enabled ? JoinButton(matchId: matchId) : JoinButtonDisabled()); } } class LeaveMatchBottomBar extends StatelessWidget { - final String matchId; final bool enabled; - const LeaveMatchBottomBar({Key? key, required this.matchId, required this.enabled}) : super(key: key); + const LeaveMatchBottomBar( + {Key? key, required this.matchId, required this.enabled}) + : super(key: key); @override Widget build(BuildContext context) { var match = context.read().getMatch(matchId); - return BottomBarMatch(matchId: matchId, + return BottomBarMatch( + matchId: matchId, text: AppLocalizations.of(context)!.joinMatchSuccessTitle, - subText: AppLocalizations.of(context)!.joinMatchBarSubtitle(match!.getGoingPlayers()), - button: enabled ? LeaveButton(matchId: matchId) : LeaveButtonDisabled() - ); + subText: AppLocalizations.of(context)! + .joinMatchBarSubtitle(match!.getGoingPlayers()), + button: + enabled ? LeaveButton(matchId: matchId) : LeaveButtonDisabled()); } } class RatePlayersBottomBar extends StatelessWidget { - final String matchId; - const RatePlayersBottomBar({Key? key, required this.matchId}) : super(key: key); + const RatePlayersBottomBar({Key? key, required this.matchId}) + : super(key: key); @override Widget build(BuildContext context) { - return BottomBarMatch(matchId: matchId, + return BottomBarMatch( + matchId: matchId, text: "Rate players", - subText: context.watch().getStillToVote( - matchId, - context.read().currentUserId!)!.length.toString() + - " players left", - button: RateButton(matchId: matchId) - ); + subText: context + .watch() + .getStillToVote( + matchId, context.read().currentUserId!)! + .length + .toString() + + " players left", + button: RateButton(matchId: matchId)); } } class NotPublishedBottomBar extends StatelessWidget { - final String matchId; - const NotPublishedBottomBar({Key? key, required this.matchId}) : super(key: key); + const NotPublishedBottomBar({Key? key, required this.matchId}) + : super(key: key); @override Widget build(BuildContext context) { var userState = context.read(); - return BottomBarMatch(matchId: matchId,text: "Not Published", - subText: "Complete your Stripe account to receive payments and publish this match", - button: InkWell(onTap: () => - launchUrl(Uri.parse(getStripeUrl(userState.isTestMode, - userState.currentUserId!))), + return BottomBarMatch( + matchId: matchId, + text: "Not Published", + subText: + "Complete your Stripe account to receive payments and publish this match", + button: InkWell( + onTap: () => launchUrl( + Uri.parse(getStripeUrl( + userState.isTestMode, userState.currentUserId!)), + mode: LaunchMode.externalApplication), child: Padding( padding: EdgeInsets.only(top: 8), - child: Text("GO TO STRIPE", style: TextPalette.linkStyle))) - ); + child: Text("GO TO STRIPE", style: TextPalette.linkStyle)))); } } diff --git a/lib/screens/UserPage.dart b/lib/screens/UserPage.dart index 9becb1e..1561d00 100644 --- a/lib/screens/UserPage.dart +++ b/lib/screens/UserPage.dart @@ -118,7 +118,7 @@ class UserPageState extends State { }); try { await UserController.updloadPicture( - context, userDetails!); + context, userDetails); } catch (e, s) { print(e); print(s); @@ -188,7 +188,7 @@ class UserPageState extends State { }); try { await UserController.updloadPicture( - context, userDetails!); + context, userDetails); } catch (e, s) { print(e); print(s); @@ -211,7 +211,7 @@ class UserPageState extends State { child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ - Text(userDetails!.name ?? "N/A", style: TextPalette.h2), + Text(userDetails.name ?? "N/A", style: TextPalette.h2), SizedBox(height: 10), Text(formatEmail(userDetails.email), style: TextPalette.bodyText) @@ -246,7 +246,7 @@ class UserPageState extends State { child: UserInfoBox( content: (userDetails.numWin ?? 0).toString(), description: - AppLocalizations.of(context)!.numMatchesWonBoxTitle)), + AppLocalizations.of(context)!.numMatchesWonBoxTitle)), ]), if (userDetails.numWin != null) verticalSpace, if (userDetails.numWin != null) @@ -255,7 +255,7 @@ class UserPageState extends State { child: UserInfoBox( content: (userDetails.numDraw ?? 0).toString(), description: - AppLocalizations.of(context)!.numMatchesDrawBoxTitle)), + AppLocalizations.of(context)!.numMatchesDrawBoxTitle)), SizedBox(width: 20), Expanded( child: UserInfoBox( @@ -375,10 +375,11 @@ class UserPageState extends State { AppLocalizations.of(context)! .goToStripeDashboardText + (isTest ? " TEST" : ""), (_) async { - var url = CloudFunctionsClient() - .getUrl("stripe/account?is_test?$isTest&user_id=${userDetails.documentId}"); + var url = CloudFunctionsClient().getUrl( + "stripe/account?is_test?$isTest&user_id=${userDetails.documentId}"); - await launchUrl(Uri.parse(url)); + await launchUrl(Uri.parse(url), + mode: LaunchMode.externalApplication); }, Primary())) ]), ]); @@ -788,7 +789,8 @@ class CompleteOrganiserAccountWidget extends StatelessWidget { textAction: "GO TO STRIPE", action: () async { await launchUrl( - Uri.parse(getStripeUrl(isTest, userState.currentUserId!))); + Uri.parse(getStripeUrl(isTest, userState.currentUserId!)), + mode: LaunchMode.externalApplication); }, ); }