Skip to content

Commit

Permalink
feat: add trivia page status view variants
Browse files Browse the repository at this point in the history
  • Loading branch information
luisburgos committed Sep 22, 2022
1 parent 15d08df commit 2477420
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 5 deletions.
5 changes: 5 additions & 0 deletions example/lib/get/modules/trivia_module.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:buzz/buzz.dart';
import 'package:flutter/cupertino.dart';
import 'package:get/get.dart';

import '../../shared/modules/trivia/page.dart';
Expand Down Expand Up @@ -28,6 +29,10 @@ class TriviaRoute extends GetRoute {
onSeeScoreboardTap: (triviaId) {
Buzz.fire(NavigateToTriviaScoreboard(triviaId: triviaId));
},
onCopyJoinLinkTap: (joinLink) {
//TODO: Implement
debugPrint(joinLink);
},
),
);
}
Expand Down
77 changes: 72 additions & 5 deletions example/lib/shared/modules/trivia/page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,22 @@ import 'package:get/get.dart';
class NavigateToTrivia extends NavigateToCommand {
NavigateToTrivia({
required this.triviaId,
this.status,
}) : super(
directions: NavigationDirections(
routeBuilder: () => TriviaPage.routeName.replaceAll(
':trivia_id',
triviaId,
),
routeBuilder: () {
final routeWithId = TriviaPage.routeName.replaceAll(
':trivia_id',
triviaId,
);
return '$routeWithId?status=${status ?? 'initial'}';
},
),
);

final String triviaId;
//TODO: Make enum
String? status;
}

class TriviaPage extends StatelessWidget {
Expand All @@ -26,17 +32,78 @@ class TriviaPage extends StatelessWidget {
Key? key,
required this.onStartPlayTap,
required this.onSeeScoreboardTap,
required this.onCopyJoinLinkTap,
}) : super(key: key);

final Function(String) onStartPlayTap;
final Function(String) onSeeScoreboardTap;
final Function(String) onCopyJoinLinkTap;

@override
Widget build(BuildContext context) {
final triviaId = Get.parameters['trivia_id'] ?? '';
final status = Get.parameters['status'] ?? '';

if (status == 'started') {
return _TriviaStartedStatusPage(
triviaId: triviaId,
onStartPlayTap: onStartPlayTap,
onSeeScoreboardTap: onSeeScoreboardTap,
);
}

return _TriviaInitialStatusPage(
triviaId: triviaId,
onCopyJoinLinkTap: onCopyJoinLinkTap,
);
}
}

class _TriviaInitialStatusPage extends StatelessWidget {
const _TriviaInitialStatusPage({
Key? key,
required this.triviaId,
required this.onCopyJoinLinkTap,
}) : super(key: key);

final String triviaId;
final Function(String) onCopyJoinLinkTap;

@override
Widget build(BuildContext context) {
const joinLink = 'TODO: improve joinLink';

return BasePage(
name: '$runtimeType',
actions: [
MainAction(
label: 'Copy!',
onPressed: () {
debugPrint('$runtimeType onStartPlayTap');
onCopyJoinLinkTap(joinLink);
},
),
],
);
}
}

class _TriviaStartedStatusPage extends StatelessWidget {
const _TriviaStartedStatusPage({
Key? key,
required this.triviaId,
required this.onStartPlayTap,
required this.onSeeScoreboardTap,
}) : super(key: key);

final String triviaId;
final Function(String) onStartPlayTap;
final Function(String) onSeeScoreboardTap;

@override
Widget build(BuildContext context) {
return BasePage(
name: '$pageName – $triviaId',
name: '$runtimeType',
actions: [
MainAction(
label: 'Start play!',
Expand Down

0 comments on commit 2477420

Please sign in to comment.