Skip to content

Snappy1

  • Home
  • Android
  • What
  • How
  • Is
  • Can
  • Does
  • Do
  • Why
  • Are
  • Who
  • Toggle search form

[FIXED] android – Flutter load new page in background

Posted on November 11, 2022 By

Solution 1 :

Have you tried using the timer, so just set the animated timer to the timer and then navigate later.

Timer(Duration(seconds: animatedSeconds), () {
  // pass your animation time  in seconds and then just navigate 
Navigator.push(thisContext, MaterialPageRoute(builder: (context) {
      return NewPage(
        title: "New Page"
      );
    }));
});

Solution 2 :

The second page will be created when the page transition begins.

See this official example.

 import 'package:flutter/material.dart';

main() {
  runApp(MaterialApp(
    home: Page1(),
  ));
}

class Page1 extends StatelessWidget {
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(),
      body: Center(
        child: RaisedButton(
          child: Text('Go!'),
          onPressed: () {
            Navigator.of(context).push(_createRoute());
          },
        ),
      ),
    );
  }
}

Route _createRoute() {
  return PageRouteBuilder(
    pageBuilder: (context, animation, secondaryAnimation) => Page2(),
    transitionsBuilder: (context, animation, secondaryAnimation, child) {
      var begin = Offset(0.0, 1.0);
      var end = Offset.zero;
      var curve = Curves.ease;

      var tween = Tween(begin: begin, end: end).chain(CurveTween(curve: curve));

      return SlideTransition(
        position: animation.drive(tween),
        child: child,
      );
    },
  );
}

class Page2 extends StatelessWidget {
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(),
      body: Center(
        child: Text('Page 2'),
      ),
    );
  }
}

Well, so how to init the second page faster?

You have the following options

  1. Fetch the required data before launching the second page and pass them as argument.

  2. You can cache the data when you fetch it for first time, and then
    onward use the cached data. Also ensure that you invalidate that
    cached data after a particular time.

Problem :

Scenario: I have a button, when pressed plays an animation and then navigates to a new page. There is a visible wait time to load the new page. This wait time is however quicker than the initial animation. At the moment the user sees the animation play then a visible pause whilst the new page loads.

READ  [FIXED] matrix - Android Camera2 API, how does one get the preview image to cover the whole screen using transformation matrices?
Powered by Inline Related Posts

I was wondering if it is possible to load the new page in the background whilst the animation is playing? This way when the animation has finished there shouldn’t be any visible wait time and the user would instantly switch to the new page.

Currently I load the new page using Navigator…

await Navigator.push(thisContext, MaterialPageRoute(builder: (context) {
      return NewPage(
        title: "New Page"
      );
    }));

Was thinking it should be possible to load the new page, then only push it to the navigator when its already loaded and the animation has finished.

This is whats currently happening…

enter image description here

Vs what I want to happen…

enter image description here

Comments

Comment posted by metamonkey

Did you ever find a solution to this? @Michael Johnston The answers below don’t solve the problem.

Comment posted by metamonkey

This doesn’t actually load the page in the background. It just delays the load.

Android Tags:android, dart, flutter, flutter-animation

Post navigation

Previous Post: [FIXED] android – how to change notification background color in nougat?
Next Post: [FIXED] android – How to make width ratio equal in XML GridView

Related Posts

[FIXED] Reading .txt files in Android with a delay Android
[FIXED] How to click a button inside a recyclerview item in kotlin Android
[FIXED] android – Error while loading opencv_java4.so file by dynamic delivery feature Android
[FIXED] android – How country targeting works in Google Play Console? Android
[FIXED] javascript – React-native throwing unexpected token error on import statement Android
[FIXED] android – How to set vector background on a Bottom Sheet Dialog Android

Archives

  • March 2023
  • February 2023
  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022

Categories

  • ¿Cómo
  • ¿Cuál
  • ¿Cuándo
  • ¿Cuántas
  • ¿Cuánto
  • ¿Qué
  • Android
  • Are
  • At
  • C'est
  • Can
  • Comment
  • Did
  • Do
  • Does
  • Est-ce
  • Est-il
  • For
  • Has
  • Hat
  • How
  • In
  • Is
  • Ist
  • Kann
  • Où
  • Pourquoi
  • Quand
  • Quel
  • Quelle
  • Quelles
  • Quels
  • Qui
  • Should
  • Sind
  • Sollte
  • Uncategorized
  • Wann
  • Warum
  • Was
  • Welche
  • Welchen
  • Welcher
  • Welches
  • Were
  • What
  • What's
  • When
  • Where
  • Which
  • Who
  • Who's
  • Why
  • Wie
  • Will
  • Wird
  • Wo
  • Woher
  • you can create a selvedge edge: You can make the edges of garter stitch more smooth by slipping the first stitch of every row.2022-02-04
  • you really only need to know two patterns: garter stitch

Recent Posts

  • Can VPN be traced by police?
  • Where were Kaiser-Frazer cars built?
  • How do you make gold rose gold paint?
  • What are the newest type of dentures?
  • Can you wear joggers as dress pants?

Recent Comments

No comments to show.

Copyright © 2023 Snappy1.

Powered by PressBook Grid Dark theme