-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add option to change the language between English and Spanish.
- Loading branch information
1 parent
6aabc56
commit 5f013b8
Showing
14 changed files
with
222 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
arb-dir: lib/l10n | ||
template-arb-file: app_en.arb | ||
output-localization-file: app_localizations.dart | ||
use-deferred-loading: true | ||
use-deferred-loading: false | ||
nullable-getter: false | ||
format: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import 'dart:ui'; | ||
|
||
import 'package:riverpod_annotation/riverpod_annotation.dart'; | ||
|
||
part 'localization_controller.g.dart'; | ||
|
||
@riverpod | ||
class LocalizationController extends _$LocalizationController { | ||
static const locales = [ | ||
Locale('en'), | ||
Locale('es'), | ||
]; | ||
|
||
@override | ||
// Consider returning null to use the system locale by default | ||
Locale build() => locales[0]; | ||
|
||
void toggleLocale() => state = state == locales[0] ? locales[1] : locales[0]; | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,9 @@ | ||
{ | ||
"contentPath": "assets/content/es/", | ||
"cvFile": "alejandro_fernandez_cv-en.pdf" | ||
"cvFile": "alejandro_fernandez_cv-en.pdf", | ||
"research": "Investigación", | ||
"projects": "Proyectos", | ||
"cv": "Curriculum Vitae", | ||
"experience": "Experiencia", | ||
"education": "Educación" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_riverpod/flutter_riverpod.dart'; | ||
|
||
import '../controllers/localization_controller.dart'; | ||
|
||
class LanguageToggleButton extends ConsumerWidget { | ||
const LanguageToggleButton({super.key}); | ||
|
||
@override | ||
Widget build(BuildContext context, WidgetRef ref) { | ||
final locale = ref.watch(localizationControllerProvider); | ||
final textTheme = Theme.of(context).textTheme; | ||
final isEnglish = locale.languageCode == 'en'; | ||
|
||
return TextButton( | ||
onPressed: () { | ||
ref.read(localizationControllerProvider.notifier).toggleLocale(); | ||
}, | ||
child: Row( | ||
children: [ | ||
Text( | ||
'EN', | ||
style: textTheme.bodyMedium?.copyWith( | ||
fontWeight: isEnglish ? FontWeight.bold : null, | ||
decoration: isEnglish ? TextDecoration.underline : null, | ||
decorationColor: textTheme.bodyMedium?.color, | ||
), | ||
), | ||
// Text('|', style: textTheme.bodySmall), | ||
const SizedBox(height: 12, child: VerticalDivider(thickness: 1.5)), | ||
Text( | ||
'ES', | ||
style: textTheme.bodyMedium?.copyWith( | ||
fontWeight: !isEnglish ? FontWeight.bold : null, | ||
decoration: !isEnglish ? TextDecoration.underline : null, | ||
decorationColor: textTheme.bodyMedium?.color, | ||
), | ||
), | ||
], | ||
), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// This is a basic Flutter widget test. | ||
// | ||
// To perform an interaction with a widget in your test, use the WidgetTester | ||
// utility in the flutter_test package. For example, you can send tap and scroll | ||
// gestures. You can also use WidgetTester to find child widgets in the widget | ||
// tree, read text, and verify that the values of widget properties are correct. | ||
|
||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
|
||
import 'package:portfolio/models/route_data.dart'; | ||
import 'package:portfolio/widgets/sliver_app_bar.dart'; | ||
|
||
const routesEnglish = [ | ||
RouteData( | ||
name: 'Research', | ||
path: '/research', | ||
icon: Icons.article, | ||
), | ||
RouteData( | ||
name: 'Projects', | ||
path: '/projects', | ||
icon: Icons.terminal, | ||
), | ||
RouteData( | ||
name: 'Curriculum Vitae', | ||
path: '/cv', | ||
icon: Icons.school, | ||
), | ||
]; | ||
|
||
void main() { | ||
testWidgets('ResponsiveAppBar adapts based on screen width', (tester) async { | ||
tester.view.devicePixelRatio = 1.0; | ||
const appTitle = 'Alejandro'; | ||
|
||
// Build our app and trigger a frame. | ||
// Build our app with English top bar and trigger a frame. | ||
await tester.pumpWidget( | ||
const MaterialApp( | ||
home: Scaffold( | ||
body: CustomScrollView( | ||
physics: BouncingScrollPhysics(), | ||
slivers: [ | ||
MySliverAppBar(menuRoutes: routesEnglish), | ||
], | ||
), | ||
), | ||
), | ||
); | ||
|
||
// Test actions visibility when screen width is greater than the breakpoint | ||
tester.view.physicalSize = const Size(840, 600); | ||
await tester.pump(); | ||
expect(find.byIcon(Icons.menu), findsNothing); | ||
expect(find.text(appTitle), findsOneWidget); | ||
|
||
// Test actions visibility when screen width is less than the breakpoint | ||
tester.view.physicalSize = const Size(839, 600); | ||
await tester.pump(); | ||
expect(find.byIcon(Icons.menu), findsOneWidget); | ||
expect(find.text(appTitle), findsOneWidget); | ||
}); | ||
} |
Oops, something went wrong.