I'm making a screen using Mbox, however it aren't refresh my object.
I wanna just show a List of string for after create a table with this information.
My Mbox code is it:
abstract class ControllerResearchBase with Store {
Pesquisa _finalResearch = new Pesquisa();
set finalResearch(Pesquisa pesquisa) {
_finalResearch = pesquisa;
}
@observable
List<String> informationLC = [];
@action
void changeLojaOrConcorrete({int op = 0}) {
informationLC.clear();
if (_finalResearch == null) informationLC.add("Error, pesquisa vazia");
if (op == 0) {
if (_finalResearch.loja == null) {
informationLC.add("Error, loja vazia");
return;
}
_finalResearch.loja.forEach((element) {
informationLC.add(element.desLoja);
});
} else if (op == 1) {
if (_finalResearch.concorrente == null) {
informationLC.add("Error, concorrente vazia");
return;
}
_finalResearch.concorrente.forEach((element) {
informationLC.add(element.desConco);
});
} else {
informationLC.add("Opção invalida");
}
}
I already create the class ControllerResearch and file.g.dart
The simple screen is:
Widget build(BuildContext context) {
ControllerResearch controller = new ControllerResearch();
UtilsWidgetsComponents _components = new UtilsWidgetsComponents();
controller.finalResearch = finalResearch;
return Scaffold(
appBar: AppBar(
flexibleSpace: _components.colorAppBar(),
title: Center(child: Text('Detalhes')),
),
body: Column(
children: [
Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Padding(
padding: const EdgeInsets.all(8.0),
child: ElevatedButton(
onPressed: () {
controller.changeLojaOrConcorrete(op: 0);
},
child: Text("Lojas")),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: ElevatedButton(
onPressed: () {
controller.changeLojaOrConcorrete(op: 1);
},
child: Text("Concorrentes")),
),
],
),
Observer(builder: (_) => Text("${controller.informationLC}"))
],
),
),
);
}
In my prints debug, the information is correct, However at screen is showing []
Okay, the problem could be that you are restarting your controller every time build is called:
If you move your variables to outside of build method, it could fix the issue.