0
Good morning
I’m starting to study Flutter and I was trying to create a Configuration screen, where after configuring the parameters on the screen, you can search at any time, and for this I’m using Sharedpreferences
First I created the Parameter Class as follows
class Parametros{
LocalSettings settings = LocalSettings();
String _URL_API;
String _CodEmpresaPadrao;
Parametros();
String get url_api => _URL_API;
set url_api(String value) {
_URL_API = value;
}
String get codempresapadrao => _CodEmpresaPadrao;
set codempresapadrao(String value){
_CodEmpresaPadrao = value;
}
}
Based on some questions I saw here created the Localsettings
class LocalSettings{
SharedPreferences preferences;
Future<void> getInstance() async {
preferences = await SharedPreferences.getInstance();
}
}
and then the Search Wire method in the Parameters
void BuscarParametros() async {
await settings.getInstance();
if (settings.preferences.containsKey('URL_API'))
_URL_API = settings.preferences.getString('URL_API');
}
But in the configuration screen, when I call the search method to fill the Parameter class, and pass to the text controller, the value null arrives
What I noticed in the debug and that it passes in the search wire, arrives in the line " await Settings.getInstance();" and leaves the method, without passing in time, and after rotating Fillrtxtoparam, it returns in the search wire and rotates everything, even what had not been rotated.
I was wondering if there might be another way to be doing this, or if I might be fixing my code somehow.
By default, when naming a function start with lower case letter, for example
void buscarParametros()
; For classes use the first uppercase letter, for exampleclass PreencherTextParam()
(That you’ve done correctly).– Matheus Ribeiro
Thanks for the tip
– Iury Pereira