简体   繁体   English

Flutter Riverpod 在生命周期恢复从服务器获取数据

[英]Flutter Riverpod getting data from server on lifecycle resumed

With this below code i'm trying to get data from server when Flutter lifecycle resumed, but it doesn't work for me and i'm not sure how can i resolve that使用下面的代码,我试图在Flutter生命周期恢复时从服务器获取数据,但它对我不起作用,我不知道如何解决这个问题

class Home extends HookConsumerWidget {
  const Home({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context, WidgetRef ref) {
    final scaffoldKey = useMemoized(() => GlobalKey<ScaffoldState>());
    final appLifecycleState = useAppLifecycleState();
    final showLoading = useState(false);

    useEffect(() {
      ref.read(bakersProvider.notifier).send(
        method: HTTP.GET,
        endPoint: Server.$onlineBakersList,
        parameters: {},
      );
      if (appLifecycleState == AppLifecycleState.resumed) {
        debugPrint('resumed');
        ref.read(bakersProvider.notifier).send(
          method: HTTP.GET,
          endPoint: Server.$onlineBakersList,
          parameters: {},
        );
      }

      return (){};
    }, [appLifecycleState]);

this issue solved.这个问题解决了。 reference 参考

useOnAppLifecycleStateChange((pref, state) {
  if (state == AppLifecycleState.resumed) {
    //make a request
  }
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM