mehery_sender 0.1.9
mehery_sender: ^0.1.9 copied to clipboard
A Flutter package to send device tokens to a server.
PushApp Flutter SDK #
Flutter SDK for push notifications, event tracking, and in-app messages (popup, banner, PiP, inline, tooltip).
What Your App Must Add (Quick Checklist) #
Your Flutter app should include all of the following:
- Firebase config files:
- Android:
android/app/google-services.json - iOS:
ios/Runner/GoogleService-Info.plist
- Android:
- iOS push capability and foreground notification handling in
AppDelegate.swift - SDK initialization at app startup:
Pushapp(...).initializeAndSendToken() - User identity and tracking calls based on your user journey:
loginlogoutinitPagesendEvent
- In-app context registration using
setInAppNotification(context) - Placeholder/tooltip registration if inline or tooltip surfaces are used
Part 1 - Setup #
1.1 Dependencies #
Add this to your app's pubspec.yaml:
dependencies:
flutter:
sdk: flutter
mehery_sender: ^0.1.8
firebase_core: ^4.0.0
firebase_messaging: ^16.0.0
Run:
flutter pub get
1.2 Firebase Console #
- Open Firebase Console.
- Create/select a project.
- Register Android app using your
applicationId. - Register iOS app using your Xcode bundle ID.
Download and place files:
- Android:
google-services.json->android/app/google-services.json - iOS:
GoogleService-Info.plist->ios/Runner/GoogleService-Info.plist
In Xcode, ensure GoogleService-Info.plist is added to the Runner target.
1.3 FlutterFire CLI (Recommended) #
Generate lib/firebase_options.dart:
dart pub global activate flutterfire_cli
flutterfire configure
1.4 Android Platform Config #
In android/settings.gradle.kts, ensure Google Services plugin is available:
plugins {
id("dev.flutter.flutter-plugin-loader") version "1.0.0"
id("com.android.application") version "8.11.1" apply false
id("org.jetbrains.kotlin.android") version "2.2.20" apply false
id("com.google.gms.google-services") version "4.4.2" apply false
}
In android/app/build.gradle.kts, apply plugin:
plugins {
id("com.android.application")
id("kotlin-android")
id("dev.flutter.flutter-gradle-plugin")
id("com.google.gms.google-services")
}
In android/app/src/main/AndroidManifest.xml, add notification permission:
<uses-permission android:name="android.permission.POST_NOTIFICATIONS"/>
1.5 iOS Platform Config #
In Xcode -> Runner -> Signing & Capabilities:
- Enable Push Notifications
- Enable Background Modes -> Remote notifications (recommended)
In ios/Runner/Runner.entitlements, verify:
<key>aps-environment</key>
<string>development</string>
Use production for App Store/TestFlight builds.
In ios/Runner/AppDelegate.swift, ensure foreground notification delegate registration:
UNUserNotificationCenter.current().delegate = self
application.registerForRemoteNotifications()
In ios/Podfile, set:
platform :ios, '15.0'
Then run:
cd ios && pod install && cd ..
Part 2 - Implementation #
2.1 Import #
import 'package:mehery_sender/mehery_sender.dart';
2.2 SDK instance (lib/push_service.dart) #
import 'package:flutter/material.dart';
import 'package:mehery_sender/mehery_sender.dart';
final pushApp = Pushapp(
identifier: 'demo_1751694691225', // from PushApp dashboard
sandbox: false,
);
final pushAppNavigatorKey = GlobalKey<NavigatorState>();
void registerPushInAppContext() {
final context = pushAppNavigatorKey.currentContext;
if (context != null && context.mounted) {
pushApp.setInAppNotification(context);
}
}
Future<void> initializePushApp() async {
await pushApp.initializeAndSendToken();
registerPushInAppContext();
}
2.3 App entry (lib/main.dart) #
import 'dart:async';
import 'package:firebase_core/firebase_core.dart';
import 'package:firebase_messaging/firebase_messaging.dart';
import 'package:flutter/material.dart';
import 'firebase_options.dart';
import 'push_service.dart';
@pragma('vm:entry-point')
Future<void> firebaseMessagingBackgroundHandler(RemoteMessage message) async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp(
options: DefaultFirebaseOptions.currentPlatform,
);
}
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
FirebaseMessaging.onBackgroundMessage(firebaseMessagingBackgroundHandler);
await Firebase.initializeApp(
options: DefaultFirebaseOptions.currentPlatform,
);
runApp(const MyApp());
unawaited(_setupPush());
}
Future<void> _setupPush() async {
final messaging = FirebaseMessaging.instance;
await messaging.requestPermission(alert: true, badge: true, sound: true);
await initializePushApp();
}
2.4 MaterialApp setup #
Pass navigator key from push_service.dart:
MaterialApp(
navigatorKey: pushAppNavigatorKey,
home: const HomeScreen(),
);
2.5 Login / Logout #
On sign-in:
await pushApp.login(userId);
On sign-out:
await pushApp.logout(userId);
2.6 Screen tracking #
Call in screens where in-app eligibility is required:
@override
void initState() {
super.initState();
pushApp.initPage('dashboard');
}
2.7 Custom events (optional) #
await pushApp.sendEvent('event_name', {'key': 'value'});
2.8 Inline placeholder (optional) #
MeSendWidget(
placeholderId: 'home_banner_slot',
meSend: pushApp,
height: 180,
width: double.infinity,
)
2.9 Tooltip (optional) #
pushApp.registerWidget(
placeholderId: 'checkout_help_button',
child: IconButton(
icon: const Icon(Icons.help_outline),
onPressed: () {},
),
)
Version #
mehery_sender: ^0.1.8
License #
MIT