From 35eaa3ed34e157c15b4883e561e05e2da55707d5 Mon Sep 17 00:00:00 2001 From: Mairon Lucas Date: Wed, 30 Oct 2024 20:02:39 -0300 Subject: [PATCH] Brazilian intl and change from "live" to "today" --- domain/lib/model/team_score.dart | 4 +- domain/lib/repository/game_repository.dart | 2 + domain/lib/use_case/get_today_games_uc.dart | 16 ++ lib/common/di.dart | 20 +- lib/common/theme/util.dart | 11 +- lib/data/remote/data_sources/game_rds.dart | 12 +- lib/data/remote/model/team_score_rm.dart | 2 +- lib/data/repository/game_repository.dart | 15 +- lib/generated/intl/messages_all.dart | 4 + lib/generated/intl/messages_en_US.dart | 5 +- lib/generated/intl/messages_pt_BR.dart | 37 +++ lib/generated/l10n.dart | 25 +- lib/l10n/intl_en_US.arb | 4 +- lib/l10n/intl_pt_BR.arb | 11 + lib/presentation/home/common/game_chip.dart | 70 ++--- lib/presentation/home/home_bloc.dart | 286 +------------------- lib/presentation/home/home_models.dart | 4 +- lib/presentation/home/home_page.dart | 40 ++- 18 files changed, 219 insertions(+), 349 deletions(-) create mode 100644 domain/lib/use_case/get_today_games_uc.dart create mode 100644 lib/generated/intl/messages_pt_BR.dart create mode 100644 lib/l10n/intl_pt_BR.arb diff --git a/domain/lib/model/team_score.dart b/domain/lib/model/team_score.dart index b219425..e17d898 100644 --- a/domain/lib/model/team_score.dart +++ b/domain/lib/model/team_score.dart @@ -2,10 +2,10 @@ class TeamScore { TeamScore({ required this.wins, required this.loses, - required this.points, + this.points, }); final int wins; final int loses; - final int points; + final int? points; } \ No newline at end of file diff --git a/domain/lib/repository/game_repository.dart b/domain/lib/repository/game_repository.dart index 78306da..d1f732e 100644 --- a/domain/lib/repository/game_repository.dart +++ b/domain/lib/repository/game_repository.dart @@ -2,4 +2,6 @@ import 'package:domain/model/game_summary.dart'; abstract class GameDataRepository { Future> getLiveGames(); + + Future> getTodayGames(); } diff --git a/domain/lib/use_case/get_today_games_uc.dart b/domain/lib/use_case/get_today_games_uc.dart new file mode 100644 index 0000000..4c95425 --- /dev/null +++ b/domain/lib/use_case/get_today_games_uc.dart @@ -0,0 +1,16 @@ +import 'package:domain/model/game_summary.dart'; +import 'package:domain/repository/game_repository.dart'; +import 'package:domain/use_case/use_case.dart'; + +class GetTodayGamesUC extends UseCase> { + GetTodayGamesUC({ + required super.errorLogger, + required GameDataRepository repository, + }) : _repository = repository; + + final GameDataRepository _repository; + + @override + Future> getRawFuture(void params) => + _repository.getTodayGames(); +} diff --git a/lib/common/di.dart b/lib/common/di.dart index 9c43770..b10a0ef 100644 --- a/lib/common/di.dart +++ b/lib/common/di.dart @@ -2,6 +2,7 @@ import 'package:dio/dio.dart'; import 'package:domain/error_logger.dart'; import 'package:domain/repository/game_repository.dart'; import 'package:domain/use_case/get_live_games_uc.dart'; +import 'package:domain/use_case/get_today_games_uc.dart'; import 'package:get_it/get_it.dart'; import 'package:nbapp/data/remote/data_sources/game_rds.dart'; import 'package:nbapp/data/remote/infraestructure/my_dio.dart'; @@ -26,12 +27,19 @@ void initRepositories() { } void initUseCases() { - getIt.registerSingleton( - GetLiveGamesUC( - errorLogger: getIt(), - repository: getIt(), - ), - ); + getIt + ..registerSingleton( + GetLiveGamesUC( + errorLogger: getIt(), + repository: getIt(), + ), + ) + ..registerSingleton( + GetTodayGamesUC( + errorLogger: getIt(), + repository: getIt(), + ), + ); } void initDataSources() { diff --git a/lib/common/theme/util.dart b/lib/common/theme/util.dart index 88e8758..32cf9d6 100644 --- a/lib/common/theme/util.dart +++ b/lib/common/theme/util.dart @@ -1,12 +1,11 @@ import 'package:flutter/material.dart'; import 'package:google_fonts/google_fonts.dart'; +import 'package:nbapp/generated/l10n.dart'; -TextTheme createTextTheme( - BuildContext context, String bodyFontString, String displayFontString) { +TextTheme createTextTheme(BuildContext context, String bodyFontString, String displayFontString) { TextTheme baseTextTheme = Theme.of(context).textTheme; TextTheme bodyTextTheme = GoogleFonts.getTextTheme(bodyFontString, baseTextTheme); - TextTheme displayTextTheme = - GoogleFonts.getTextTheme(displayFontString, baseTextTheme); + TextTheme displayTextTheme = GoogleFonts.getTextTheme(displayFontString, baseTextTheme); TextTheme textTheme = displayTextTheme.copyWith( bodyLarge: bodyTextTheme.bodyLarge, bodyMedium: bodyTextTheme.bodyMedium, @@ -17,3 +16,7 @@ TextTheme createTextTheme( ); return textTheme; } + +extension GetString on BuildContext { + S get strings => S.of(this); +} diff --git a/lib/data/remote/data_sources/game_rds.dart b/lib/data/remote/data_sources/game_rds.dart index c99a39f..5c06740 100644 --- a/lib/data/remote/data_sources/game_rds.dart +++ b/lib/data/remote/data_sources/game_rds.dart @@ -6,12 +6,14 @@ import 'package:nbapp/data/remote/model/game_summary_rm.dart'; class GameRDS { GameRDS({ required Dio dio, -}) : _dio = dio; + }) : _dio = dio; final Dio _dio; - - Future> getLiveGames() async { - final response = await _dio.get('${baseUrl}/games?date=2024-04-21'); + + Future> getGames({DateTime? date}) async { + final response = await _dio.get( + date == null ? '${baseUrl}/games?live=all' : '${baseUrl}/games?date=${date.year}-${date.month}-${date.day}', + ); if (response.statusCode == 200 || response.data == null) { final games = []; final data = response.data as Map; @@ -23,4 +25,4 @@ class GameRDS { throw BackendException(); } } -} \ No newline at end of file +} diff --git a/lib/data/remote/model/team_score_rm.dart b/lib/data/remote/model/team_score_rm.dart index cb394c9..ad5ff3c 100644 --- a/lib/data/remote/model/team_score_rm.dart +++ b/lib/data/remote/model/team_score_rm.dart @@ -12,7 +12,7 @@ class TeamScoreRM { final int win; final int loss; - final int points; + final int? points; factory TeamScoreRM.fromJson(Map json) => _$TeamScoreRMFromJson(json); diff --git a/lib/data/repository/game_repository.dart b/lib/data/repository/game_repository.dart index 99f4164..220b5c3 100644 --- a/lib/data/repository/game_repository.dart +++ b/lib/data/repository/game_repository.dart @@ -11,7 +11,20 @@ class GameRepository extends GameDataRepository { final GameRDS _gameRDS; @override - Future> getLiveGames() => _gameRDS.getLiveGames().then( + Future> getLiveGames() => _gameRDS.getGames().then( + (games) => games + .map( + (game) => game.toDM(), + ) + .toList(), + ); + + @override + Future> getTodayGames() => _gameRDS + .getGames( + date: DateTime.now(), + ) + .then( (games) => games .map( (game) => game.toDM(), diff --git a/lib/generated/intl/messages_all.dart b/lib/generated/intl/messages_all.dart index cc8ee49..8fc0dc3 100644 --- a/lib/generated/intl/messages_all.dart +++ b/lib/generated/intl/messages_all.dart @@ -17,16 +17,20 @@ import 'package:intl/message_lookup_by_library.dart'; import 'package:intl/src/intl_helpers.dart'; import 'messages_en_US.dart' as messages_en_us; +import 'messages_pt_BR.dart' as messages_pt_br; typedef Future LibraryLoader(); Map _deferredLibraries = { 'en_US': () => new SynchronousFuture(null), + 'pt_BR': () => new SynchronousFuture(null), }; MessageLookupByLibrary? _findExact(String localeName) { switch (localeName) { case 'en_US': return messages_en_us.messages; + case 'pt_BR': + return messages_pt_br.messages; default: return null; } diff --git a/lib/generated/intl/messages_en_US.dart b/lib/generated/intl/messages_en_US.dart index 5d50bc0..b1bf67b 100644 --- a/lib/generated/intl/messages_en_US.dart +++ b/lib/generated/intl/messages_en_US.dart @@ -24,7 +24,10 @@ class MessageLookup extends MessageLookupByLibrary { static Map _notInlinedMessages(_) => { "appName": MessageLookupByLibrary.simpleMessage("NBApp"), "emptyLiveGames": MessageLookupByLibrary.simpleMessage( - "There is no game being played right now.\nCome back when the season starts!"), + "There is no game being played right now.\nCome back later!"), + "emptyTodayGames": MessageLookupByLibrary.simpleMessage( + "There is no game today.\nCome back tomorrow or check the "), + "emptyTodayGamesLink": MessageLookupByLibrary.simpleMessage("schedule"), "homeOnboardingMessage": MessageLookupByLibrary.simpleMessage( "Welcome to NBApp!\nThis is the right place to follow\nthe NBA season by live games"), "liveGames": MessageLookupByLibrary.simpleMessage("Live Games"), diff --git a/lib/generated/intl/messages_pt_BR.dart b/lib/generated/intl/messages_pt_BR.dart new file mode 100644 index 0000000..5340175 --- /dev/null +++ b/lib/generated/intl/messages_pt_BR.dart @@ -0,0 +1,37 @@ +// DO NOT EDIT. This is code generated via package:intl/generate_localized.dart +// This is a library that provides messages for a pt_BR locale. All the +// messages from the main program should be duplicated here with the same +// function name. + +// Ignore issues from commonly used lints in this file. +// ignore_for_file:unnecessary_brace_in_string_interps, unnecessary_new +// ignore_for_file:prefer_single_quotes,comment_references, directives_ordering +// ignore_for_file:annotate_overrides,prefer_generic_function_type_aliases +// ignore_for_file:unused_import, file_names, avoid_escaping_inner_quotes +// ignore_for_file:unnecessary_string_interpolations, unnecessary_string_escapes + +import 'package:intl/intl.dart'; +import 'package:intl/message_lookup_by_library.dart'; + +final messages = new MessageLookup(); + +typedef String MessageIfAbsent(String messageStr, List args); + +class MessageLookup extends MessageLookupByLibrary { + String get localeName => 'pt_BR'; + + final messages = _notInlinedMessages(_notInlinedMessages); + static Map _notInlinedMessages(_) => { + "appName": MessageLookupByLibrary.simpleMessage("NBApp"), + "emptyLiveGames": MessageLookupByLibrary.simpleMessage( + "Não há nenhum jogo no momento.\nVolte mais tarde!"), + "emptyTodayGames": MessageLookupByLibrary.simpleMessage( + "Não há nenhum jogo hoje.\nVolte amanhã ou confira o "), + "emptyTodayGamesLink": + MessageLookupByLibrary.simpleMessage("calendário"), + "homeOnboardingMessage": MessageLookupByLibrary.simpleMessage( + "Bem-vindo ao NBApp!\nVocê está no lugar certo para\nacompanhar os jogos da NBA"), + "liveGames": MessageLookupByLibrary.simpleMessage("Jogos agora"), + "tryAgain": MessageLookupByLibrary.simpleMessage("Tentar novamente") + }; +} diff --git a/lib/generated/l10n.dart b/lib/generated/l10n.dart index 4e87507..692ad0a 100644 --- a/lib/generated/l10n.dart +++ b/lib/generated/l10n.dart @@ -90,15 +90,35 @@ class S { ); } - /// `There is no game being played right now.\nCome back when the season starts!` + /// `There is no game being played right now.\nCome back later!` String get emptyLiveGames { return Intl.message( - 'There is no game being played right now.\nCome back when the season starts!', + 'There is no game being played right now.\nCome back later!', name: 'emptyLiveGames', desc: '', args: [], ); } + + /// `There is no game today.\nCome back tomorrow or check the ` + String get emptyTodayGames { + return Intl.message( + 'There is no game today.\nCome back tomorrow or check the ', + name: 'emptyTodayGames', + desc: '', + args: [], + ); + } + + /// `schedule` + String get emptyTodayGamesLink { + return Intl.message( + 'schedule', + name: 'emptyTodayGamesLink', + desc: '', + args: [], + ); + } } class AppLocalizationDelegate extends LocalizationsDelegate { @@ -107,6 +127,7 @@ class AppLocalizationDelegate extends LocalizationsDelegate { List get supportedLocales { return const [ Locale.fromSubtags(languageCode: 'en', countryCode: 'US'), + Locale.fromSubtags(languageCode: 'pt', countryCode: 'BR'), ]; } diff --git a/lib/l10n/intl_en_US.arb b/lib/l10n/intl_en_US.arb index 080ec1e..398c3be 100644 --- a/lib/l10n/intl_en_US.arb +++ b/lib/l10n/intl_en_US.arb @@ -4,5 +4,7 @@ "homeOnboardingMessage": "Welcome to NBApp!\nThis is the right place to follow\nthe NBA season by live games", "liveGames": "Live Games", "tryAgain": "Try Again", - "emptyLiveGames": "There is no game being played right now.\nCome back when the season starts!" + "emptyLiveGames": "There is no game being played right now.\nCome back later!", + "emptyTodayGames": "There is no game today.\nCome back tomorrow or check the ", + "emptyTodayGamesLink": "schedule" } \ No newline at end of file diff --git a/lib/l10n/intl_pt_BR.arb b/lib/l10n/intl_pt_BR.arb new file mode 100644 index 0000000..4a73548 --- /dev/null +++ b/lib/l10n/intl_pt_BR.arb @@ -0,0 +1,11 @@ +{ + "@@locale": "pt_BR", + "appName": "NBApp", + "homeOnboardingMessage": "Bem-vindo ao NBApp!\nVocê está no lugar certo para\nacompanhar os jogos da NBA", + "liveGames": "Jogos agora", + "todayGames": "Jogos de hoje", + "tryAgain": "Tentar novamente", + "emptyLiveGames": "Não há nenhum jogo no momento.\nVolte mais tarde!", + "emptyTodayGames": "Não há nenhum jogo hoje.\nVolte amanhã ou confira o ", + "emptyTodayGamesLink": "calendário" +} \ No newline at end of file diff --git a/lib/presentation/home/common/game_chip.dart b/lib/presentation/home/common/game_chip.dart index 10eb68a..a028389 100644 --- a/lib/presentation/home/common/game_chip.dart +++ b/lib/presentation/home/common/game_chip.dart @@ -6,46 +6,54 @@ class GameChip extends StatelessWidget { required this.visitorTeamLogo, required this.homeTeamScore, required this.visitorTeamScore, + required this.date, super.key, }); final String homeTeamLogo; final String visitorTeamLogo; - final String homeTeamScore; - final String visitorTeamScore; + final int? homeTeamScore; + final int? visitorTeamScore; + final DateTime date; @override Widget build(BuildContext context) => Container( - decoration: BoxDecoration( - color: Theme.of(context).colorScheme.surfaceContainer, - borderRadius: BorderRadius.circular(8), - border: Border.all( - color: Theme.of(context).colorScheme.outline, - width: 3, - ), - ), - padding: EdgeInsets.all(4), - child: Column( - children: [ - Expanded( - child: Image.network( - homeTeamLogo, + decoration: BoxDecoration( + color: Theme.of(context).colorScheme.surfaceContainer, + borderRadius: BorderRadius.circular(8), + border: Border.all( + color: Theme.of(context).colorScheme.outline, + width: 3, ), ), - Text( - homeTeamScore, - style: Theme.of(context).textTheme.bodyMedium, + padding: EdgeInsets.all(4), + child: Column( + children: [ + Expanded( + child: Image.network( + homeTeamLogo, + ), + ), + if (homeTeamScore != null && visitorTeamScore != null) ...[ + Text( + homeTeamScore!.toString(), + style: Theme.of(context).textTheme.bodyMedium, + ), + Text( + visitorTeamScore!.toString(), + style: Theme.of(context).textTheme.bodyMedium, + ) + ] else + Text( + '${date.hour.toString().padLeft(2, '0')}:${date.minute.toString().padLeft(2, '0')}', + style: Theme.of(context).textTheme.bodyMedium, + ), + Expanded( + child: Image.network( + visitorTeamLogo, + ), + ), + ], ), - Text( - visitorTeamScore, - style: Theme.of(context).textTheme.bodyMedium, - ), - Expanded( - child: Image.network( - visitorTeamLogo, - ), - ), - ], - ), - ); + ); } diff --git a/lib/presentation/home/home_bloc.dart b/lib/presentation/home/home_bloc.dart index 90e2766..627e334 100644 --- a/lib/presentation/home/home_bloc.dart +++ b/lib/presentation/home/home_bloc.dart @@ -1,305 +1,29 @@ import 'package:bloc/bloc.dart'; -import 'package:domain/model/game_status.dart'; -import 'package:domain/model/game_summary.dart'; -import 'package:domain/model/team.dart'; -import 'package:domain/model/team_score.dart'; -import 'package:domain/use_case/get_live_games_uc.dart'; +import 'package:domain/use_case/get_today_games_uc.dart'; import 'package:nbapp/presentation/home/home_models.dart'; class HomeBloc extends Bloc { HomeBloc({ - required GetLiveGamesUC getLiveGamesUC, - }) : _getLiveGamesUC = getLiveGamesUC, + required GetTodayGamesUC getTodayGamesUC, + }) : _getTodayGamesUC = getTodayGamesUC, super(HomeLoading()) { on(_onGetLiveGames); add(GetLiveGames()); } - final GetLiveGamesUC _getLiveGamesUC; + final GetTodayGamesUC _getTodayGamesUC; Future _onGetLiveGames( GetLiveGames event, Emitter emitter, ) async { - final useMock = true; emitter(HomeLoading()); try { await Future.delayed(Duration(seconds: 2)); emitter( HomeSuccess( - liveGames: !useMock - ? (await _getLiveGamesUC.getFuture(null)) - : [ - GameSummary( - date: DateTime.now(), - period: 1, - gameStatus: GameStatus( - isFinished: false, - isHalfTime: false, - ), - id: '123', - arenaName: 'Crypto Arena', - homeTeam: Team( - id: 'hasd', - name: 'Los Angeles Lakers', - nickName: 'Lakers', - code: 'LKR', - logoUrl: - 'https://upload.wikimedia.org/wikipedia/commons/thumb/3/3c/Los_Angeles_Lakers_logo.svg/220px-Los_Angeles_Lakers_logo.svg.png'), - visitorTeam: Team( - id: 'hasd', - name: 'Boston Celtics', - nickName: 'Celtics', - code: 'BCS', - logoUrl: - 'https://upload.wikimedia.org/wikipedia/fr/thumb/6/65/Celtics_de_Boston_logo.svg/1024px-Celtics_de_Boston_logo.svg.png'), - homeTeamScore: TeamScore( - wins: 10, - loses: 5, - points: 27, - ), - visitorTeamScore: TeamScore( - wins: 13, - loses: 2, - points: 33, - ), - ), - GameSummary( - date: DateTime.now(), - period: 4, - gameStatus: GameStatus( - isFinished: false, - isHalfTime: false, - ), - id: '123', - arenaName: 'Crypto Arena', - homeTeam: Team( - id: 'hasd', - name: 'Atlanta Hawks', - nickName: 'Lakers', - code: 'LKR', - logoUrl: 'https://upload.wikimedia.org/wikipedia/fr/e/ee/Hawks_2016.png'), - visitorTeam: Team( - id: 'hasd', - name: 'Boston Celtics', - nickName: 'Celtics', - code: 'BCS', - logoUrl: - 'https://upload.wikimedia.org/wikipedia/commons/thumb/4/44/Brooklyn_Nets_newlogo.svg/130px-Brooklyn_Nets_newlogo.svg.png'), - homeTeamScore: TeamScore( - wins: 10, - loses: 5, - points: 120, - ), - visitorTeamScore: TeamScore( - wins: 13, - loses: 2, - points: 100, - ), - ), - GameSummary( - date: DateTime.now(), - period: 1, - gameStatus: GameStatus( - isFinished: false, - isHalfTime: false, - ), - id: '123', - arenaName: 'Crypto Arena', - homeTeam: Team( - id: 'hasd', - name: 'Los Angeles Lakers', - nickName: 'Lakers', - code: 'LKR', - logoUrl: - 'https://upload.wikimedia.org/wikipedia/commons/thumb/3/3c/Los_Angeles_Lakers_logo.svg/220px-Los_Angeles_Lakers_logo.svg.png'), - visitorTeam: Team( - id: 'hasd', - name: 'Boston Celtics', - nickName: 'Celtics', - code: 'BCS', - logoUrl: - 'https://upload.wikimedia.org/wikipedia/fr/thumb/6/65/Celtics_de_Boston_logo.svg/1024px-Celtics_de_Boston_logo.svg.png'), - homeTeamScore: TeamScore( - wins: 10, - loses: 5, - points: 27, - ), - visitorTeamScore: TeamScore( - wins: 13, - loses: 2, - points: 33, - ), - ), - GameSummary( - date: DateTime.now(), - period: 4, - gameStatus: GameStatus( - isFinished: false, - isHalfTime: false, - ), - id: '123', - arenaName: 'Crypto Arena', - homeTeam: Team( - id: 'hasd', - name: 'Atlanta Hawks', - nickName: 'Lakers', - code: 'LKR', - logoUrl: 'https://upload.wikimedia.org/wikipedia/fr/e/ee/Hawks_2016.png'), - visitorTeam: Team( - id: 'hasd', - name: 'Boston Celtics', - nickName: 'Celtics', - code: 'BCS', - logoUrl: - 'https://upload.wikimedia.org/wikipedia/commons/thumb/4/44/Brooklyn_Nets_newlogo.svg/130px-Brooklyn_Nets_newlogo.svg.png'), - homeTeamScore: TeamScore( - wins: 10, - loses: 5, - points: 120, - ), - visitorTeamScore: TeamScore( - wins: 13, - loses: 2, - points: 100, - ), - ), - GameSummary( - date: DateTime.now(), - period: 1, - gameStatus: GameStatus( - isFinished: false, - isHalfTime: false, - ), - id: '123', - arenaName: 'Crypto Arena', - homeTeam: Team( - id: 'hasd', - name: 'Los Angeles Lakers', - nickName: 'Lakers', - code: 'LKR', - logoUrl: - 'https://upload.wikimedia.org/wikipedia/commons/thumb/3/3c/Los_Angeles_Lakers_logo.svg/220px-Los_Angeles_Lakers_logo.svg.png'), - visitorTeam: Team( - id: 'hasd', - name: 'Boston Celtics', - nickName: 'Celtics', - code: 'BCS', - logoUrl: - 'https://upload.wikimedia.org/wikipedia/fr/thumb/6/65/Celtics_de_Boston_logo.svg/1024px-Celtics_de_Boston_logo.svg.png'), - homeTeamScore: TeamScore( - wins: 10, - loses: 5, - points: 27, - ), - visitorTeamScore: TeamScore( - wins: 13, - loses: 2, - points: 33, - ), - ), - GameSummary( - date: DateTime.now(), - period: 4, - gameStatus: GameStatus( - isFinished: false, - isHalfTime: false, - ), - id: '123', - arenaName: 'Crypto Arena', - homeTeam: Team( - id: 'hasd', - name: 'Atlanta Hawks', - nickName: 'Lakers', - code: 'LKR', - logoUrl: 'https://upload.wikimedia.org/wikipedia/fr/e/ee/Hawks_2016.png'), - visitorTeam: Team( - id: 'hasd', - name: 'Boston Celtics', - nickName: 'Celtics', - code: 'BCS', - logoUrl: - 'https://upload.wikimedia.org/wikipedia/commons/thumb/4/44/Brooklyn_Nets_newlogo.svg/130px-Brooklyn_Nets_newlogo.svg.png'), - homeTeamScore: TeamScore( - wins: 10, - loses: 5, - points: 120, - ), - visitorTeamScore: TeamScore( - wins: 13, - loses: 2, - points: 100, - ), - ), - GameSummary( - date: DateTime.now(), - period: 1, - gameStatus: GameStatus( - isFinished: false, - isHalfTime: false, - ), - id: '123', - arenaName: 'Crypto Arena', - homeTeam: Team( - id: 'hasd', - name: 'Los Angeles Lakers', - nickName: 'Lakers', - code: 'LKR', - logoUrl: - 'https://upload.wikimedia.org/wikipedia/commons/thumb/3/3c/Los_Angeles_Lakers_logo.svg/220px-Los_Angeles_Lakers_logo.svg.png'), - visitorTeam: Team( - id: 'hasd', - name: 'Boston Celtics', - nickName: 'Celtics', - code: 'BCS', - logoUrl: - 'https://upload.wikimedia.org/wikipedia/fr/thumb/6/65/Celtics_de_Boston_logo.svg/1024px-Celtics_de_Boston_logo.svg.png'), - homeTeamScore: TeamScore( - wins: 10, - loses: 5, - points: 27, - ), - visitorTeamScore: TeamScore( - wins: 13, - loses: 2, - points: 33, - ), - ), - GameSummary( - date: DateTime.now(), - period: 4, - gameStatus: GameStatus( - isFinished: false, - isHalfTime: false, - ), - id: '123', - arenaName: 'Crypto Arena', - homeTeam: Team( - id: 'hasd', - name: 'Atlanta Hawks', - nickName: 'Lakers', - code: 'LKR', - logoUrl: 'https://upload.wikimedia.org/wikipedia/fr/e/ee/Hawks_2016.png'), - visitorTeam: Team( - id: 'hasd', - name: 'Boston Celtics', - nickName: 'Celtics', - code: 'BCS', - logoUrl: - 'https://upload.wikimedia.org/wikipedia/commons/thumb/4/44/Brooklyn_Nets_newlogo.svg/130px-Brooklyn_Nets_newlogo.svg.png'), - homeTeamScore: TeamScore( - wins: 10, - loses: 5, - points: 120, - ), - visitorTeamScore: TeamScore( - wins: 13, - loses: 2, - points: 100, - ), - ), - ], + todayGames: await _getTodayGamesUC.getFuture(null), ), ); } catch (e) { diff --git a/lib/presentation/home/home_models.dart b/lib/presentation/home/home_models.dart index 61c2551..6d528ba 100644 --- a/lib/presentation/home/home_models.dart +++ b/lib/presentation/home/home_models.dart @@ -6,10 +6,10 @@ class HomeLoading extends HomeState {} class HomeSuccess extends HomeState { HomeSuccess({ - required this.liveGames, + required this.todayGames, }); - final List liveGames; + final List todayGames; } class HomeError extends HomeState {} diff --git a/lib/presentation/home/home_page.dart b/lib/presentation/home/home_page.dart index f8be6be..f88946b 100644 --- a/lib/presentation/home/home_page.dart +++ b/lib/presentation/home/home_page.dart @@ -1,9 +1,10 @@ import 'package:carousel_slider/carousel_slider.dart'; -import 'package:domain/use_case/get_live_games_uc.dart'; +import 'package:domain/use_case/get_today_games_uc.dart'; +import 'package:flutter/gestures.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:get_it/get_it.dart'; -import 'package:nbapp/generated/l10n.dart'; +import 'package:nbapp/common/theme/util.dart'; import 'package:nbapp/presentation/home/common/game_chip.dart'; import 'package:nbapp/presentation/home/home_bloc.dart'; import 'package:nbapp/presentation/home/home_models.dart'; @@ -16,21 +17,21 @@ class HomePage extends StatelessWidget { @override Widget build(BuildContext context) => Scaffold( appBar: AppBar( - title: Text(S.of(context).appName), + title: Text(context.strings.appName), ), body: Padding( padding: EdgeInsets.symmetric(horizontal: 16), child: Column( children: [ Text( - S.of(context).homeOnboardingMessage, + context.strings.homeOnboardingMessage, style: Theme.of(context).textTheme.bodyLarge, textAlign: TextAlign.center, ), SizedBox(height: 16), BlocProvider( create: (context) => HomeBloc( - getLiveGamesUC: GetIt.instance.get(), + getTodayGamesUC: GetIt.instance.get(), ), child: BlocBuilder( builder: (context, state) => switch (state) { @@ -39,29 +40,44 @@ class HomePage extends StatelessWidget { ), HomeError() => Center( child: Text( - S.of(context).tryAgain, + context.strings.tryAgain, style: TextStyle( color: Theme.of(context).colorScheme.error, ), ), ), - HomeSuccess() => state.liveGames.isEmpty + HomeSuccess() => state.todayGames.isEmpty ? Center( - child: Text( - S.of(context).emptyLiveGames, + child: RichText( + text: TextSpan( + text: context.strings.emptyTodayGames, + children: [ + TextSpan( + text: context.strings.emptyTodayGamesLink, + style: TextStyle( + color: Theme.of(context).colorScheme.primary, + ), + recognizer: TapGestureRecognizer() + ..onTap = () { + // TODO(Mairon): Go to schedule + }, + ), + ], + ), textAlign: TextAlign.center, ), ) : CarouselSlider( - items: state.liveGames + items: state.todayGames .map( (game) => Padding( padding: const EdgeInsets.symmetric(horizontal: 4), child: GameChip( homeTeamLogo: game.homeTeam.logoUrl, visitorTeamLogo: game.visitorTeam.logoUrl, - homeTeamScore: game.homeTeamScore.points.toString(), - visitorTeamScore: game.visitorTeamScore.points.toString(), + homeTeamScore: game.homeTeamScore.points, + visitorTeamScore: game.visitorTeamScore.points, + date: game.date.toLocal(), ), ), )