颤动钩。在哪里"requestPermission",因为它没有初始化状态



我正在学习Flutter Hooks,但当你需要一个通常在initState中的特定权限请求时,我找不到任何关于使用什么的信息,例如:

class _HomePageState extends State<HomePage> {
@override
void initState() {
super.initState();
_requestPermissions();
_configureDidReceiveLocalNotificationSubject();
_configureSelectNotificationSubject();
}
void _requestPermissions() {
flutterLocalNotificationsPlugin
.resolvePlatformSpecificImplementation<
IOSFlutterLocalNotificationsPlugin>()
?.requestPermissions(
alert: true,
badge: true,
sound: true,
);
flutterLocalNotificationsPlugin
.resolvePlatformSpecificImplementation<
MacOSFlutterLocalNotificationsPlugin>()
?.requestPermissions(
alert: true,
badge: true,
sound: true,
);
}...

现在迁移到使用钩子initState和dispose不是";所需的";因为它为您处理了这一点,这在很多情况下都很好,但我无法思考将这种类型的请求权限放在哪里?

使用class HomePage extends HookWidget时如何请求这些权限?

解决此问题的最简单方法是使用StatefulHookWidget而不是HookWidgetStatefulHookWidget的行为与StatefulWidget一样,但您可以在构建方法内部使用钩子。