FutureBuilder method inside future called twice

This issue has been tracked since 2022-09-22.

I am using the FutureBuilder widget as per documentation as follows:

late Future _initWidget;

  void initState() {
    _initWidget =  _initializeWidget();

  Widget build(BuildContext context) {
    return FutureBuilder(
      future: _initWidget,
      builder: (BuildContext context, AsyncSnapshot snapshot){
          //Not important stuff

_initializeWidget() async{
      await GetUserInfo().getUserData();
    _plans = await GetUserInfo().getPlans();

    WidgetsBinding.instance.addPostFrameCallback((timeStamp) async{
      print("Setting callback");
      if(widget.args.initialPage == 0 && _plans.length > 1)
        _timer = Timer.periodic(Duration(seconds: 3), (timer) => _pageController.animateTo(20, duration: Duration(milliseconds: 400), curve: Curves.easeOut));

      if(widget.args.subscriptionProcessInitiated && user.paymentMethods.isNotEmpty){

  Future<void> _payAndSubscribe() async{
    int index = _pageController.page!.round();
    bool? success = await startSubscription(context, index, _plans[index]['id']);

    if(success == null){


      openCustomerPortal(context, NetworkService().getSiteUrl() + '/accountPage');
      Navigator.pushReplacementNamed(context, '/accountPage');
      setState(() {});

And this is the content of my console:

Setting callback

The same happens with prints inside the GetUserInfo().getUserData() and GetUserInfo().getPlans() calls.

It seems that the _initializeWidget future is called only once, however the methods inside it are called twice (once on instantiation and once on the execution of the future I believe).

The main problem I'm having with this is that the startSubscription() method opens a Dialog and, since the method is called twice, the dialog is opened twice.

exaby73 wrote this answer on 2022-09-23

Hi @SeriousMonk
This issue doesn't seem to describe a bug or a feature request. Please see https://flutter.dev/community for resources and asking questions like this,
you may also get some help if you post it on Stack Overflow and if you need help with your code, please see https://www.reddit.com/r/flutterhelp/
Closing, as this isn't an issue with Flutter itself. If you disagree, please write in the comments and I will reopen it.
Thank you

SeriousMonk wrote this answer on 2022-09-23

The issue was caused by another widget triggering the method.

More Details About Repo
Owner Name flutter
Repo Name flutter
Full Name flutter/flutter
Language Dart
Created Date 2015-03-06
Updated Date 2022-09-30
Star Count 145381
Watcher Count 3565
Fork Count 23363
Issue Count 11208


Issue Title Created Date Updated Date