'Auto reload Home view after navigating from successful api call flutter

I have a special use case in my app where i want to show a success page to users after a successful api call and then after 3 minutes of timeout i navigate to the homepage. Now my struggle is i want to reload the home page in order to rebuild all the children widgets and update the state there. So here is my home page;

class HomeView extends StatelessWidget {
  const HomeView({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return ViewModelBuilder<HomeViewModel>.reactive(
      onModelReady: (viewModel) => viewModel.initialiseModel(),
      viewModelBuilder: () => HomeViewModel(),
      builder: (context, viewModel, child) {
        return viewModel.networkStatus
            ? Scaffold(
                bottomNavigationBar: BottomNavigationBar(
                  currentIndex: viewModel.currentPage,
                  type: BottomNavigationBarType.fixed,
                  showSelectedLabels: true,
                  showUnselectedLabels: false,
                  selectedItemColor: primaryColor,
                  iconSize: 30,
                  onTap: (value) => viewModel.changePage(value),
                  items: const [
                    BottomNavigationBarItem(
                      icon: Icon(EvaIcons.home),
                      label: 'Home',
                    ),
                    BottomNavigationBarItem(
                      icon: Icon(EvaIcons.activity),
                      label: 'Bookings',
                    ),
                    BottomNavigationBarItem(
                      icon: Icon(EvaIcons.search),
                      label: 'Explore',
                    ),
                    BottomNavigationBarItem(
                      icon: Icon(EvaIcons.messageCircle),
                      label: 'Chats',
                    ),
                    BottomNavigationBarItem(
                      icon: Icon(EvaIcons.person),
                      label: 'Profile',
                    ),
                  ],
                ),
                body: viewModel.pagesList[viewModel.currentPage],
              )
            : ErrorComponent(
                text: 'No Internet Connection',
                buttonTitle: 'Retry',
                onTap: () {
                  Get.offNamed('/home');
                },
              );
      },
    );
  }
}

I am using the stacked package for state management and get package for routing. All the children pages are only making the initialisation functions once so as to maintain state when navigating with the bottom navigation bar.

This is the success page;

import 'package:customer_app_reloaded/app/size_constant.dart';
import 'package:customer_app_reloaded/helpers/images.dart';
import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:get/get.dart';
import 'package:lottie/lottie.dart';
import 'package:nb_utils/nb_utils.dart';

class SuccessComponent extends HookWidget {
  final String successMessage;
  const SuccessComponent({
    Key? key,
    required this.successMessage,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    useEffect(
      () {
        Future.microtask(
          () => Future.delayed(
            const Duration(seconds: 3),
            () => Get.offNamed('/home'),
          ),
        );
      },
      [],
    );

    return Scaffold(
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            SizedBox(
              height: screenHeight(context, dividedBy: 4),
              child: Lottie.asset(successLottie),
            ),
            15.height,
            Text(
              successMessage,
              style: const TextStyle(fontSize: 19),
              textAlign: TextAlign.center,
            )
          ],
        ),
      ),
    );
  }
}

As you can see the success page redirects to the home page after 3 seconds and this is where i would like to do a sort of auto reload of the home widget so that the children widgets would also get auto reloaded. Been struggling with this for a while now and would appreciate any help



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source