Skip to content

Commit

Permalink
localization updates and fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
hectorAguero committed Apr 16, 2024
1 parent 291145c commit f4ad834
Show file tree
Hide file tree
Showing 31 changed files with 494 additions and 121 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,6 @@ app.*.map.json
/android/app/debug
/android/app/profile
/android/app/release

# Until I change the config for dev and release
web/flutter_bootstrap.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'package:flutter/material.dart';

class AnimatedLinearGradient extends StatefulWidget {
const AnimatedLinearGradient({
class AppAnimatedLinearGradient extends StatefulWidget {
const AppAnimatedLinearGradient({
required this.colors,
required this.child,
this.begin = Alignment.topLeft,
Expand All @@ -16,10 +16,11 @@ class AnimatedLinearGradient extends StatefulWidget {
final Alignment end;

@override
State<AnimatedLinearGradient> createState() => _AnimatedLinearGradientState();
State<AppAnimatedLinearGradient> createState() =>
_AppAnimatedLinearGradientState();
}

class _AnimatedLinearGradientState extends State<AnimatedLinearGradient>
class _AppAnimatedLinearGradientState extends State<AppAnimatedLinearGradient>
with SingleTickerProviderStateMixin {
late AnimationController _controller;
late Animation<double> _animation;
Expand Down
54 changes: 54 additions & 0 deletions lib/common_widgets/app_animation_wrapper.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import 'package:flutter/material.dart';

class AppAnimationWrapper extends StatefulWidget {
const AppAnimationWrapper({
required this.child,
super.key,
this.keepAlive = false,
});

final bool keepAlive;
final Widget child;

@override
State<AppAnimationWrapper> createState() => _AppAnimationWrapperState();
}

class _AppAnimationWrapperState extends State<AppAnimationWrapper>
with SingleTickerProviderStateMixin, AutomaticKeepAliveClientMixin {
late final AnimationController _controller;
late final Animation<double> _animation;

@override
void initState() {
super.initState();
_controller = AnimationController(
vsync: this,
duration: const Duration(seconds: 1),
)..forward();
_animation = Tween<double>(begin: 0.5, end: 1).animate(
CurvedAnimation(
parent: _controller,
curve: Curves.easeInOut,
),
);
}

@override
void dispose() {
_controller.dispose();
super.dispose();
}

@override
Widget build(BuildContext context) {
super.build(context);
return ScaleTransition(
scale: _animation,
child: widget.child,
);
}

@override
bool get wantKeepAlive => widget.keepAlive;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import 'package:flutter/material.dart';
import '../extensions/is_ios_or_macos_platform_extension.dart';
import '../extensions/theme_of_context_extension.dart';

class GoBackButton extends StatelessWidget {
const GoBackButton({super.key});
class AppBackButton extends StatelessWidget {
const AppBackButton({super.key});

@override
Widget build(BuildContext context) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import '../extensions/js_bottom_padding_extension.dart'

/// Widget that calls the calls to JS to get the insets of web
/// https://github.com/flutter/flutter/issues/84833#issuecomment-1679737846
class WebPadding extends StatelessWidget {
const WebPadding({
class AppWebPadding extends StatelessWidget {
const AppWebPadding({
required this.child,
this.bottom = true,
this.top = true,
Expand All @@ -18,7 +18,7 @@ class WebPadding extends StatelessWidget {
super.key,
});

const WebPadding.only({
const AppWebPadding.only({
required this.child,
this.bottom = false,
this.top = false,
Expand Down
7 changes: 5 additions & 2 deletions lib/core/client_network_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,11 @@ class ClientNetwork extends _$ClientNetwork {
final language = ref.watch(languageAppProvider).value!.languageCode;
final cacheDirPath = await _getTemporaryDirectory();
final cache = CacheOptions(
store: HiveCacheStore(cacheDirPath),
hitCacheOnErrorExcept: [401, 403],
store: BackupCacheStore(
primary: MemCacheStore(),
secondary: HiveCacheStore(cacheDirPath),
),
hitCacheOnErrorExcept: [],
);
final options = BaseOptions(
baseUrl: Endpoint.basePath.path,
Expand Down
30 changes: 13 additions & 17 deletions lib/extensions/intl_extension.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,23 +34,19 @@ extension IntlExtension on DateTime {
}

extension OrdinalExtension on int {
String intlOrdinal(BuildContext context) {
if (context.loc.localeName == 'en') {
return switch (this % 10) {
1 => '${this}st',
2 => '${this}nd',
3 => '${this}rd',
_ => '${this}th'
};
}
if (context.loc.localeName == 'ja') {
return '第$formatNumberToJapanese';
//return '第$this';
}
if (context.loc.localeName == 'es' || context.loc.localeName == 'pt') {
return '$thisº';
}
return '$this';
String intlOrdinal(BuildContext context, {bool spaceAfter = true}) {
final ordinal = switch (context.loc.localeName) {
('ja') => '第$formatNumberToJapanese',
('es' || 'pt') => '$thisº',
('en') => switch (this % 10) {
1 => '${this}st',
2 => '${this}nd',
3 => '${this}rd',
_ => '${this}th'
},
(_) => '$this',
};
return spaceAfter ? '$ordinal ' : ordinal;
}

String get formatNumberToJapanese {
Expand Down
4 changes: 2 additions & 2 deletions lib/features/home/home_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:go_router/go_router.dart';

import '../../common_widgets/web_padding.dart';
import '../../common_widgets/app_web_padding.dart';
import '../../extensions/media_query_context_extension.dart';
import '../../extensions/theme_of_context_extension.dart';
import '../../utils/immutable_list.dart';
Expand All @@ -22,7 +22,7 @@ class HomePage extends ConsumerWidget {
return Scaffold(
body: size.isSmallScreen
? navigationShell
: WebPadding.only(
: AppWebPadding.only(
left: true,
color: context.colorScheme.surface,
child: Row(
Expand Down
6 changes: 3 additions & 3 deletions lib/features/home/widgets/adaptive_navigation_bar.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

import '../../../common_widgets/web_padding.dart';
import '../../../common_widgets/app_web_padding.dart';
import '../../../extensions/is_ios_or_macos_platform_extension.dart';
import '../../../extensions/theme_of_context_extension.dart';
import '../../../utils/immutable_list.dart';
Expand All @@ -25,7 +25,7 @@ class AdaptiveNavigationBar extends StatelessWidget {
if (kIsCupertino) {
return AnimatedTheme(
data: Theme.of(context),
child: WebPadding.only(
child: AppWebPadding.only(
color: Theme.of(context).bottomNavigationBarTheme.backgroundColor,
bottom: true,
child: CupertinoTabBar(
Expand All @@ -45,7 +45,7 @@ class AdaptiveNavigationBar extends StatelessWidget {
),
);
}
return WebPadding.only(
return AppWebPadding.only(
color: context.colorScheme.primaryContainer,
bottom: true,
child: NavigationBar(
Expand Down
6 changes: 3 additions & 3 deletions lib/features/instruments/details/instrument_details_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:sliver_tools/sliver_tools.dart';

import '../../../common_widgets/app_back_button.dart';
import '../../../common_widgets/app_cupertino_sliver_navigation_bar.dart';
import '../../../common_widgets/go_back_button.dart';
import '../../../common_widgets/web_padding.dart';
import '../../../common_widgets/app_web_padding.dart';
import '../../../extensions/app_localization_extension.dart';
import '../../../extensions/media_query_context_extension.dart';
import 'instrument_details_providers.dart';
Expand Down Expand Up @@ -48,7 +48,7 @@ class _InstrumentDetailsPageState extends ConsumerState<InstrumentDetailsPage> {
sliver: SliverCrossAxisConstrained(
maxCrossAxisExtent: screenConstraint,
child: AppCupertinoSliverNavigationBar(
leading: const GoBackButton(),
leading: const AppBackButton(),
largeTitle: context.loc.instrumentDetails,
stretch: true,
),
Expand Down
2 changes: 1 addition & 1 deletion lib/features/instruments/instruments_tab_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import 'package:go_router/go_router.dart';
import 'package:sliver_tools/sliver_tools.dart';

import '../../common_widgets/app_cupertino_sliver_navigation_bar.dart';
import '../../common_widgets/web_padding.dart';
import '../../common_widgets/app_web_padding.dart';
import '../../extensions/app_localization_extension.dart';
import '../../extensions/media_query_context_extension.dart';
import '../home/home_page_controller.dart';
Expand Down
6 changes: 3 additions & 3 deletions lib/features/parades/parades_tab_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,9 @@ class _ParadesTabPageState extends ConsumerState<ParadesTabPage> {
currentParadeProvider.overrideWithValue(value[index]),
],
child: Padding(
padding: index == 0
? const EdgeInsets.only(top: 24)
: EdgeInsets.zero,
padding: index != 0
? EdgeInsets.zero
: const EdgeInsets.only(top: 24),
child: const ParadeItem(),
),
);
Expand Down
22 changes: 15 additions & 7 deletions lib/features/parades/widgets/parade_item.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ import 'dart:ui';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';

import '../../../common_widgets/animated_linear_gradient.dart';
import '../../../common_widgets/app_animated_linear_gradient.dart';
import '../../../common_widgets/app_fade_in_image.dart';
import '../../../extensions/app_localization_extension.dart';
import '../../../extensions/theme_of_context_extension.dart';
import '../../schools/school.dart';
import '../../schools/school_extensions.dart';
Expand Down Expand Up @@ -160,7 +161,7 @@ class ParadeItemBadge extends StatelessWidget {
borderRadius: const BorderRadius.only(
bottomLeft: Radius.circular(16),
),
child: AnimatedLinearGradient(
child: AppAnimatedLinearGradient(
duration: const Duration(seconds: 2),
colors: [
medalColor.withOpacity(0.9),
Expand Down Expand Up @@ -275,7 +276,7 @@ class ParadeItemTextContentDetails extends ConsumerWidget {
TextSpan(
children: [
TextSpan(
text: 'Carnavalescos: ',
text: '${context.loc.carnavalescos}:',
style: context.textTheme.labelMedium,
),
TextSpan(
Expand All @@ -299,7 +300,7 @@ class ParadeItemTextContentDetails extends ConsumerWidget {
TextSpan(
children: [
TextSpan(
text: 'Components: ',
text: '${context.loc.schoolComponents}: ',
style: context.textTheme.labelSmall!.copyWith(
fontWeight: FontWeight.w400,
),
Expand All @@ -312,24 +313,31 @@ class ParadeItemTextContentDetails extends ConsumerWidget {
),
TextSpan(
children: [
const TextSpan(text: '\n'),
TextSpan(
text: parade.numberOfFloats > 0 ? '\nFloats: ' : '',
text: parade.numberOfFloats > 0
? '${context.loc.floats}: '
: '',
),
TextSpan(
text: parade.numberOfFloats > 0
? parade.numberOfFloats.toString()
: '',
),
TextSpan(
text: parade.numberOfWings > 0 ? ' - Wings: ' : '',
text: parade.numberOfWings > 0
? ' - ${context.loc.wings}: '
: '',
),
TextSpan(
text: parade.numberOfWings > 0
? parade.numberOfWings.toString()
: '',
),
TextSpan(
text: parade.numberOfTripods > 0 ? ' - Tripods: ' : '',
text: parade.numberOfTripods > 0
? ' - ${context.loc.tripods}: '
: '',
),
TextSpan(
text: parade.numberOfTripods > 0
Expand Down
21 changes: 9 additions & 12 deletions lib/features/parades/widgets/parade_item_bottom_row.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'package:flutter/material.dart';

import '../../../common_widgets/animated_linear_gradient.dart';
import '../../../common_widgets/app_animated_linear_gradient.dart';
import '../../../extensions/app_localization_extension.dart';
import '../../../extensions/intl_extension.dart';
import '../../../extensions/theme_of_context_extension.dart';
Expand All @@ -18,7 +18,9 @@ class ParadeItemBottomRow extends StatelessWidget {
@override
Widget build(BuildContext context) {
final medalColor = parade.medalColor(context);
return AnimatedLinearGradient(
final day = parade.performanceDay.intlOrdinal(context);
final order = parade.performanceOrder.intlOrdinal(context);
return AppAnimatedLinearGradient(
duration: const Duration(seconds: 10),
colors: [
if (parade.school.colorsCode.length > 1)
Expand All @@ -34,24 +36,19 @@ class ParadeItemBottomRow extends StatelessWidget {
child: Row(
children: [
Text.rich(
maxLines: 2,
TextSpan(
style: context.textTheme.labelMedium,
children: [
TextSpan(
text: '${parade.performanceDay.intlOrdinal(context)} Day ',
),
TextSpan(
text: parade.date.intlTime(context),
),
TextSpan(text: '$day${context.loc.day} '),
TextSpan(text: parade.date.intlTime(context)),
],
),
maxLines: 2,
style: context.textTheme.labelMedium,
),
const Spacer(),
const SizedBox(width: 16),
Text(
'${parade.performanceOrder.intlOrdinal(context)}'
' ${context.loc.schoolToParade}',
'$order${context.loc.schoolToParade}',
style: context.textTheme.labelMedium!.copyWith(
fontStyle: FontStyle.italic,
),
Expand Down
Loading

0 comments on commit f4ad834

Please sign in to comment.