@@ -113,22 +113,31 @@ apply plugin: 'com.google.gms.google-services'
113113
114114## Quick Start Guide
115115
116- ### 1. Initialize the Plugin
116+ ### 1. One-Line Setup
117117
118- Configure the plugin once at app startup with your project ID :
118+ The simplest way to get started - this handles everything for most apps :
119119
120120``` dart
121121import 'package:pnta_flutter/pnta_flutter.dart';
122122
123123void main() async {
124124 WidgetsFlutterBinding.ensureInitialized();
125125
126+ // One line setup - requests permission and registers device
126127 await PntaFlutter.initialize(
127128 'prj_XXXXXXXXX', // Your project ID from app.pnta.io
128- autoHandleLinks: true, // Auto-open links from background notifications
129- showSystemUI: false, // Hide system notification UI when app is in foreground
129+ metadata: {
130+ 'user_id': '123',
131+ 'user_email': 'user@example.com',
132+ },
130133 );
131134
135+ // Optional: Get the device token if you need it for your backend
136+ // final deviceToken = await PntaFlutter.initialize(...);
137+ // if (deviceToken != null) {
138+ // print('Device token: $deviceToken');
139+ // }
140+
132141 runApp(MyApp());
133142}
134143```
@@ -144,42 +153,43 @@ MaterialApp(
144153)
145154```
146155
147- ### 3. Request Notification Permission
156+ ### 3. Advanced: Delayed Permission Flow
148157
149- ``` dart
150- final granted = await PntaFlutter.requestNotificationPermission();
151- if (granted) {
152- print('Notification permission granted');
153- } else {
154- print('Notification permission denied');
155- }
156- ```
158+ For apps that need to ask for permission at a specific time (e.g., after user onboarding):
157159
158- ### 4. Identify Your Device
160+ ``` dart
161+ void main() async {
162+ WidgetsFlutterBinding.ensureInitialized();
159163
160- After requesting notification permission, register the device with optional metadata. The project ID is already set during initialization.
164+ // Initialize without requesting permission
165+ await PntaFlutter.initialize(
166+ 'prj_XXXXXXXXX',
167+ requestPermission: false, // Skip permission request
168+ );
161169
162- There are two ways to call this method:
170+ runApp(MyApp());
171+ }
163172
164- ``` dart
165- // Option 1: Simple identification (device token handled internally)
166- await PntaFlutter.identify(metadata: {
167- 'user_id': '123',
168- 'user_email': 'user@example.com',
169- });
173+ // Later in your app, when ready to ask for permission:
174+ Future<void> setupNotifications() async {
175+ await PntaFlutter.requestPermission(
176+ metadata: {
177+ 'user_id': '123',
178+ 'user_email': 'user@example.com',
179+ },
180+ );
170181
171- // Option 2: Get the device token returned (if you need it for your backend)
172- final deviceToken = await PntaFlutter.identify(metadata: {
173- 'user_id': '123',
174- 'user_email': 'user@example.com',
175- });
176- if (deviceToken != null) {
177- print('Device token: $deviceToken');
178- // Store or send to your backend if needed
182+ // Optional: Get the device token if you need it for your backend
183+ // final deviceToken = await PntaFlutter.requestPermission(...);
184+ // if (deviceToken != null) {
185+ // print('Permission granted and device registered!');
186+ // } else {
187+ // print('Permission denied or registration failed');
188+ // }
179189}
180190```
181191
182- ### 5 . Handle Notifications
192+ ### 4 . Handle Notifications
183193
184194#### Foreground Notifications
185195
@@ -219,30 +229,29 @@ PntaFlutter.onNotificationTap.listen((payload) {
219229
220230### Core Methods
221231
222- #### ` PntaFlutter.initialize(String projectId, {bool autoHandleLinks, bool showSystemUI}) `
232+ #### ` PntaFlutter.initialize(String projectId, {Map<String, dynamic>? metadata, bool requestPermission, bool autoHandleLinks, bool showSystemUI}) `
223233
224- Initializes the plugin with your project ID and configuration options.
234+ Main initialization method that handles everything for most apps:
225235
226236- ` projectId ` : Your PNTA project ID (format: ` prj_XXXXXXXXX ` ) from [ app.pnta.io] ( https://app.pnta.io )
227- - ` autoHandleLinks ` : Automatically handle ` link_to ` URLs when notifications are tapped from background/terminated state
228- - ` showSystemUI ` : Show system notification banner/sound when app is in foreground
237+ - ` metadata ` : Optional device metadata to include during registration
238+ - ` requestPermission ` : Whether to request permission and register device immediately (default: ` true ` )
239+ - ` autoHandleLinks ` : Automatically handle ` link_to ` URLs when notifications are tapped (default: ` true ` )
240+ - ` showSystemUI ` : Show system notification banner/sound when app is in foreground (default: ` false ` )
229241
230- #### ` PntaFlutter.requestNotificationPermission() `
242+ Returns ` Future<String?> ` - the device token if permission was granted and device registered, null otherwise.
231243
232- Requests notification permission from the user. Returns ` Future<bool> ` .
244+ #### ` PntaFlutter.requestPermission({Map<String, dynamic>? metadata}) `
233245
234- #### ` PntaFlutter.identify({Map<String, dynamic>? metadata}) `
246+ For delayed permission scenarios. Must be called after ` initialize() ` with ` requestPermission: false ` .
235247
236- Registers the device with your PNTA project using the project ID from initialization. Can be called in two ways:
248+ - ` metadata ` : Optional device metadata to include during registration (merged with metadata from initialize)
237249
238- - ** Without storing token** : ` await PntaFlutter.identify(metadata: {...}) `
239- - ** With token returned** : ` final token = await PntaFlutter.identify(metadata: {...}) `
250+ Returns ` Future<String?> ` - the device token if permission was granted and device registered, null otherwise. ** Note: You can ignore the return value if you don't need the token.**
240251
241- Returns the device token as ` Future <String?> ` if you need it for your own backend or logging.
252+ #### ` PntaFlutter.updateMetadata(Map <String, dynamic> metadata) `
242253
243- #### ` PntaFlutter.updateMetadata({Map<String, dynamic>? metadata}) `
244-
245- Updates device metadata without re-registering. Uses the project ID from initialization. Returns ` Future<void> ` .
254+ Updates device metadata without re-registering. Must be called after successful initialization. Returns ` Future<void> ` .
246255
247256#### ` PntaFlutter.handleLink(String link) `
248257
@@ -284,8 +293,8 @@ class UserMetadata {
284293}
285294
286295// Use everywhere
287- await PntaFlutter.identify( metadata: UserMetadata.current);
288- await PntaFlutter.updateMetadata(metadata: UserMetadata.current);
296+ await PntaFlutter.initialize('prj_XXXXXXXXX', metadata: UserMetadata.current);
297+ await PntaFlutter.updateMetadata(UserMetadata.current);
289298```
290299
291300## Simple Example
@@ -297,13 +306,19 @@ import 'package:pnta_flutter/pnta_flutter.dart';
297306void main() async {
298307 WidgetsFlutterBinding.ensureInitialized();
299308
300- // Initialize plugin with project ID
301- await PntaFlutter.initialize(
309+ // One-line setup - handles permission, registration, and configuration
310+ final deviceToken = await PntaFlutter.initialize(
302311 'prj_XXXXXXXXX', // Your project ID from app.pnta.io
303- autoHandleLinks: true, // Auto-handle links from background taps
304- showSystemUI: false, // Hide system UI in foreground
312+ metadata: {
313+ 'user_id': '123',
314+ 'user_email': 'user@example.com',
315+ },
305316 );
306317
318+ if (deviceToken != null) {
319+ print('Device registered successfully!');
320+ }
321+
307322 runApp(MyApp());
308323}
309324
@@ -330,15 +345,14 @@ class _HomePageState extends State<HomePage> {
330345 }
331346
332347 void _setupNotifications() async {
333- // Request permission
334- final granted = await PntaFlutter.requestNotificationPermission();
335- if (!granted) return;
336-
337- // Identify device (project ID already set in initialize)
338- await PntaFlutter.identify(metadata: {
339- 'user_id': '123',
340- 'user_email': 'user@example.com',
341- });
348+ // If you used initialize() with requestPermission: true, this is already done!
349+ // Otherwise, for delayed permission scenarios:
350+ // await PntaFlutter.requestPermission(
351+ // metadata: {
352+ // 'user_id': '123',
353+ // 'user_email': 'user@example.com',
354+ // },
355+ // );
342356
343357 // Listen for foreground notifications
344358 PntaFlutter.foregroundNotifications.listen((payload) {
0 commit comments