0

Hi IM trying to load initial data from db and sharepref as user first open page.

...
 List questionsList = [];
 bool _languageA = false;

  @override
  void initState() {
    super.initState();

    loadData(); // seting for some dropdown menu
    _getLanguageChoise(); //geting from sharepref bool value

    _getData(arabic: _languageArabic).then((value) {   //async db call load List ext...
      setState(() {});
    });
  }

Problem is that "questionsList" and "_languageA" bool is not filed in initState , so I get null or initial value, only when I refresh state or reload List get filed and var get value... So what I need to do in order to have initial filed variables before build method so user can see..

Lineu Pastorelli
  • 502
  • 1
  • 8
  • 20
Alex Apps
  • 317
  • 6
  • 19

2 Answers2

0

assign questionsList and _languageA values inside initState method just like this in order to initialize a field value when the widget is created

void initState() {
    super.initState();
    questionsList=["hello"];
    _languageA=true;

    
    }
0

Make your initstate like this

  @override
  void initState() {
    super.initState();
      
questionsList=[""];
_languageA=true;
    loadData(); // seting for some dropdown menu
    _getLanguageChoise(); //geting from sharepref bool value

    _getData(arabic: _languageArabic).then((value) {   //async db call load List ext...
      setState(() {});
    });
  }
Dharman
  • 30,962
  • 25
  • 85
  • 135
Anand
  • 4,355
  • 2
  • 35
  • 45