Skip to content

Commit

Permalink
feat: add trivia page view components
Browse files Browse the repository at this point in the history
  • Loading branch information
luisburgos committed Sep 24, 2022
1 parent 97783f3 commit 6a973b3
Show file tree
Hide file tree
Showing 8 changed files with 166 additions and 13 deletions.
4 changes: 4 additions & 0 deletions buzz.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,7 @@ buzz:
page_name: "trivia_play_page"
- path: "/scoreboard"
page_name: "trivia_scoreboard_page"
- name: "join"
initial_route: ""
- name: "profile"
initial_route: ""
4 changes: 4 additions & 0 deletions example/lib/shared/app_routes.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import 'modules/trivia/play/page.dart';
import 'modules/trivia/scoreboard/page.dart';

class AppRoutes {
// Home can display Authentication info
// Authentication depends on User information and Sessions
static const root = HomePage.routeName;
static const newTrivia = NewTriviaPage.routeName;
static const trivia = TriviaPage.routeName;
Expand All @@ -14,5 +16,7 @@ class AppRoutes {
static const join = JoinPage.routeName;

static const profileRoot = '/profile';
static const profileEdit = '/profile/edit';
static const profileSettings = '/profile/settings';
static const notFound = '/not-found';
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import 'package:core/core.dart';
import 'package:flutter/material.dart';

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

final String joinLink;
final Function(String) onCopyJoinLinkTap;

@override
Widget build(BuildContext context) {
return Column(
children: [
Container(
decoration: BoxDecoration(
border: Border.all(
color: const Color.fromARGB(255, 51, 204, 255),
width: 1,
),
borderRadius: BorderRadius.circular(5),
shape: BoxShape.rectangle,
),
child: Text(joinLink),
),
MainActionWidget(
action: MainAction(
label: 'Copy!',
onPressed: () {
debugPrint('$runtimeType onStartPlayTap');
onCopyJoinLinkTap(joinLink);
},
),
),
],
);
}
}
50 changes: 50 additions & 0 deletions example/lib/shared/modules/trivia/components/trivia_data_view.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import 'package:flutter/material.dart';

class TriviaDataView extends StatelessWidget {
const TriviaDataView({
Key? key,
required this.hostName,
required this.triviaName,
required this.triviaDescription,
required this.triviaMainQuestion,
}) : super(key: key);

final String hostName;
final String triviaName;
final String triviaDescription;
final String triviaMainQuestion;

@override
Widget build(BuildContext context) {
return Column(
children: [
_TriviaDataViewLabel(hostName),
_TriviaDataViewLabel(triviaName),
_TriviaDataViewLabel(triviaDescription),
_TriviaDataViewLabel(triviaMainQuestion),
],
);
}
}

class _TriviaDataViewLabel extends StatelessWidget {
const _TriviaDataViewLabel(
this.content, {
Key? key,
}) : super(key: key);

final String content;

@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.symmetric(
vertical: 16,
horizontal: 20,
),
child: Center(
child: Text(content),
),
);
}
}
30 changes: 21 additions & 9 deletions example/lib/shared/modules/trivia/page.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import 'package:buzz/buzz.dart';
import 'package:core/core.dart';
import 'package:example/shared/modules/trivia/components/trivia_data_view.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';

import 'components/copy_join_link_view.dart';

class NavigateToTrivia extends NavigateToCommand {
NavigateToTrivia({
required this.triviaId,
Expand Down Expand Up @@ -82,15 +85,24 @@ class _TriviaInitialStatusPage extends StatelessWidget {

return BasePage(
name: '$runtimeType',
actions: [
MainAction(
label: 'Copy!',
onPressed: () {
debugPrint('$runtimeType onStartPlayTap');
onCopyJoinLinkTap(joinLink);
},
),
],
body: Column(
children: [
const SizedBox(height: 50),
const TriviaDataView(
hostName: 'hostName',
triviaName: 'triviaName',
triviaDescription: 'triviaDescription',
triviaMainQuestion: 'triviaMainQuestion',
),
const Spacer(),
CopyJoinLinkView(
joinLink: joinLink,
onCopyJoinLinkTap: (joinLink) {
//TODO: Implement.
},
),
],
),
);
}
}
Expand Down
1 change: 1 addition & 0 deletions example/packages/core/lib/data_model_access.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

8 changes: 4 additions & 4 deletions example/packages/core/lib/src/named_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class BasePage extends StatelessWidget {
if (actions.isNotEmpty) {
actionWidgets = actions
.map(
(action) => _MainActionWidget(action: action),
(action) => MainActionWidget(action: action),
)
.toList();
}
Expand All @@ -59,7 +59,7 @@ class BasePage extends StatelessWidget {
children: [
Text(name),
if (body != null) Expanded(child: body!),
if (action != null) _MainActionWidget(action: action!),
if (action != null) MainActionWidget(action: action!),
...actionWidgets,
],
),
Expand All @@ -68,8 +68,8 @@ class BasePage extends StatelessWidget {
}
}

class _MainActionWidget extends StatelessWidget {
const _MainActionWidget({
class MainActionWidget extends StatelessWidget {
const MainActionWidget({
Key? key,
required this.action,
}) : super(key: key);
Expand Down
41 changes: 41 additions & 0 deletions example/test/trivia_data_view_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import 'package:example/shared/modules/trivia/components/trivia_data_view.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';

void main() {
testWidgets('TriviaDataView test1', (tester) async {
// Given
await tester.pumpWidget(
const Directionality(
textDirection: TextDirection.ltr,
child: MediaQuery(
data: MediaQueryData(),
child: TriviaDataView(
hostName: 'Luis',
triviaName: 'High school times',
triviaDescription:
'Search the song on the Spotify app, and paste the share link!',
triviaMainQuestion:
'What is that song that reminds you of high school times?',
),
),
),
);

// When
final hostNameFinder = find.text('Luis');
final nameFinder = find.text('High school times');
final descriptionFinder = find.text(
'Search the song on the Spotify app, and paste the share link!',
);
final questionFinder = find.text(
'What is that song that reminds you of high school times?',
);

// Then
expect(hostNameFinder, findsOneWidget);
expect(nameFinder, findsOneWidget);
expect(descriptionFinder, findsOneWidget);
expect(questionFinder, findsOneWidget);
});
}

0 comments on commit 6a973b3

Please sign in to comment.