1

i have main StatefulWidget which contains several StatefulWidget classes by it's TabBarView like following

    class MyNainClass extends StatefulWidget {
  const MyNainClass({Key? key}) : super(key: key);

  @override
  State<MyNainClass> createState() => _MyNainClassState();
}

class _MyNainClassState extends State<MyNainClass> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        actions: [
          TextField() // here is the problem 
        ],
      ),
      body: TabBarView(
        children: [
          // Here i have several `StatefulWidget` as tabs like 4 ones
          // Note: that per claas is contains heavy work code  !
          MyStatefulWidget1(),
          MyStatefulWidget2(),
          MyStatefulWidget3(),
          MyStatefulWidget4(),
      ),
    );
  }
}

well, now every time user tabbed on the TextField then keyboard pops up so it is causes widget rebuilding , that's means all my classes into TabBarView do rebuild too .

in the fact even if user tabbed any other TextField it also rebuild the whole classes .

This was a huge disappointment to me after I studied a lot of provider and i completely not using setState to make my app good with performance .

i have read many similar questions like mine but it look like there no solution with this issue

that's happen because Scaffold depends on MediaQuesry with causes more resize of screen for keyboard . i tried with resizeToAvoidBottomInset set to false but it still des not prevent unwanted rebuild when keyboard pops up .

my AppBar search bar is very active in my app and i can't imagine what the horrible results will be effect to my app performance if users tab on it every time special i have big classes will be rebuild too .

any solution to How prevent widget rebuilding when keyboard pops up are most welcome thank you

1
  • 1
    Seems like a state-management library will do you good. Use a stateless widget in combination with either Riverpod, Provider or Getx Mar 22, 2022 at 18:43

1 Answer 1

3

have you tried using "const TabBarView(..." ?

1
  • thank you so mush , it is really prevent rebuild as wanted ,, ! i really didn't imagine that const will do all this Mar 22, 2022 at 19:05

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.