respond_io_sdk 0.0.3
respond_io_sdk: ^0.0.3 copied to clipboard
Official Respond.io SDK for Flutter - Manage contacts, send messages, and integrate with Respond.io API
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),
),
);
}
}