我有 main StatefulWidget,其中包含幾個StatefulWidget類,TabBarView
如下所示
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(),
),
);
}
}
好吧,現在每次用戶在TextFieldthen 鍵盤上按選項卡時都會彈出,所以它會導致小部件重建,這意味著我所有的類TabBarView也都要做重建。
事實上,即使用戶選擇了任何其他選項TextField,它也會重建整個類。
在我研究了很多供應商之后,這對我來說是一個巨大的失望,而且我完全沒有使用setState來使我的應用程式具有良好的性能。
我已經閱讀了許多類似的問題,但看起來這個問題沒有解決方案
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
uj5u.com熱心網友回復:
你試過使用“const TabBarView(...”嗎?
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/447849.html
標籤:flutter performance dart build rebuild
