Skip to content

Commit

Permalink
use external browser
Browse files Browse the repository at this point in the history
  • Loading branch information
alexlipa91 committed Nov 5, 2023
1 parent 6479cad commit 0340edd
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 53 deletions.
103 changes: 59 additions & 44 deletions lib/screens/BottomBarMatch.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<MatchesState>().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<UserState>().getLoggedUserDetails());
var isGoing =
match.isUserGoing(context.read<UserState>().getLoggedUserDetails());

var bottomBar;

Expand All @@ -47,8 +46,8 @@ class BottomBarMatch extends StatelessWidget {
break;
case MatchStatus.to_rate:
if (isGoing) {
var stillToVote = context.read<MatchesState>()
.getStillToVote(matchId, context.read<UserState>().currentUserId!);
var stillToVote = context.read<MatchesState>().getStillToVote(
matchId, context.read<UserState>().currentUserId!);
if (stillToVote != null && stillToVote.isNotEmpty)
bottomBar = RatePlayersBottomBar(matchId: matchId);
}
Expand All @@ -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) {
Expand All @@ -96,8 +100,7 @@ class BottomBarMatch extends StatelessWidget {
],
),
),
if (button != null)
button!
if (button != null) button!
],
),
));
Expand Down Expand Up @@ -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) {
Expand All @@ -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<MatchesState>().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<MatchesState>().getStillToVote(
matchId,
context.read<UserState>().currentUserId!)!.length.toString() +
" players left",
button: RateButton(matchId: matchId)
);
subText: context
.watch<MatchesState>()
.getStillToVote(
matchId, context.read<UserState>().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<UserState>();

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))));
}
}
20 changes: 11 additions & 9 deletions lib/screens/UserPage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ class UserPageState extends State<UserPage> {
});
try {
await UserController.updloadPicture(
context, userDetails!);
context, userDetails);
} catch (e, s) {
print(e);
print(s);
Expand Down Expand Up @@ -188,7 +188,7 @@ class UserPageState extends State<UserPage> {
});
try {
await UserController.updloadPicture(
context, userDetails!);
context, userDetails);
} catch (e, s) {
print(e);
print(s);
Expand All @@ -211,7 +211,7 @@ class UserPageState extends State<UserPage> {
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)
Expand Down Expand Up @@ -246,7 +246,7 @@ class UserPageState extends State<UserPage> {
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)
Expand All @@ -255,7 +255,7 @@ class UserPageState extends State<UserPage> {
child: UserInfoBox(
content: (userDetails.numDraw ?? 0).toString(),
description:
AppLocalizations.of(context)!.numMatchesDrawBoxTitle)),
AppLocalizations.of(context)!.numMatchesDrawBoxTitle)),
SizedBox(width: 20),
Expanded(
child: UserInfoBox(
Expand Down Expand Up @@ -375,10 +375,11 @@ class UserPageState extends State<UserPage> {
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()))
]),
]);
Expand Down Expand Up @@ -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);
},
);
}
Expand Down

0 comments on commit 0340edd

Please sign in to comment.