From 6a973b3028e9d747345d3d7889b98134332e159a Mon Sep 17 00:00:00 2001 From: Luis Burgos Date: Fri, 23 Sep 2022 21:10:10 -0500 Subject: [PATCH] feat: add trivia page view components --- buzz.yml | 4 ++ example/lib/shared/app_routes.dart | 4 ++ .../components/copy_join_link_view.dart | 41 +++++++++++++++ .../trivia/components/trivia_data_view.dart | 50 +++++++++++++++++++ example/lib/shared/modules/trivia/page.dart | 30 +++++++---- .../packages/core/lib/data_model_access.dart | 1 + example/packages/core/lib/src/named_page.dart | 8 +-- example/test/trivia_data_view_test.dart | 41 +++++++++++++++ 8 files changed, 166 insertions(+), 13 deletions(-) create mode 100644 example/lib/shared/modules/trivia/components/copy_join_link_view.dart create mode 100644 example/lib/shared/modules/trivia/components/trivia_data_view.dart create mode 100644 example/packages/core/lib/data_model_access.dart create mode 100644 example/test/trivia_data_view_test.dart diff --git a/buzz.yml b/buzz.yml index d5a2e88..6dfc592 100644 --- a/buzz.yml +++ b/buzz.yml @@ -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: "" diff --git a/example/lib/shared/app_routes.dart b/example/lib/shared/app_routes.dart index db3ce35..4ca4b24 100644 --- a/example/lib/shared/app_routes.dart +++ b/example/lib/shared/app_routes.dart @@ -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; @@ -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'; } diff --git a/example/lib/shared/modules/trivia/components/copy_join_link_view.dart b/example/lib/shared/modules/trivia/components/copy_join_link_view.dart new file mode 100644 index 0000000..df241c0 --- /dev/null +++ b/example/lib/shared/modules/trivia/components/copy_join_link_view.dart @@ -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); + }, + ), + ), + ], + ); + } +} diff --git a/example/lib/shared/modules/trivia/components/trivia_data_view.dart b/example/lib/shared/modules/trivia/components/trivia_data_view.dart new file mode 100644 index 0000000..04f6ca2 --- /dev/null +++ b/example/lib/shared/modules/trivia/components/trivia_data_view.dart @@ -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), + ), + ); + } +} diff --git a/example/lib/shared/modules/trivia/page.dart b/example/lib/shared/modules/trivia/page.dart index eb86ea3..f8b4a86 100644 --- a/example/lib/shared/modules/trivia/page.dart +++ b/example/lib/shared/modules/trivia/page.dart @@ -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, @@ -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. + }, + ), + ], + ), ); } } diff --git a/example/packages/core/lib/data_model_access.dart b/example/packages/core/lib/data_model_access.dart new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/example/packages/core/lib/data_model_access.dart @@ -0,0 +1 @@ + diff --git a/example/packages/core/lib/src/named_page.dart b/example/packages/core/lib/src/named_page.dart index 9a26c9f..25e707a 100644 --- a/example/packages/core/lib/src/named_page.dart +++ b/example/packages/core/lib/src/named_page.dart @@ -32,7 +32,7 @@ class BasePage extends StatelessWidget { if (actions.isNotEmpty) { actionWidgets = actions .map( - (action) => _MainActionWidget(action: action), + (action) => MainActionWidget(action: action), ) .toList(); } @@ -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, ], ), @@ -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); diff --git a/example/test/trivia_data_view_test.dart b/example/test/trivia_data_view_test.dart new file mode 100644 index 0000000..79656ab --- /dev/null +++ b/example/test/trivia_data_view_test.dart @@ -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); + }); +}