I am learning Flutter Hooks, but I can't find anything about what to use when you need to have a specific permission request which usually goes in the initState, for example:
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,
);
}...
Now migrating this to use hooks the initState and dispose are not "needed" as it handles that for you which is nice in many situations, but I can't wrap my head around where to place this type of request permissions for example?
How to request those permissions when using class HomePage extends HookWidget?
The simplest way to solve this is by using a
StatefulHookWidgetinstead of aHookWidget.StatefulHookWidgetbehaves just as theStatefulWidgetbut you can use hooks inside of the build method.