Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Rafa Castillo Passols
/
peponator
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
2efccfc7
authored
May 14, 2025
by
Rafa Castillo Passols
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Ahora se guarda la dificultad en las preferencias
parent
85fe25b0
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
33 additions
and
8 deletions
lib/modelo/listaDificultad.dart
lib/paginas/pantalla_dificultad.dart
lib/paginas/pantalla_juego.dart
lib/modelo/listaDificultad.dart
View file @
2efccfc7
import
'package:flutter/material.dart'
;
import
'package:peponator/modelo/dificultad.dart'
;
import
'package:shared_preferences/shared_preferences.dart'
;
// TODO: CARGAR LAS DIFICULTADES CARGADAS EN MEMORIA
class
ListaDificultad
extends
ChangeNotifier
{
...
...
@@ -8,13 +9,30 @@ class ListaDificultad extends ChangeNotifier {
Dificultad
.
normal
,
Dificultad
.
dificil
];
int
_indiceSeleccionado
=
0
;
bool
_cargando
=
true
;
ListaDificultad
()
{
_getDificultadPreferencias
();
}
List
<
Dificultad
>
get
dificultades
=>
List
.
unmodifiable
(
_dificultades
);
int
get
length
=>
_dificultades
.
length
;
int
get
indiceSeleccionado
=>
_indiceSeleccionado
;
Dificultad
get
seleccionada
=>
_dificultades
[
_indiceSeleccionado
];
bool
get
cargando
=>
_cargando
;
bool
get
listo
=>
!
_cargando
;
void
_getDificultadPreferencias
()
async
{
final
prefs
=
await
SharedPreferences
.
getInstance
();
_indiceSeleccionado
=
prefs
.
getInt
(
"dificultad"
)
??
0
;
_cargando
=
false
;
notifyListeners
();
}
Dificultad
get
(
int
index
)
{
return
_dificultades
[
index
];
}
...
...
@@ -34,8 +52,11 @@ class ListaDificultad extends ChangeNotifier {
notifyListeners
();
}
void
select
(
int
indice
)
{
void
select
(
int
indice
)
async
{
_indiceSeleccionado
=
indice
;
notifyListeners
();
final
prefs
=
await
SharedPreferences
.
getInstance
();
prefs
.
setInt
(
"dificultad"
,
_indiceSeleccionado
);
}
}
\ No newline at end of file
lib/paginas/pantalla_dificultad.dart
View file @
2efccfc7
...
...
@@ -10,13 +10,16 @@ class PantallaDificultad extends StatelessWidget {
return
Consumer
<
ListaDificultad
>(
builder:
(
context
,
manager
,
child
)
{
return
SafeArea
(
child:
ListView
.
separated
(
itemBuilder:
(
context
,
index
)
{
return
DificultadWidget
(
indice:
index
,);
},
separatorBuilder:
(
context
,
index
)
=>
const
SizedBox
(
height:
8
),
itemCount:
manager
.
length
)
);
child:
manager
.
listo
?
ListView
.
separated
(
itemBuilder:
(
context
,
index
)
{
return
DificultadWidget
(
indice:
index
,);
},
separatorBuilder:
(
context
,
index
)
=>
const
SizedBox
(
height:
8
),
itemCount:
manager
.
length
)
:
CircularProgressIndicator
()
);
}
);
}
...
...
lib/paginas/pantalla_juego.dart
View file @
2efccfc7
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment