respond_io_sdk 0.0.4 copy "respond_io_sdk: ^0.0.4" to clipboard
respond_io_sdk: ^0.0.4 copied to clipboard

Official Respond.io SDK for Flutter - Manage contacts, send messages, and integrate with Respond.io API

example/lib/main.dart

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

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

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Respond.io SDK Example',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.blue),
        useMaterial3: true,
      ),
      home: const MyHomePage(title: 'Respond.io SDK Example'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key, required this.title});

  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  // TODO: Replace with your actual API token
  final String _apiToken = 'YOUR_API_TOKEN';
  late final RespondIO _respondIO;

  String _status = 'Ready';
  List<Contact> _contacts = [];
  bool _isLoading = false;

  @override
  void initState() {
    super.initState();
    _respondIO = RespondIO(RespondIOConfig(apiToken: _apiToken));
  }

  Future<void> _fetchContacts() async {
    if (_apiToken == 'YOUR_API_TOKEN') {
      setState(() {
        _status = 'Please set your API token in lib/main.dart';
      });
      return;
    }

    setState(() {
      _isLoading = true;
      _status = 'Fetching contacts...';
    });

    try {
      final result = await _respondIO.contacts.list(
        ContactFilter(timezone: 'UTC', filter: {}),
        pagination: const PaginationParams(limit: 10),
      );

      final contacts = result['items'] as List<Contact>;

      setState(() {
        _contacts = contacts;
        _status = 'Fetched ${contacts.length} contacts';
        _isLoading = false;
      });
    } catch (e) {
      setState(() {
        _status = 'Error: $e';
        _isLoading = false;
      });
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
        title: Text(widget.title),
      ),
      body: Column(
        children: [
          Padding(padding: const EdgeInsets.all(16.0), child: Text(_status)),
          Expanded(
            child: _isLoading
                ? const Center(child: CircularProgressIndicator())
                : ListView.builder(
                    itemCount: _contacts.length,
                    itemBuilder: (context, index) {
                      final contact = _contacts[index];
                      return ListTile(
                        leading: CircleAvatar(
                          backgroundImage: contact.profilePic != null
                              ? NetworkImage(contact.profilePic!)
                              : null,
                          child: contact.profilePic == null
                              ? Text(contact.firstName[0])
                              : null,
                        ),
                        title: Text(
                          '${contact.firstName} ${contact.lastName ?? ''}',
                        ),
                        subtitle: Text(
                          contact.email ?? contact.phone ?? 'No contact info',
                        ),
                      );
                    },
                  ),
          ),
        ],
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _fetchContacts,
        tooltip: 'Fetch Contacts',
        child: const Icon(Icons.refresh),
      ),
    );
  }
}
0
likes
160
points
--
downloads

Publisher

unverified uploader

Weekly Downloads

Official Respond.io SDK for Flutter - Manage contacts, send messages, and integrate with Respond.io API

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

dio, flutter, freezed_annotation, json_annotation

More

Packages that depend on respond_io_sdk