呼叫未来的提供商,延迟应用程序中的用户进度



我的目标是通过整个应用程序中的提供者提供用户位置的价值。这对我来说很重要,因为我也想在路线中使用价值。

然而,在我的应用程序中,用户首先需要登录。直到后来他才拿到地图。事情是这样的。根据业务需求,在用户访问地图小部件之前,我不能调用权限。因此,提供商需要在应用程序上,但用户登录后必须调用未来的功能。我怎样才能做到这一点?

这是我的MyApp小部件的一个示例。

class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MultiProvider(
providers: [
StreamProvider<UserModel?>.value(
initialData: null,
value: AuthService().user,
),
FutureProvider<LatLng?>.value(
value: GeolocationService().getUserLocation(),
initialData: null,
)
],
child: MaterialApp(
title: '',
theme: themeData(),
onGenerateRoute: onGenerateRoute(),
builder: EasyLoading.init(),
home: AuthWrapper(),
),
);
}
}
调度程序中的SchedulerBinding.instances。您可以在StatefulWidget 的initState中使用它
{
//inside initState method
SchedulerBinding.instances?.addPostframecallback((_){
//anything run within this function will be called just after the very first build method
// how it works?
// before the build method ran, initState will be called first synchronously 
// after that, build method will be called
// then right after that build method finished the first render task,
// the post frame callback will be called, in this place we can use context
// since the UI has been built
});
}

相关内容

最新更新