0

I'm trying to implement the flutter Getx plugin and made some splash screen like this one:

class SplashScreen extends StatelessWidget {
  const SplashScreen({Key key}) : super(key: key);
  @override
  Widget build(BuildContext context) {
    return GetBuilder(
      init: SplashController(),
        builder: (_) => Scaffold(
          body: Center(
            child: CircularProgressIndicator(),
          ),
        )
    );
  }
}

Then I wrote a splashcontroller like this one:

class SplashController extends GetxController {
  @override
  void onReady() {
    // TODO: implement onReady
    super.onReady();
    myFunctionCalculations();
    final Controller _controller = Get.put(controller());
    List items = _controller.items;
    if (items > 0) {
      Get.off(OnePlayerScreen());
    }
  }
}

Now from my HomeScreen I tap a button to navigate to this splash screen. It does nothing more only

onPressed: () {
                  Get.to(SplashScreen());
               }

The thing is that I want to show the circular indicator while my function is running and when it populates the List items to go to the Items Screen, but when I tap the button to get the splash screen it gets a while until the splash screen appear and then immediately goes to the Items screen, because meanwhile it populated the List. When I don't initialize the function it get immediately to the splash screen and I see the indicator.

Why I get this functionality? I thought it's supposed to show the loading indicator and meanwhile populate the List. But it seems when I tap the button from HomeScreen the function is initialized and when its donde the splashcreen appears. What am I doing wrong?

Rex Nihilo
  • 604
  • 2
  • 7
  • 16
i6x86
  • 1,557
  • 6
  • 23
  • 42

1 Answers1

0

Didn't you forget to call update() in your calculation function?

And it seems that your function is async, so you should await it before populating the list

Andrey Gritsay
  • 979
  • 1
  • 10
  • 18
  • I've tried await but it doesn't matter, the problem is that the splash screen doesn't appear until the calculations are done and it's supposed they should be done once it appears. – i6x86 Dec 29 '20 at 20:46