Section 2 Official Documentation

Connecting Flutter App via HosteDay CLI

Send and manage push notifications using Firebase FCM v1 for Flutter and other platforms.

Connecting Flutter App via HosteDay CLI

In this guide, you will learn how to connect a Flutter app to your HosteDay App in seconds using the official HosteDay Flutter CLI, auto-generate Firebase configuration files, and sync device tokens for Push Notifications.


Prerequisites

  • Flutter SDK installed (version 3.0 or higher).
  • curl and python3 available in your terminal.
  • Your CLI Token and setup command from the HosteDay Flutter CLI Integration page in your App dashboard at dash.hosteday.com.

Step 1: Run the Official Setup CLI

The setup.sh tool offers two options depending on your project state:

Option 1: Clone the Official Production-Ready Flutter Template (--clone)

curl -fsSL https://dash.hosteday.com/cli/setup.sh | bash -s -- --project=YOUR_APP_SLUG --token='YOUR_CLI_TOKEN' --clone

Option 2: Inject Configuration into an Existing Flutter Project (--dir=.)

cd /path/to/my_flutter_app
curl -fsSL https://dash.hosteday.com/cli/setup.sh | bash -s -- --project=YOUR_APP_SLUG --token='YOUR_CLI_TOKEN' --dir=.

You can also run dart run hosteday_flutter:setup inside a project that includes hosteday_flutter when refreshing configuration.


Step 2: Files Generated Automatically

The CLI generates and places the following configuration files in your Flutter project:

my_flutter_app/
├── lib/
│   └── hosteday_config.dart             # App settings, API URLs, and integration keys
├── android/app/
│   └── google-services.json             # Firebase configuration for Android
├── ios/Runner/
│   └── GoogleService-Info.plist         # Firebase configuration for iOS
└── web/
    ├── firebase-config.json             # Firebase configuration for Web browsers
    └── firebase-messaging-sw.js         # Service Worker for background Web notifications

Step 3: Initialize SDK & Sync Device Tokens in Dart

In main.dart, initialize hosteday_flutter when your app starts:

await Hosteday.initializeApp(
  baseUrl: HostedayConfig.baseUrl,
  apiToken: HostedayConfig.apiToken,
);

Syncing, Refreshing & Unlinking Device Tokens

  1. Sync the device token on login or app launch:
await Hosteday.notifications.syncDeviceToken(
  deviceToken: fcmToken,
  deviceId: deviceId,
  deviceType: 'android', // android, ios, web, macos, windows, linux
);
  1. Automatically update when the token refreshes (onTokenRefresh):
FirebaseMessaging.instance.onTokenRefresh.listen((newToken) async {
  await Hosteday.notifications.syncDeviceToken(
    deviceToken: newToken,
    deviceId: deviceId,
  );
});
  1. Unlink the device on logout (unlink):
await Hosteday.notifications.unlink(deviceId: deviceId);
  1. Deep Links Support: Pass a target route inside the data payload when sending a notification (e.g., {"screen": "/orders/123"}) and read it on notification tap to navigate directly.

Next Step

Now that your Flutter app is configured and syncing tokens, learn how to manage devices and send notifications: