颤音:使Splash屏幕加载所有API的数据

发布于 2025-02-10 06:34:26 字数 1000 浏览 1 评论 0原文

我有Flutter应用程序需要将一些API的数据加载到包含动画的飞溅屏幕中。

class _SplashPageState extends State<SplashPage> {
  @override
  void initState() {
    WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
      var auth = Provider.of<AuthProvider>(context, listen: false);
      auth.chekingAuthVariables();

      var loading = Provider.of<LoadingProvider>(context, listen: false);
      loading.getBrands();
      loading.getVideos();

      var catsProv = Provider.of<CatProviders>(context, listen: false);
      catsProv.getCategoryList();
    });

    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return AnimatedSplashScreen(
      backgroundColor: ColorManager.tabBottonNonActive,
      duration: 3000,
      splash: 'assets/splash.png',
      nextScreen: const MainTabPage(),
      splashTransition: SplashTransition.slideTransition,
    );
  }
}

动画的持续时间为3秒钟,有时当网络慢速时,API的数据不加载,这是加载某些屏幕的问题。 加载所有API的数据后,如何使动画持续时间完成?

I have flutter app need to load some api's data in splash screen which contain animation.

class _SplashPageState extends State<SplashPage> {
  @override
  void initState() {
    WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
      var auth = Provider.of<AuthProvider>(context, listen: false);
      auth.chekingAuthVariables();

      var loading = Provider.of<LoadingProvider>(context, listen: false);
      loading.getBrands();
      loading.getVideos();

      var catsProv = Provider.of<CatProviders>(context, listen: false);
      catsProv.getCategoryList();
    });

    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return AnimatedSplashScreen(
      backgroundColor: ColorManager.tabBottonNonActive,
      duration: 3000,
      splash: 'assets/splash.png',
      nextScreen: const MainTabPage(),
      splashTransition: SplashTransition.slideTransition,
    );
  }
}

the duration of animation is 3 seconds, sometimes when the net is slow the api's data dont load which make a problem for loading some screens.
How can I make the duration of animation finish after loading all api's data?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

小瓶盖 2025-02-17 06:34:26
void loadAPIData() {
          WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
          var auth = Provider.of<AuthProvider>(context, listen: false);
          auth.chekingAuthVariables();
    
          var loading = Provider.of<LoadingProvider>(context, listen: false);
          loading.getBrands();
          loading.getVideos();
    
          var catsProv = Provider.of<CatProviders>(context, listen: false);
          catsProv.getCategoryList();
          // run the animation indefinitely and use navigate after retrieving all data
          Navigator.push(
          context,
      MaterialPageRoute(builder: (context) => const SecondRoute()),
             );
        });
    }

我注意到您正在不使用等待的情况下进行API调用,考虑到您正在从异步来源加载数据,这很奇怪。

void loadAPIData() {
          WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
          var auth = Provider.of<AuthProvider>(context, listen: false);
          auth.chekingAuthVariables();
    
          var loading = Provider.of<LoadingProvider>(context, listen: false);
          loading.getBrands();
          loading.getVideos();
    
          var catsProv = Provider.of<CatProviders>(context, listen: false);
          catsProv.getCategoryList();
          // run the animation indefinitely and use navigate after retrieving all data
          Navigator.push(
          context,
      MaterialPageRoute(builder: (context) => const SecondRoute()),
             );
        });
    }

I noticed you are making API calls without using await, which is quite odd considering you are loading data from an asynchronous source.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文