0

I implemented TabBar inside Dialog and I add listener to this TabBar. I am calling setState when tab is changed but nothing is happening.

I tried wrapping my Dialog inside StatefulBuilder but it didnt help.

Is there a way to do it? In Dialog I am only displaying data based on actual tab

showDialog(context: context, builder: (BuildContext context) {
   return BackdropFilter(
     filter: ImageFilter.blur(sigmaX: 2, sigmaY: 2),
     child: StatefulBuilder(
        builder: (BuildContext context, StateSetter setState) {
           return Dialog(
              elevation: 10,
              insetPadding: EdgeInsets.zero,
              child: SizedBox(
                 height: size.height * 0.8,
                 width: size.width * 0.9,
                 child: Column(
                    children: [
                       TabBar(
                          tabs: [
                            Tab(text: 'Weźmie udział'),
                            Tab(text: 'Interesuje się'),
                            Tab(text: 'Będzie dzisiaj'),
                          ],
                          controller: _dialogTabController,
                       ),
                       FutureBuilder(
                         future: myFriendPartiesLoader = loadFriendParties(element['id']),
                         builder: (context, snapshot) {
                             if (snapshot.connectionState != ConnectionState.done && !snapshot.hasData) { /* some not needed code */}
                             else if ((snapshot.data! as List).isNotEmpty) {
                                 return Column(
                                     children: [
                                         Text(takePart ? 'Weźmie udział' : 'Nie wexmie'),
                                         SizedBox(
/***** more, not needed here, code *******/

void dialogTabChangeListener() {
    if (_dialogTabController.index == 0) {
      setState(() {
        takePart = true;
        interested = false;
        beToday = false;
      });
    } else if (_dialogTabController.index == 1) {
      setState(() {
        takePart = false;
        interested = true;
        beToday = false;
      });
    } else {
      setState(() {
        takePart = false;
        interested = false;
        beToday = true;
      });
    }
  }
Md. Yeasin Sheikh
  • 54,221
  • 7
  • 29
  • 56

1 Answers1

0

Most likely dialogTabChangeListener will use state class setState and StatefulBuilder's setState is out of scope to update dialog UI. You can pass StatefulBuilder's setState to update the ui. I think it would be better rename setState method.

void dialogTabChangeListener(setStateSB) {
 //... all operation here 

setStateSB((){}); // this will update dialog ui
}

And pass StatefulBuilder's setState on this method.

Md. Yeasin Sheikh
  • 54,221
  • 7
  • 29
  • 56