My aim is to invoke an API Call method Provider.of<AddToCartProvider>(context, listen: false).getCartProducts(); as and when required instead of using didChangeDependencies which basically which keeps calling apis in loops. I, therefore, thought that resorting to didChangeAppLifecycleState might solve this issue. However, this isn't getting called no matter what. I would like to know what I need to do to resolve this. Also, will this be the right approach for this? Here's the code:

class CustomBottomNavigation extends StatefulWidget {
  CustomBottomNavigationState createState() => CustomBottomNavigationState();
}

class CustomBottomNavigationState extends State<CustomBottomNavigation>
    with WidgetsBindingObserver {
  int index = 2;
  bool isLoading = true;
  int length = 0;

  @override
  void initState() {
    // TODO: implement initState
    Provider.of<Network>(context, listen: false).getToken();
    length = Provider.of<AddToCartProvider>(context, listen: false).length;
    print('LENGTH: $length');
    Provider.of<AddToCartProvider>(context, listen: false)
        .getCartProducts()
        .then((_) {
      Provider.of<ProfileProvider>(context, listen: false)
          .getProfileDetails()
          .then((_) {
        Provider.of<AddressProvider>(context, listen: false)
            .getDefaultAddress()
            .then((_) {
          // Provider.of<OrderHistoryProvider>(context, listen: false)
          //     .getOrderHistory()
          //     .then((_) {
          Provider.of<CouponProvider>(context, listen: false)
              .fetchCoupons()
              .then((_) {
            Provider.of<PopularDealsProvider>(context, listen: false)
                .getPopularDeals()
                .then((_) {
              Provider.of<CategoryProvider>(context, listen: false)
                  .getCategory()
                  .then((_) {
                Provider.of<WishListProvider>(context, listen: false)
                    .fetchProducts()
                    .then((_) {
                  Provider.of<TopProductsProvider>(context, listen: false)
                      .getTopProducts()
                      .then((_) {
                    Provider.of<OrderHistoryProvider>(context, listen: false)
                        .getOrderHistory()
                        .then((_) {
                      Provider.of<NotificationList>(context, listen: false)
                          .getNotificationList()
                          .then((_) {
                        setState(() {
                          isLoading = false;

                          length = Provider.of<AddToCartProvider>(context,
                                  listen: false)
                              .cartData['data']['cartItem']
                              .length;
                        });
                      });
                    });
                  });
                });
              });
            });
          });
        });
      });
    });
    super.initState();
    WidgetsBinding.instance.addObserver(this);
  }

  @override
  void dispose() {
    // TODO: implement dispose
    WidgetsBinding.instance.removeObserver(this);
    super.dispose();
  }

  @override
  void didChangeAppLifecycleState(AppLifecycleState state) {
    // TODO: implement didChangeAppLifecycleState
    print('State: $state');
    if (state == AppLifecycleState.resumed) {
      Provider.of<AddToCartProvider>(context, listen: false).getCartProducts();
      print('LOGGGGGGG: $length');
    }
    super.didChangeAppLifecycleState(state);
  }