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).
curlandpython3available 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:setupinside a project that includeshosteday_flutterwhen 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
- 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
);
- Automatically update when the token refreshes (
onTokenRefresh):
FirebaseMessaging.instance.onTokenRefresh.listen((newToken) async {
await Hosteday.notifications.syncDeviceToken(
deviceToken: newToken,
deviceId: deviceId,
);
});
- Unlink the device on logout (
unlink):
await Hosteday.notifications.unlink(deviceId: deviceId);
- Deep Links Support: Pass a target route inside the
datapayload 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:
- Continue to: Device Management & Sending Notifications