Commit 6c25f5e9 by Diego Pérez Peña Committed by Tecnicos

Agregada orientación para la pantalla final y la de récords

parent 508e88e1
...@@ -619,8 +619,10 @@ class _PantallaJuegoState extends State<PantallaJuego> ...@@ -619,8 +619,10 @@ class _PantallaJuegoState extends State<PantallaJuego>
// TODO: Agregar una pantalla de registro de récords // TODO: Agregar una pantalla de registro de récords
Widget _buildPantallaFinal(Orientation orientation){ Widget _buildPantallaFinal(Orientation orientation){
final fullWidth = MediaQuery.of(context).size.width; final fullWidth = (orientation == Orientation.portrait)?
final fullHeight = 380.0; MediaQuery.of(context).size.width - MediaQuery.of(context).padding.horizontal : 400.0;
final fullHeight = (orientation == Orientation.portrait)?
380.0 : MediaQuery.of(context).size.height - MediaQuery.of(context).padding.vertical;
return SizedBox( return SizedBox(
width: fullWidth, width: fullWidth,
......
...@@ -8,60 +8,52 @@ class PantallaRecords extends StatelessWidget { ...@@ -8,60 +8,52 @@ class PantallaRecords extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
// TODO: Cargar los récords (esto se haría con un archivo de texto en la carpeta privada de la aplicación) // TODO: Cargar los récords (esto se haría con un archivo de texto en la carpeta privada de la aplicación)
final records = <PeponatorRecord>[];
records.add(PeponatorRecord(
jugador: "AAA",
puntuacion: 12211350,
fecha: DateTime.now()
));
records.add(PeponatorRecord(
jugador: "BBB",
puntuacion: 25,
fecha: DateTime.now()
));
records.add(PeponatorRecord(
jugador: "CCC",
puntuacion: 13,
fecha: DateTime.now()
));
records.add(PeponatorRecord(
jugador: "DDD",
puntuacion: 7,
fecha: DateTime.now()
));
records.add(PeponatorRecord(
jugador: "EEE",
puntuacion: 6,
fecha: DateTime.now()
));
records.add(PeponatorRecord(
jugador: "FFF",
puntuacion: 5,
fecha: DateTime.now()
));
records.add(PeponatorRecord(
jugador: "GGG",
puntuacion: 4,
fecha: DateTime.now()
));
records.add(PeponatorRecord(
jugador: "HHH",
puntuacion: 3,
fecha: DateTime.now()
));
return OrientationBuilder(builder: (context, orientation) {
return Scaffold( return Scaffold(
body: SafeArea( body: SafeArea(
child: LayoutBuilder( child: LayoutBuilder(
builder: (context, constraints) { builder: (context, constraints) {
if(orientation == Orientation.portrait){
return Column( return Column(
crossAxisAlignment: CrossAxisAlignment.stretch, crossAxisAlignment: CrossAxisAlignment.stretch,
children: [ children: [
Container( _buildTitle(context, orientation),
_buildRecordsView(context, orientation)
],
);
}
else{
return Row(
children: [
SizedBox(
height: constraints.maxHeight,
width: constraints.maxWidth/4,
child: _buildTitle(context, orientation),
),
SizedBox(
height: constraints.maxHeight,
width: constraints.maxWidth*3/4,
child: _buildRecordsView(context, orientation),
)
],
);
}
}
)
),
floatingActionButton: _buildFAB(context, orientation),
);
});
}
Widget _buildTitle(BuildContext context, Orientation orientation){
return Container(
color: Theme.of(context).colorScheme.primary, color: Theme.of(context).colorScheme.primary,
child: Padding( child: Padding(
padding: const EdgeInsets.symmetric(vertical: 16.0, horizontal: 8.0), padding: const EdgeInsets.symmetric(vertical: 16.0, horizontal: 8.0),
child: Column( child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.stretch, crossAxisAlignment: CrossAxisAlignment.stretch,
children: [ children: [
Text( Text(
...@@ -84,9 +76,17 @@ class PantallaRecords extends StatelessWidget { ...@@ -84,9 +76,17 @@ class PantallaRecords extends StatelessWidget {
], ],
), ),
) )
), );
if(records.isNotEmpty) Expanded( }
Widget _buildRecordsView(BuildContext context, Orientation orientation){
final records = _loadMockData();
if(records.isNotEmpty) {
return Expanded(
child: ListView.builder( child: ListView.builder(
shrinkWrap: true,
itemCount: records.length,
itemBuilder: (context, index){ itemBuilder: (context, index){
Color c = Theme.of(context).colorScheme.inversePrimary; Color c = Theme.of(context).colorScheme.inversePrimary;
Color? t = Theme.of(context).textTheme.titleLarge?.color; Color? t = Theme.of(context).textTheme.titleLarge?.color;
...@@ -164,11 +164,14 @@ class PantallaRecords extends StatelessWidget { ...@@ -164,11 +164,14 @@ class PantallaRecords extends StatelessWidget {
), ),
); );
}, },
shrinkWrap: true,
itemCount: records.length,
) )
) );
else Expanded( }
else {
return Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Expanded(
child: Center( child: Center(
child: Text( child: Text(
'No hay ningún récord registrado de momento.\n\n¡Juega y registra el primero!', 'No hay ningún récord registrado de momento.\n\n¡Juega y registra el primero!',
...@@ -176,14 +179,15 @@ class PantallaRecords extends StatelessWidget { ...@@ -176,14 +179,15 @@ class PantallaRecords extends StatelessWidget {
style: Theme.of(context).textTheme.titleLarge, style: Theme.of(context).textTheme.titleLarge,
) )
), ),
) ),
], ],
); );
} }
) }
),
floatingActionButton: Align( Widget _buildFAB(BuildContext context, Orientation orientation){
alignment: Alignment.bottomCenter, return Align(
alignment: (orientation == Orientation.portrait)? Alignment.bottomCenter : Alignment.bottomRight,
child: Padding( child: Padding(
padding: const EdgeInsets.only(left: 32.0), padding: const EdgeInsets.only(left: 32.0),
child: FloatingActionButton.extended( child: FloatingActionButton.extended(
...@@ -198,7 +202,10 @@ class PantallaRecords extends StatelessWidget { ...@@ -198,7 +202,10 @@ class PantallaRecords extends StatelessWidget {
style: Theme.of(context).textTheme.titleLarge, style: Theme.of(context).textTheme.titleLarge,
)), )),
content: Text( content: Text(
'Esta acción no se puede deshacer. ¿Seguro que quieres borrar todos los récords?', (orientation == Orientation.portrait)?
'Esta acción no se puede deshacer. ¿Seguro que quieres borrar todos los récords?':
'Esta acción no se puede deshacer.\n¿Seguro que quieres borrar todos los récords?'
,
textAlign: TextAlign.center, textAlign: TextAlign.center,
style: Theme.of(context).textTheme.titleMedium, style: Theme.of(context).textTheme.titleMedium,
), ),
...@@ -206,6 +213,7 @@ class PantallaRecords extends StatelessWidget { ...@@ -206,6 +213,7 @@ class PantallaRecords extends StatelessWidget {
actions: [ actions: [
TextButton( TextButton(
onPressed: () { onPressed: () {
// TODO: Borrar récords
Navigator.pop(context); Navigator.pop(context);
}, },
style: TextButton.styleFrom( style: TextButton.styleFrom(
...@@ -214,11 +222,14 @@ class PantallaRecords extends StatelessWidget { ...@@ -214,11 +222,14 @@ class PantallaRecords extends StatelessWidget {
width: 2.0 width: 2.0
) )
), ),
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 24.0),
child: Text( child: Text(
'Sí', 'Sí',
style: Theme.of(context).textTheme.titleMedium?.copyWith( style: Theme.of(context).textTheme.titleMedium?.copyWith(
color: Theme.of(context).colorScheme.primary color: Theme.of(context).colorScheme.primary
), ),
),
) )
), ),
TextButton( TextButton(
...@@ -228,11 +239,14 @@ class PantallaRecords extends StatelessWidget { ...@@ -228,11 +239,14 @@ class PantallaRecords extends StatelessWidget {
style: TextButton.styleFrom( style: TextButton.styleFrom(
backgroundColor: Theme.of(context).colorScheme.primary backgroundColor: Theme.of(context).colorScheme.primary
), ),
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 24.0),
child: Text( child: Text(
'No', 'No',
style: Theme.of(context).textTheme.titleMedium?.copyWith( style: Theme.of(context).textTheme.titleMedium?.copyWith(
color: Theme.of(context).colorScheme.onPrimary color: Theme.of(context).colorScheme.onPrimary
), ),
),
) )
) )
], ],
...@@ -249,7 +263,53 @@ class PantallaRecords extends StatelessWidget { ...@@ -249,7 +263,53 @@ class PantallaRecords extends StatelessWidget {
), ),
), ),
), ),
),
); );
} }
List<PeponatorRecord> _loadMockData() {
final records = <PeponatorRecord>[];
records.add(PeponatorRecord(
jugador: "AAA",
puntuacion: 12211350,
fecha: DateTime.now()
));
records.add(PeponatorRecord(
jugador: "BBB",
puntuacion: 25,
fecha: DateTime.now()
));
records.add(PeponatorRecord(
jugador: "CCC",
puntuacion: 13,
fecha: DateTime.now()
));
records.add(PeponatorRecord(
jugador: "DDD",
puntuacion: 7,
fecha: DateTime.now()
));
records.add(PeponatorRecord(
jugador: "EEE",
puntuacion: 6,
fecha: DateTime.now()
));
records.add(PeponatorRecord(
jugador: "FFF",
puntuacion: 5,
fecha: DateTime.now()
));
records.add(PeponatorRecord(
jugador: "GGG",
puntuacion: 4,
fecha: DateTime.now()
));
records.add(PeponatorRecord(
jugador: "HHH",
puntuacion: 3,
fecha: DateTime.now()
));
return records;
}
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment