ordersune_crm_flutter_sdk 0.0.5 copy "ordersune_crm_flutter_sdk: ^0.0.5" to clipboard
ordersune_crm_flutter_sdk: ^0.0.5 copied to clipboard

A Flutter-ready CRM tool to manage notifications, in-app messages, email campaigns.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:ordersune_crm_flutter_sdk/ordersune_crm_flutter_sdk.dart';
import 'package:ordersune_crm_flutter_sdk/types.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'OrderSune CRM Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: CRMHomePage(),
    );
  }
}

class CRMHomePage extends StatefulWidget {
  @override
  _CRMHomePageState createState() => _CRMHomePageState();
}

class _CRMHomePageState extends State<CRMHomePage> {
  late CRM crm;
  bool isInitialized = false;
  String status = 'Initializing CRM...';

  @override
  void initState() {
    super.initState();
    initializeCRM();
  }

  Future<void> initializeCRM() async {
    try {
      // Step 1: Create CRM instance with configuration
      crm = CRM(SDKConfig(
        apiKey: 'your_api_key_here',
        endpoint: 'https://your-api-endpoint.com',
        debug: true,
        batchSize: 10,
        batchInterval: 10000,
      ));

      // Step 2: Initialize the SDK (REQUIRED!)
      await crm.initialize();

      setState(() {
        isInitialized = true;
        status = 'CRM Initialized Successfully!';
      });

      // Step 3: Set push token (optional, when available)
      // crm.setToken('your_firebase_push_token');

      // Step 4: Identify user (optional)
      crm.identify('user_12345');

      // Step 5: Track initial events and attributes
      crm.trackEvent('app_opened', {
        'screen': 'home',
        'timestamp': DateTime.now().millisecondsSinceEpoch,
      });

      crm.trackCustomAttribute('user_preference', 'demo_user');
      crm.trackCustomAttribute('app_version', '1.0.0');

    } catch (e) {
      setState(() {
        status = 'CRM Initialization Failed: $e';
      });
    }
  }

  void trackButtonPress() {
    if (isInitialized) {
      crm.trackEvent('demo_button_pressed', {
        'button_name': 'demo_button',
        'pressed_at': DateTime.now().toString(),
        'screen': 'home',
      });
      
      setState(() {
        status = 'Button press tracked!';
      });
    }
  }

  void trackPurchase() {
    if (isInitialized) {
      crm.logProductPurchase(
        'order_123456',
        'product_789',
        'Demo Product',
        29.99,
        1,
        'mobile_app',
        'online',
        itemCategory: 'electronics',
      );
      
      setState(() {
        status = 'Purchase tracked!';
      });
    }
  }

  void clearUserData() async {
    if (isInitialized) {
      await crm.clearUserData();
      setState(() {
        status = 'User data cleared! New guest user created.';
      });
    }
  }

  void forceSendData() async {
    if (isInitialized) {
      try {
        await crm.forceSend();
        setState(() {
          status = 'Data sent to server!';
        });
      } catch (e) {
        setState(() {
          status = 'Send failed: $e';
        });
      }
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('OrderSune CRM Demo'),
        backgroundColor: Colors.blue,
      ),
      body: Padding(
        padding: const EdgeInsets.all(16.0),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.stretch,
          children: [
            Card(
              child: Padding(
                padding: const EdgeInsets.all(16.0),
                child: Column(
                  children: [
                    Icon(
                      isInitialized ? Icons.check_circle : Icons.hourglass_empty,
                      color: isInitialized ? Colors.green : Colors.orange,
                      size: 48,
                    ),
                    SizedBox(height: 8),
                    Text(
                      status,
                      style: TextStyle(fontSize: 16),
                      textAlign: TextAlign.center,
                    ),
                  ],
                ),
              ),
            ),
            SizedBox(height: 24),
            ElevatedButton(
              onPressed: isInitialized ? trackButtonPress : null,
              child: Text('Track Button Press Event'),
            ),
            SizedBox(height: 12),
            ElevatedButton(
              onPressed: isInitialized ? trackPurchase : null,
              child: Text('Track Purchase Event'),
            ),
            SizedBox(height: 12),
            ElevatedButton(
              onPressed: isInitialized ? forceSendData : null,
              child: Text('Force Send Data'),
            ),
            SizedBox(height: 12),
            ElevatedButton(
              onPressed: isInitialized ? clearUserData : null,
              style: ElevatedButton.styleFrom(backgroundColor: Colors.orange),
              child: Text('Clear User Data'),
            ),
            SizedBox(height: 24),
            if (isInitialized)
              Card(
                child: Padding(
                  padding: const EdgeInsets.all(16.0),
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      Text(
                        'Current User:',
                        style: TextStyle(fontWeight: FontWeight.bold),
                      ),
                      SizedBox(height: 8),
                      Text('ID: ${crm.getUserProfile()?.id ?? 'Not set'}'),
                      Text('Guest ID: ${crm.getUserProfile()?.guestUserId ?? 'Not set'}'),
                    ],
                  ),
                ),
              ),
          ],
        ),
      ),
    );
  }
}
0
likes
140
points
184
downloads

Publisher

verified publishersuntechsolutions.com

Weekly Downloads

A Flutter-ready CRM tool to manage notifications, in-app messages, email campaigns.

Homepage

Documentation

API reference

License

MIT (license)

Dependencies

device_info_plus, flutter, flutter_timezone, http, package_info_plus, shared_preferences, url_launcher, uuid

More

Packages that depend on ordersune_crm_flutter_sdk