Home > OS >  How can I prevent the widget rebuilding when opening the keyboard
How can I prevent the widget rebuilding when opening the keyboard

Time:03-23

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

CodePudding user response:

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

  • Related