brevoflutter 0.1.1 copy "brevoflutter: ^0.1.1" to clipboard
brevoflutter: ^0.1.1 copied to clipboard

A Flutter package for Brevo (formerly Sendinblue) Marketing Automation API integration. Track users, events, link clicks, and page views with type-safe models and comprehensive error handling.

example/lib/main.dart

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

void main() {
  BrevoTracker.instance.initialize(
    apiKey: 'YOUR_MA_KEY_HERE',
  );

  runApp(const MyApp());
}

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Brevo Tracker Demo',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        useMaterial3: true,
      ),
      home: const BrevoTrackerDemo(),
    );
  }
}

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

  @override
  State<BrevoTrackerDemo> createState() => _BrevoTrackerDemoState();
}

class _BrevoTrackerDemoState extends State<BrevoTrackerDemo> {
  final TextEditingController _emailController = TextEditingController(
    text: 'user@example.com',
  );
  String _result = '';
  bool _isLoading = false;

  Future<void> _identifyUser() async {
    setState(() {
      _isLoading = true;
      _result = '';
    });

    try {
      final response = await BrevoTracker.instance.identifyUser(
        email: _emailController.text,
        attributes: {
          'FirstName': 'John',
          'LastName': 'Doe',
          'Age': 30,
          'SMS': 919989894562,
        },
      );

      setState(() {
        _result = 'User identified successfully!\n'
            'Status: ${response.statusCode}\n'
            'Success: ${response.success}';
      });
    } on BrevoException catch (e) {
      setState(() {
        _result = 'Error: ${e.message}';
      });
    } finally {
      setState(() {
        _isLoading = false;
      });
    }
  }

  Future<void> _trackEvent() async {
    setState(() {
      _isLoading = true;
      _result = '';
    });

    try {
      final response = await BrevoTracker.instance.trackEvent(
        email: _emailController.text,
        event: 'cart_updated',
        eventData: {
          'data': {
            'added_product': [
              {
                'currency': 'EUR',
                'name': 'Wrist watch',
                'type': 'accessories',
                'price': '50.00',
              }
            ],
          },
        },
        properties: {
          'cart_total': '150.00',
          'items_count': 3,
        },
      );

      setState(() {
        _result = 'Event tracked successfully!\n'
            'Status: ${response.statusCode}\n'
            'Success: ${response.success}';
      });
    } on BrevoException catch (e) {
      setState(() {
        _result = 'Error: ${e.message}';
      });
    } finally {
      setState(() {
        _isLoading = false;
      });
    }
  }

  Future<void> _trackLink() async {
    setState(() {
      _isLoading = true;
      _result = '';
    });

    try {
      final response = await BrevoTracker.instance.trackLink(
        email: _emailController.text,
        link: 'https://example.com/document.pdf',
        properties: {
          'category': 'downloads',
          'document_type': 'case_study',
        },
      );

      setState(() {
        _result = 'Link tracked successfully!\n'
            'Status: ${response.statusCode}\n'
            'Success: ${response.success}';
      });
    } on BrevoException catch (e) {
      setState(() {
        _result = 'Error: ${e.message}';
      });
    } finally {
      setState(() {
        _isLoading = false;
      });
    }
  }

  Future<void> _trackPage() async {
    setState(() {
      _isLoading = true;
      _result = '';
    });

    try {
      final response = await BrevoTracker.instance.trackPage(
        email: _emailController.text,
        page: 'Checkout',
        properties: {
          'title': 'Checkout - Step 2',
          'url': '/checkout/payment',
          'referrer': '/cart',
        },
      );

      setState(() {
        _result = 'Page tracked successfully!\n'
            'Status: ${response.statusCode}\n'
            'Success: ${response.success}';
      });
    } on BrevoException catch (e) {
      setState(() {
        _result = 'Error: ${e.message}';
      });
    } finally {
      setState(() {
        _isLoading = false;
      });
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
        title: const Text('Brevo Tracker Demo'),
      ),
      body: SingleChildScrollView(
        padding: const EdgeInsets.all(16.0),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.stretch,
          children: [
            TextField(
              controller: _emailController,
              decoration: const InputDecoration(
                labelText: 'Email',
                border: OutlineInputBorder(),
                hintText: 'user@example.com',
              ),
              keyboardType: TextInputType.emailAddress,
            ),
            const SizedBox(height: 24),
            ElevatedButton.icon(
              onPressed: _isLoading ? null : _identifyUser,
              icon: const Icon(Icons.person_add),
              label: const Text('Identify User'),
            ),
            const SizedBox(height: 12),
            ElevatedButton.icon(
              onPressed: _isLoading ? null : _trackEvent,
              icon: const Icon(Icons.event),
              label: const Text('Track Event'),
            ),
            const SizedBox(height: 12),
            ElevatedButton.icon(
              onPressed: _isLoading ? null : _trackLink,
              icon: const Icon(Icons.link),
              label: const Text('Track Link Click'),
            ),
            const SizedBox(height: 12),
            ElevatedButton.icon(
              onPressed: _isLoading ? null : _trackPage,
              icon: const Icon(Icons.pageview),
              label: const Text('Track Page View'),
            ),
            const SizedBox(height: 24),
            if (_isLoading)
              const Center(
                child: CircularProgressIndicator(),
              ),
            if (_result.isNotEmpty)
              Card(
                child: Padding(
                  padding: const EdgeInsets.all(16.0),
                  child: Text(
                    _result,
                    style: Theme.of(context).textTheme.bodyMedium,
                  ),
                ),
              ),
          ],
        ),
      ),
    );
  }

  @override
  void dispose() {
    _emailController.dispose();
    super.dispose();
  }
}
0
likes
140
points
119
downloads

Publisher

unverified uploader

Weekly Downloads

A Flutter package for Brevo (formerly Sendinblue) Marketing Automation API integration. Track users, events, link clicks, and page views with type-safe models and comprehensive error handling.

Documentation

API reference

License

MIT (license)

Dependencies

cupertino_icons, flutter, http

More

Packages that depend on brevoflutter