Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laggy animation

Tags:

flutter

dart

Does anyone have experienced laggy transition between screens when using a TabBar, or am I using it wrong ? Basically I am using it as following by building page in other widgets

home: DefaultTabController(
    initialIndex: 0,
    length: 5,
    child: Scaffold(
      appBar: AppBar(
        bottom: TabBar(
          isScrollable: true,
          labelStyle: TextStyle(fontSize: 12.0, fontWeight: FontWeight.bold),
          tabs: [
            Tab(text: 'HOME'),
            Tab(text: 'SCHEDULE'),
            Tab(text: 'ANALYTICS'),
            Tab(text: 'TEMP'),
            Tab(text: 'SETTINGS'),
          ],
        ),
        title: Text('${widget.title}'),
      ),
      body: TabBarView(
        children: [
          TheGridView().build(),
          SchedulePage(),
          ChartPage(),
          TempPage(),
          SettingsPage(),
        ],
      ),
    ),
  ),
like image 216
Q. Eude Avatar asked Jul 26 '18 16:07

Q. Eude


People also ask

What FPS is most animations?

It's commonly accepted that 60 frames per second is the rate at which animations will appear smooth. For a rate of 60 frames per second, the browser has 16.7 milliseconds to execute scripts, recalculate styles and layout if needed, and repaint the area being updated.

What is animation-delay?

The animation-delay CSS property specifies the amount of time to wait from applying the animation to an element before beginning to perform the animation. The animation can start later, immediately from its beginning, or immediately and partway through the animation.

What FPS are animations?

A frame rate of 24 fps is the default setting for new Animate documents and usually gives the best results on the web. (The standard rate for motion pictures is also 24 fps.) The complexity of the animation and the speed of the computer playing the animation affect the playback's smoothness.


1 Answers

The TabBarView doesn't save the state of the widgets in it. They are rebuilt everytime they reappear on screen. You can check this by adding a print() statement in initState() for one of the widgets. To fix this you can use AutomaticKeepAliveClientMixin

class SettingsPage extends StatefulWidget {
  SettingsPage({Key key}) : super(key: key);

  @override
  _SettingsPageState createState() => _SettingsPageState();
}

class _SettingsPageState extends State<SettingsPage> with AutomaticKeepAliveClientMixin { //<-- AutomaticKeepAliveClientMixin

  @override
  bool get wantKeepAlive => true; //Set to true

  @override
  Widget build(BuildContext context) {
    super.build(context); //You must add this
    return Container(); //A screen here
  }
}

With this small change, the widgets won't rebuild every time they are brought back to the screen

like image 120
camelCase1492 Avatar answered Oct 11 '22 00:10

camelCase1492