homePageFloatingActionButton function Home

FloatingActionButton? homePageFloatingActionButton(
  1. BuildContext context,
  2. WidgetRef ref
)

The FloatingActionButton at the bottom of the HomePage.

When the Feed is shown, the button navigates to the CreatePostPage page. When the Calendar is shown, the button navigates to CreateActivityPage. The latter is only available for admins. This still needs to be implemented.

Implementation

FloatingActionButton? homePageFloatingActionButton(
  BuildContext context,
  WidgetRef ref,
) {
  final int index = ref.watch(homepageProvider.select((model) => model.index));
  if (GoRouterState.of(context).uri.toString() != "/") return null;
  if (index == 0) {
    return FloatingActionButton.small(
      key: const Key("createPost"),
      onPressed: () {
        // We reset the createPostProvider to its initial state.
        ref.invalidate(createPostProvider);
        const CreatePostRoute().go(context);
      },
      child: const Icon(Icons.create),
    );
  } else {
    if (ref.watch(currentUserProvider)?.customClaims.admin ?? false) {
      return FloatingActionButton.small(
        key: const Key("createActivity"),
        onPressed: () {
          // We reset the createActivityProvider to its initial state.
          ref.invalidate(createActivityProvider);
          const CreateEventRoute().go(context);
        },
        child: const Icon(Icons.add),
      );
    } else {
      return null;
    }
  }
}