Skip to content

Commit f5965f2

Browse files
committed
Error en la lectura del texto de título; corregido
Se separó el texto de título que contenía el AppBar del header, en un Widget Estático [MyText]; esto debido a que al intentarse encontrar el texto de traducción directo en [buildAppBar], no se tenía un contexto con ancestros más allá del MaterialApp, y no se podía configurar el idioma Local de la traducción...
1 parent 6ed28e0 commit f5965f2

File tree

3 files changed

+30
-17
lines changed

3 files changed

+30
-17
lines changed

lib/Header.dart

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import 'package:flutter/material.dart';
22
import 'package:eight_queens_game/Theme.dart';
3-
import 'package:google_fonts/google_fonts.dart';
3+
4+
import 'MyTitle.dart';
45

56
import 'dart:js' as js;
67

7-
AppBar buildAppBar(String title) => AppBar
8+
AppBar buildAppBar() => AppBar
89
(
910

1011
title: MouseRegion
@@ -22,7 +23,9 @@ AppBar buildAppBar(String title) => AppBar
2223
String link = "https://github.com/arhcoder/eight-queens-game/";
2324
js.context.callMethod('open', [link]);
2425
},
25-
child: Text(title, style: GoogleFonts.staatliches(fontSize: 26.0))
26+
// El título se separó del AppBar debido a que para obtener
27+
// una traducción del texto, necesita un ancestro en su contexto.
28+
child: MyTitle()
2629
)
2730
),
2831
centerTitle: true,

lib/MyTitle.dart

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import 'package:flutter/material.dart';
2+
import 'package:google_fonts/google_fonts.dart';
3+
import 'generated/l10n.dart';
4+
5+
class MyTitle extends StatelessWidget
6+
{
7+
@override
8+
Widget build(BuildContext context)
9+
{
10+
return Text(S.current.app_title, style: GoogleFonts.staatliches(fontSize: 26.0));
11+
}
12+
}

lib/main.dart

+12-14
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ import 'package:eight_queens_game/Theme.dart';
44
import 'package:flutter_localizations/flutter_localizations.dart';
55
import 'generated/l10n.dart';
66

7-
import 'package:eight_queens_game/Theme.dart';
8-
97
import 'Header.dart';
108
import 'Chess.dart';
119

@@ -29,20 +27,10 @@ class MyApp extends StatelessWidget
2927
(
3028
debugShowCheckedModeBanner: false,
3129

32-
localizationsDelegates:
33-
[
34-
S.delegate,
35-
GlobalMaterialLocalizations.delegate,
36-
GlobalCupertinoLocalizations.delegate,
37-
GlobalWidgetsLocalizations.delegate
38-
],
39-
40-
supportedLocales: S.delegate.supportedLocales,
41-
4230
title: '♟ Ocho Reinas | Juego online',
4331
home: Scaffold
4432
(
45-
appBar: buildAppBar("${S.current.app_title}"),
33+
appBar: buildAppBar(),
4634

4735
body: SingleChildScrollView
4836
(
@@ -58,7 +46,17 @@ class MyApp extends StatelessWidget
5846
)
5947
)
6048
)
61-
)
49+
),
50+
51+
localizationsDelegates:
52+
[
53+
S.delegate,
54+
GlobalMaterialLocalizations.delegate,
55+
GlobalCupertinoLocalizations.delegate,
56+
GlobalWidgetsLocalizations.delegate
57+
],
58+
59+
supportedLocales: S.delegate.supportedLocales
6260
);
6361
}
6462
}

0 commit comments

Comments
 (0)