Skip to content

Commit

Permalink
HomeBloc, intl and some mappers fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
MaironLucas committed Jul 30, 2024
1 parent 72d202e commit 866d3a7
Show file tree
Hide file tree
Showing 18 changed files with 515 additions and 154 deletions.
2 changes: 1 addition & 1 deletion lib/data/mapper/game_summary_mapper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ extension GameSummaryRMtoDM on GameSummaryRM {
date: DateTime.parse(date.start),
period: periods.current,
gameStatus: status.toDM(),
id: id,
id: id.toString(),
arenaName: arena.name,
homeTeam: teams.home.toDM(),
visitorTeam: teams.visitors.toDM(),
Expand Down
2 changes: 1 addition & 1 deletion lib/data/mapper/team_mapper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import 'package:nbapp/data/remote/model/team_rm.dart';

extension TeamMapper on TeamRM {
Team toDM() => Team(
id: id,
id: id.toString(),
name: name,
code: code,
logoUrl: logo,
Expand Down
2 changes: 1 addition & 1 deletion lib/data/remote/data_sources/game_rds.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class GameRDS {
final Dio _dio;

Future<List<GameSummaryRM>> getLiveGames() async {
final response = await _dio.get('${baseUrl}/games?live=all');
final response = await _dio.get('${baseUrl}/games?date=2024-04-21');
if (response.statusCode == 200 || response.data == null) {
final games = <GameSummaryRM>[];
final data = response.data as Map<String, dynamic>;
Expand Down
2 changes: 1 addition & 1 deletion lib/data/remote/model/arena_rm.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class ArenaRM {
final String city;
final String name;
final String state;
final String country;
final String? country;

factory ArenaRM.fromJson(Map<String, dynamic> json) =>
_$ArenaRMFromJson(json);
Expand Down
4 changes: 2 additions & 2 deletions lib/data/remote/model/date_rm.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ class DateRM {
);

final String start;
final String end;
final String duration;
final String? end;
final String? duration;

factory DateRM.fromJson(Map<String, dynamic> json) => _$DateRMFromJson(json);
}
2 changes: 1 addition & 1 deletion lib/data/remote/model/game_summary_rm.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class GameSummaryRM {
this.scores,
);

final String id;
final int id;
final DateRM date;
final GameStatusRM status;
final PeriodsRM periods;
Expand Down
2 changes: 1 addition & 1 deletion lib/data/remote/model/team_rm.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class TeamRM {
this.logo,
);

final String id;
final int id;
final String name;
final String nickname;
final String code;
Expand Down
63 changes: 63 additions & 0 deletions lib/generated/intl/messages_all.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// DO NOT EDIT. This is code generated via package:intl/generate_localized.dart
// This is a library that looks up messages for specific locales by
// delegating to the appropriate library.

// Ignore issues from commonly used lints in this file.
// ignore_for_file:implementation_imports, file_names, unnecessary_new
// ignore_for_file:unnecessary_brace_in_string_interps, directives_ordering
// ignore_for_file:argument_type_not_assignable, invalid_assignment
// ignore_for_file:prefer_single_quotes, prefer_generic_function_type_aliases
// ignore_for_file:comment_references

import 'dart:async';

import 'package:flutter/foundation.dart';
import 'package:intl/intl.dart';
import 'package:intl/message_lookup_by_library.dart';
import 'package:intl/src/intl_helpers.dart';

import 'messages_en_US.dart' as messages_en_us;

typedef Future<dynamic> LibraryLoader();
Map<String, LibraryLoader> _deferredLibraries = {
'en_US': () => new SynchronousFuture(null),
};

MessageLookupByLibrary? _findExact(String localeName) {
switch (localeName) {
case 'en_US':
return messages_en_us.messages;
default:
return null;
}
}

/// User programs should call this before using [localeName] for messages.
Future<bool> initializeMessages(String localeName) {
var availableLocale = Intl.verifiedLocale(
localeName, (locale) => _deferredLibraries[locale] != null,
onFailure: (_) => null);
if (availableLocale == null) {
return new SynchronousFuture(false);
}
var lib = _deferredLibraries[availableLocale];
lib == null ? new SynchronousFuture(false) : lib();
initializeInternalMessageLookup(() => new CompositeMessageLookup());
messageLookup.addLocale(availableLocale, _findGeneratedMessagesFor);
return new SynchronousFuture(true);
}

bool _messagesExistFor(String locale) {
try {
return _findExact(locale) != null;
} catch (e) {
return false;
}
}

MessageLookupByLibrary? _findGeneratedMessagesFor(String locale) {
var actualLocale =
Intl.verifiedLocale(locale, _messagesExistFor, onFailure: (_) => null);
if (actualLocale == null) return null;
return _findExact(actualLocale);
}
33 changes: 33 additions & 0 deletions lib/generated/intl/messages_en_US.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// DO NOT EDIT. This is code generated via package:intl/generate_localized.dart
// This is a library that provides messages for a en_US 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 => 'en_US';

final messages = _notInlinedMessages(_notInlinedMessages);
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!"),
"homeOnboardingMessage": MessageLookupByLibrary.simpleMessage(
"Welcome to NBApp!\nThis is the right place to follow\nthe NBA season by live games"),
"liveGames": MessageLookupByLibrary.simpleMessage("Live Games"),
"tryAgain": MessageLookupByLibrary.simpleMessage("Try Again")
};
}
128 changes: 128 additions & 0 deletions lib/generated/l10n.dart

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

8 changes: 8 additions & 0 deletions lib/l10n/intl_en_US.arb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"@@locale": "en_US",
"appName": "NBApp",
"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!"
}
9 changes: 9 additions & 0 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import 'dart:async';

import 'package:flutter/material.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:logger/logger.dart';
import 'package:nbapp/common/di.dart';
import 'package:nbapp/common/routing/routing.dart';
import 'package:nbapp/common/theme/theme.dart';
import 'package:nbapp/common/theme/util.dart';
import 'package:nbapp/generated/l10n.dart';

class Log {
Logger logger = Logger(printer: PrettyPrinter());
Expand Down Expand Up @@ -46,6 +48,13 @@ class _MyApp extends StatelessWidget {
return MaterialApp.router(
title: 'NBApp',
debugShowCheckedModeBanner: false,
localizationsDelegates: const [
S.delegate,
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
],
supportedLocales: S.delegate.supportedLocales,
theme: theme.dark(),
routerConfig: appRoutes,
);
Expand Down
Loading

0 comments on commit 866d3a7

Please sign in to comment.