pushlio_flutter 0.1.11 copy "pushlio_flutter: ^0.1.11" to clipboard
pushlio_flutter: ^0.1.11 copied to clipboard

Pushlio push notification SDK — device registration, rich notifications, delivered/opened receipts, deep links, feature flags and in-app messages.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:pushlio_flutter/pushlio_flutter.dart';

/// How to run (values come from the dashboard — SETUP.md):
/// ```
/// flutter run \
///   --dart-define=PUSHLIO_APP_ID=<App ID from the dashboard> \
///   --dart-define=PUSHLIO_API_URL=https://pushlio.app/api/ingest
/// ```
const appId = String.fromEnvironment('PUSHLIO_APP_ID');
const apiUrl = String.fromEnvironment('PUSHLIO_API_URL');

Future<void> main() async {
  WidgetsFlutterBinding.ensureInitialized();
  if (appId.isNotEmpty && apiUrl.isNotEmpty) {
    await Pushlio.init(appId: appId, apiUrl: apiUrl);
  }
  runApp(const ExampleApp());
}

class ExampleApp extends StatelessWidget {
  const ExampleApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Pushlio Example',
      theme: ThemeData(colorSchemeSeed: Colors.deepPurple),
      darkTheme: ThemeData(
        colorSchemeSeed: Colors.deepPurple,
        brightness: Brightness.dark,
      ),
      home: const HomePage(),
    );
  }
}

class HomePage extends StatefulWidget {
  const HomePage({super.key});

  @override
  State<HomePage> createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  String? _deviceUid;
  String? _token;
  bool? _permission;
  final List<String> _log = [];

  @override
  void initState() {
    super.initState();
    _load();

    // Clicks (including cold-start): handle the deep link here
    Pushlio.onClick((n) {
      setState(() {
        _log.insert(
          0,
          '🔔 click: campaign=${n.campaignId.substring(0, 8)}… '
          'button=${n.actionId ?? "body"} link=${n.effectiveDeepLink ?? "-"} '
          'data=${n.data}',
        );
      });
    });
  }

  Future<void> _load() async {
    final uid = await Pushlio.getDeviceUid();
    final token = await Pushlio.getToken();
    if (mounted) {
      setState(() {
        _deviceUid = uid;
        _token = token;
      });
    }
  }

  void _note(String s) => setState(() => _log.insert(0, s));

  @override
  Widget build(BuildContext context) {
    const configured = appId != '' && apiUrl != '';

    return Scaffold(
      appBar: AppBar(title: const Text('Pushlio Example')),
      body: !configured
          ? const Center(
              child: Padding(
                padding: EdgeInsets.all(24),
                child: Text(
                  'PUSHLIO_APP_ID ve PUSHLIO_API_URL dart-define ile verilmedi.\n\n'
                  'flutter run --dart-define=PUSHLIO_APP_ID=... '
                  '--dart-define=PUSHLIO_API_URL=...',
                  textAlign: TextAlign.center,
                ),
              ),
            )
          : ListView(
              padding: const EdgeInsets.all(16),
              children: [
                Card(
                  child: Padding(
                    padding: const EdgeInsets.all(12),
                    child: Column(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        Text('Device UID: ${_deviceUid ?? "…"}',
                            style: const TextStyle(fontSize: 12)),
                        const SizedBox(height: 4),
                        Text(
                          'FCM Token: ${_token == null ? "yok (Firebase kurulumu gerekli)" : "${_token!.substring(0, 24)}…"}',
                          style: const TextStyle(fontSize: 12),
                        ),
                        Text('Permission: ${_permission?.toString() ?? "unknown"}',
                            style: const TextStyle(fontSize: 12)),
                      ],
                    ),
                  ),
                ),
                const SizedBox(height: 8),
                Wrap(
                  spacing: 8,
                  runSpacing: 8,
                  children: [
                    FilledButton(
                      onPressed: () async {
                        final ok = await Pushlio.requestPermission();
                        setState(() => _permission = ok);
                        _note('izin: $ok');
                      },
                      child: const Text('Bildirim izni iste'),
                    ),
                    OutlinedButton(
                      onPressed: () async {
                        await Pushlio.login('user_42');
                        _note('login: user_42');
                      },
                      child: const Text('Login (user_42)'),
                    ),
                    OutlinedButton(
                      onPressed: () async {
                        await Pushlio.logout();
                        _note('logout');
                      },
                      child: const Text('Logout'),
                    ),
                    OutlinedButton(
                      onPressed: () async {
                        await Pushlio.setTags(
                            {'premium': 'true', 'level': '12'});
                        _note('tag: premium=true, level=12');
                      },
                      child: const Text('Tag set et'),
                    ),
                    OutlinedButton(
                      onPressed: () async {
                        await Pushlio.removeTag('premium');
                        _note('tag silindi: premium');
                      },
                      child: const Text('Tag sil'),
                    ),
                    OutlinedButton(
                      onPressed: () async {
                        await Pushlio.trackEvent(
                            'level_completed', {'level': 12});
                        _note('event: level_completed');
                      },
                      child: const Text('Send event'),
                    ),
                    OutlinedButton(
                      onPressed: _load,
                      child: const Text('UID/Token yenile'),
                    ),
                  ],
                ),
                const Divider(height: 32),
                const Text('Event log',
                    style: TextStyle(fontWeight: FontWeight.bold)),
                const SizedBox(height: 8),
                if (_log.isEmpty)
                  const Text('No events yet — send a notification from the panel!'),
                ..._log.map(
                  (line) => Padding(
                    padding: const EdgeInsets.symmetric(vertical: 4),
                    child: Text(line, style: const TextStyle(fontSize: 12)),
                  ),
                ),
              ],
            ),
    );
  }
}
0
likes
150
points
565
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

Pushlio push notification SDK — device registration, rich notifications, delivered/opened receipts, deep links, feature flags and in-app messages.

Homepage
Repository (GitHub)
View/report issues

License

MIT (license)

Dependencies

device_info_plus, firebase_core, firebase_messaging, flutter, flutter_local_notifications, http, package_info_plus, path_provider, shared_preferences

More

Packages that depend on pushlio_flutter