Bob Lee
Bob Lee

Reputation: 339

Auto change layout in flutter

I don't know how to auto change layout in flutter Ex: I have page 1 and page 2 and when I run app page 1 will be appear and after 3s it will change to page2

Upvotes: 0

Views: 409

Answers (2)

Arish Khan
Arish Khan

Reputation: 750

You can user Timer to achieve this functionality.

Add this to your initState

// suppose the timer variable is declared at class level.
timer = new Timer.periodic(new Duration(seconds: 3), (time) {
    // Navigate to other page using navigator
});

Upvotes: 1

CopsOnRoad
CopsOnRoad

Reputation: 267404

I haven't tested this code, but I think it would work, let me know if it doesn't

class Page1 extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(),
      body: AnimatedCrossFade(
        firstChild: this,
        secondChild: Page2(),
        crossFadeState: CrossFadeState.showFirst,
        duration: Duration(seconds: 3),
      ),
    );
  }
}

Upvotes: 0

Related Questions