Skip to content

Commit

Permalink
Brazilian intl and change from "live" to "today"
Browse files Browse the repository at this point in the history
  • Loading branch information
MaironLucas committed Oct 30, 2024
1 parent db7b5e1 commit 35eaa3e
Show file tree
Hide file tree
Showing 18 changed files with 219 additions and 349 deletions.
4 changes: 2 additions & 2 deletions domain/lib/model/team_score.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
2 changes: 2 additions & 0 deletions domain/lib/repository/game_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@ import 'package:domain/model/game_summary.dart';

abstract class GameDataRepository {
Future<List<GameSummary>> getLiveGames();

Future<List<GameSummary>> getTodayGames();
}
16 changes: 16 additions & 0 deletions domain/lib/use_case/get_today_games_uc.dart
Original file line number Diff line number Diff line change
@@ -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<void, List<GameSummary>> {
GetTodayGamesUC({
required super.errorLogger,
required GameDataRepository repository,
}) : _repository = repository;

final GameDataRepository _repository;

@override
Future<List<GameSummary>> getRawFuture(void params) =>
_repository.getTodayGames();
}
20 changes: 14 additions & 6 deletions lib/common/di.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -26,12 +27,19 @@ void initRepositories() {
}

void initUseCases() {
getIt.registerSingleton<GetLiveGamesUC>(
GetLiveGamesUC(
errorLogger: getIt<ErrorLogger>(),
repository: getIt<GameDataRepository>(),
),
);
getIt
..registerSingleton(
GetLiveGamesUC(
errorLogger: getIt<ErrorLogger>(),
repository: getIt<GameDataRepository>(),
),
)
..registerSingleton(
GetTodayGamesUC(
errorLogger: getIt<ErrorLogger>(),
repository: getIt<GameDataRepository>(),
),
);
}

void initDataSources() {
Expand Down
11 changes: 7 additions & 4 deletions lib/common/theme/util.dart
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -17,3 +16,7 @@ TextTheme createTextTheme(
);
return textTheme;
}

extension GetString on BuildContext {
S get strings => S.of(this);
}
12 changes: 7 additions & 5 deletions lib/data/remote/data_sources/game_rds.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<List<GameSummaryRM>> getLiveGames() async {
final response = await _dio.get('${baseUrl}/games?date=2024-04-21');

Future<List<GameSummaryRM>> 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 = <GameSummaryRM>[];
final data = response.data as Map<String, dynamic>;
Expand All @@ -23,4 +25,4 @@ class GameRDS {
throw BackendException();
}
}
}
}
2 changes: 1 addition & 1 deletion lib/data/remote/model/team_score_rm.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class TeamScoreRM {

final int win;
final int loss;
final int points;
final int? points;

factory TeamScoreRM.fromJson(Map<String, dynamic> json) =>
_$TeamScoreRMFromJson(json);
Expand Down
15 changes: 14 additions & 1 deletion lib/data/repository/game_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,20 @@ class GameRepository extends GameDataRepository {
final GameRDS _gameRDS;

@override
Future<List<GameSummary>> getLiveGames() => _gameRDS.getLiveGames().then(
Future<List<GameSummary>> getLiveGames() => _gameRDS.getGames().then(
(games) => games
.map(
(game) => game.toDM(),
)
.toList(),
);

@override
Future<List<GameSummary>> getTodayGames() => _gameRDS
.getGames(
date: DateTime.now(),
)
.then(
(games) => games
.map(
(game) => game.toDM(),
Expand Down
4 changes: 4 additions & 0 deletions lib/generated/intl/messages_all.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<dynamic> LibraryLoader();
Map<String, LibraryLoader> _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;
}
Expand Down
5 changes: 4 additions & 1 deletion lib/generated/intl/messages_en_US.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ class MessageLookup extends MessageLookupByLibrary {
static Map<String, Function> _notInlinedMessages(_) => <String, Function>{
"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"),
Expand Down
37 changes: 37 additions & 0 deletions lib/generated/intl/messages_pt_BR.dart
Original file line number Diff line number Diff line change
@@ -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<dynamic> args);

class MessageLookup extends MessageLookupByLibrary {
String get localeName => 'pt_BR';

final messages = _notInlinedMessages(_notInlinedMessages);
static Map<String, Function> _notInlinedMessages(_) => <String, Function>{
"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")
};
}
25 changes: 23 additions & 2 deletions lib/generated/l10n.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion lib/l10n/intl_en_US.arb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
11 changes: 11 additions & 0 deletions lib/l10n/intl_pt_BR.arb
Original file line number Diff line number Diff line change
@@ -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"
}
70 changes: 39 additions & 31 deletions lib/presentation/home/common/game_chip.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
),
),
],
),
);
);
}
Loading

0 comments on commit 35eaa3e

Please sign in to comment.