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>
// TODO: Agregar una pantalla de registro de récords
Widget _buildPantallaFinal(Orientation orientation){
final fullWidth = MediaQuery.of(context).size.width;
final fullHeight = 380.0;
final fullWidth = (orientation == Orientation.portrait)?
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(
width: fullWidth,
......
......@@ -8,7 +8,267 @@ class PantallaRecords extends StatelessWidget {
@override
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)
return OrientationBuilder(builder: (context, orientation) {
return Scaffold(
body: SafeArea(
child: LayoutBuilder(
builder: (context, constraints) {
if(orientation == Orientation.portrait){
return Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
_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,
child: Padding(
padding: const EdgeInsets.symmetric(vertical: 16.0, horizontal: 8.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Text(
'Récords',
textAlign: TextAlign.center,
style: Theme.of(context).textTheme.headlineLarge?.copyWith(
color: Theme.of(context).colorScheme.onPrimary,
fontWeight: FontWeight.bold
),
),
const SizedBox(height: 8.0),
Text(
'¡Las 20 mejores puntuaciones registradas en el juego!',
textAlign: TextAlign.center,
style: Theme.of(context).textTheme.titleLarge?.copyWith(
color: Theme.of(context).colorScheme.onPrimary,
fontStyle: FontStyle.italic
),
),
],
),
)
);
}
Widget _buildRecordsView(BuildContext context, Orientation orientation){
final records = _loadMockData();
if(records.isNotEmpty) {
return Expanded(
child: ListView.builder(
shrinkWrap: true,
itemCount: records.length,
itemBuilder: (context, index){
Color c = Theme.of(context).colorScheme.inversePrimary;
Color? t = Theme.of(context).textTheme.titleLarge?.color;
if(index == 0){
if(Theme.of(context).brightness == Brightness.dark){
c = Colors.yellow.shade600;
}
else{
c = Colors.yellow;
}
t = Colors.black;
}
else if(index == 1){
c = Colors.grey.shade400;
t = Colors.black;
}
else if(index == 2){
if(Theme.of(context).brightness == Brightness.dark){
c = Color.fromARGB(255, 180, 76, 12);
}
else{
c = Colors.orange.shade800;
}
t = Colors.white;
}
DateTime fecha = records[index].fecha.toLocal();
return Padding(
padding: EdgeInsets.only(
top: 8.0,
bottom: (index >= records.length-1)? 100 : 0
),
child: Container(
color: c,
child: Padding(
padding: const EdgeInsets.symmetric(vertical: 8.0, horizontal: 16.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Flexible(
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Text(
records[index].jugador.toString(),
textAlign: TextAlign.start,
style: Theme.of(context).textTheme.headlineMedium?.copyWith(
color: t,
fontWeight: FontWeight.bold
),
),
const SizedBox(height: 8.0),
Text(
'${fecha.day}/${fecha.month}/${fecha.year}',
textAlign: TextAlign.start,
style: Theme.of(context).textTheme.titleLarge?.copyWith(
color: t,
),
),
],
)
),
Flexible(
child: Text(
records[index].puntuacion.toString(),
textAlign: TextAlign.end,
style: Theme.of(context).textTheme.headlineLarge?.copyWith(
color: t,
),
)
)
],
),
),
),
);
},
)
);
}
else {
return Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Expanded(
child: Center(
child: Text(
'No hay ningún récord registrado de momento.\n\n¡Juega y registra el primero!',
textAlign: TextAlign.center,
style: Theme.of(context).textTheme.titleLarge,
)
),
),
],
);
}
}
Widget _buildFAB(BuildContext context, Orientation orientation){
return Align(
alignment: (orientation == Orientation.portrait)? Alignment.bottomCenter : Alignment.bottomRight,
child: Padding(
padding: const EdgeInsets.only(left: 32.0),
child: FloatingActionButton.extended(
onPressed: () {
showDialog(
context: context,
builder: (context) {
return AlertDialog(
title: Center(child: Text(
'Borrar récords',
textAlign: TextAlign.center,
style: Theme.of(context).textTheme.titleLarge,
)),
content: Text(
(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,
style: Theme.of(context).textTheme.titleMedium,
),
actionsAlignment: MainAxisAlignment.spaceAround,
actions: [
TextButton(
onPressed: () {
// TODO: Borrar récords
Navigator.pop(context);
},
style: TextButton.styleFrom(
side: BorderSide(
color: Colors.grey,
width: 2.0
)
),
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 24.0),
child: Text(
'Sí',
style: Theme.of(context).textTheme.titleMedium?.copyWith(
color: Theme.of(context).colorScheme.primary
),
),
)
),
TextButton(
onPressed: () {
Navigator.pop(context);
},
style: TextButton.styleFrom(
backgroundColor: Theme.of(context).colorScheme.primary
),
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 24.0),
child: Text(
'No',
style: Theme.of(context).textTheme.titleMedium?.copyWith(
color: Theme.of(context).colorScheme.onPrimary
),
),
)
)
],
);
}
);
},
backgroundColor: Colors.red,
label: Text(
'Borrar récords',
style: Theme.of(context).textTheme.titleLarge?.copyWith(
color: Colors.white
),
),
),
),
);
}
List<PeponatorRecord> _loadMockData() {
final records = <PeponatorRecord>[];
records.add(PeponatorRecord(
jugador: "AAA",
puntuacion: 12211350,
......@@ -50,206 +310,6 @@ class PantallaRecords extends StatelessWidget {
fecha: DateTime.now()
));
return Scaffold(
body: SafeArea(
child: LayoutBuilder(
builder: (context, constraints) {
return Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Container(
color: Theme.of(context).colorScheme.primary,
child: Padding(
padding: const EdgeInsets.symmetric(vertical: 16.0, horizontal: 8.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Text(
'Récords',
textAlign: TextAlign.center,
style: Theme.of(context).textTheme.headlineLarge?.copyWith(
color: Theme.of(context).colorScheme.onPrimary,
fontWeight: FontWeight.bold
),
),
const SizedBox(height: 8.0),
Text(
'¡Las 20 mejores puntuaciones registradas en el juego!',
textAlign: TextAlign.center,
style: Theme.of(context).textTheme.titleLarge?.copyWith(
color: Theme.of(context).colorScheme.onPrimary,
fontStyle: FontStyle.italic
),
),
],
),
)
),
if(records.isNotEmpty) Expanded(
child: ListView.builder(
itemBuilder: (context, index){
Color c = Theme.of(context).colorScheme.inversePrimary;
Color? t = Theme.of(context).textTheme.titleLarge?.color;
if(index == 0){
if(Theme.of(context).brightness == Brightness.dark){
c = Colors.yellow.shade600;
}
else{
c = Colors.yellow;
}
t = Colors.black;
}
else if(index == 1){
c = Colors.grey.shade400;
t = Colors.black;
}
else if(index == 2){
if(Theme.of(context).brightness == Brightness.dark){
c = Color.fromARGB(255, 180, 76, 12);
}
else{
c = Colors.orange.shade800;
}
t = Colors.white;
}
DateTime fecha = records[index].fecha.toLocal();
return Padding(
padding: EdgeInsets.only(
top: 8.0,
bottom: (index >= records.length-1)? 100 : 0
),
child: Container(
color: c,
child: Padding(
padding: const EdgeInsets.symmetric(vertical: 8.0, horizontal: 16.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Flexible(
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Text(
records[index].jugador.toString(),
textAlign: TextAlign.start,
style: Theme.of(context).textTheme.headlineMedium?.copyWith(
color: t,
fontWeight: FontWeight.bold
),
),
const SizedBox(height: 8.0),
Text(
'${fecha.day}/${fecha.month}/${fecha.year}',
textAlign: TextAlign.start,
style: Theme.of(context).textTheme.titleLarge?.copyWith(
color: t,
),
),
],
)
),
Flexible(
child: Text(
records[index].puntuacion.toString(),
textAlign: TextAlign.end,
style: Theme.of(context).textTheme.headlineLarge?.copyWith(
color: t,
),
)
)
],
),
),
),
);
},
shrinkWrap: true,
itemCount: records.length,
)
)
else Expanded(
child: Center(
child: Text(
'No hay ningún récord registrado de momento.\n\n¡Juega y registra el primero!',
textAlign: TextAlign.center,
style: Theme.of(context).textTheme.titleLarge,
)
),
)
],
);
}
)
),
floatingActionButton: Align(
alignment: Alignment.bottomCenter,
child: Padding(
padding: const EdgeInsets.only(left: 32.0),
child: FloatingActionButton.extended(
onPressed: () {
showDialog(
context: context,
builder: (context) {
return AlertDialog(
title: Center(child: Text(
'Borrar récords',
textAlign: TextAlign.center,
style: Theme.of(context).textTheme.titleLarge,
)),
content: Text(
'Esta acción no se puede deshacer. ¿Seguro que quieres borrar todos los récords?',
textAlign: TextAlign.center,
style: Theme.of(context).textTheme.titleMedium,
),
actionsAlignment: MainAxisAlignment.spaceAround,
actions: [
TextButton(
onPressed: () {
Navigator.pop(context);
},
style: TextButton.styleFrom(
side: BorderSide(
color: Colors.grey,
width: 2.0
)
),
child: Text(
'Sí',
style: Theme.of(context).textTheme.titleMedium?.copyWith(
color: Theme.of(context).colorScheme.primary
),
)
),
TextButton(
onPressed: () {
Navigator.pop(context);
},
style: TextButton.styleFrom(
backgroundColor: Theme.of(context).colorScheme.primary
),
child: Text(
'No',
style: Theme.of(context).textTheme.titleMedium?.copyWith(
color: Theme.of(context).colorScheme.onPrimary
),
)
)
],
);
}
);
},
backgroundColor: Colors.red,
label: Text(
'Borrar récords',
style: Theme.of(context).textTheme.titleLarge?.copyWith(
color: Colors.white
),
),
),
),
),
);
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