امین
4 سال پیش توسط امین مطرح شد
0 پاسخ

setState هنگام ‌بیلد در فلاتر

هنگام setState در بیلدر با ارور زیر مواجه میشم. از GetX استفاده کردم.
 تصویر

اینم کد:

 Widget build(BuildContext context) {
    List firstLetters = getFirstLetters();
    var currentChar = 'A'.obs;
    var currentIndex = 0.obs;
    return Scaffold(
      appBar: AppBar(),
      body: ListView.builder(
        itemCount: firstLetters.length,
        itemBuilder: (context, index) => StickyHeader(
          header: Text(firstLetters[index][0]),
          content: Obx(
            () {
              List<Widget> listTiles = [];
              for (;
                  currentIndex.value < countries.length;
                  currentIndex.value++) {
                String char = countries.keys.elementAt(currentIndex.value)[0];
                if (char != currentChar.value) {
                  // Error from here
                  currentChar.value = char; // setStat() syntax in GetX framework
                  currentIndex.value--;
                  break;
                }
                listTiles.add(
                  ListTile(
                    title: Text(countries.keys.elementAt(currentIndex.value)),
                  ),
                );
              }
              return Column(children: listTiles);
            },
          ),
        ),
      ),
    );
  }