termii_resolve_livechat 0.1.0
termii_resolve_livechat: ^0.1.0 copied to clipboard
Termii Resolve Live Chat SDK for Flutter. Add Termii in-app customer support to any Flutter app in a few lines, with user identification and unread-count events.
example/lib/main.dart
import 'package:flutter/material.dart';
import 'package:termii_resolve_livechat/termii_resolve_livechat.dart';
// Replace with your widget ID from the Termii dashboard, or run with
// --dart-define=RESOLVE_WIDGET_ID=...
const String widgetId = String.fromEnvironment('RESOLVE_WIDGET_ID');
void main() => runApp(const DemoApp());
class DemoApp extends StatelessWidget {
const DemoApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Termii Live Chat Demo',
theme: ThemeData(colorSchemeSeed: const Color(0xFF1F3D2B)),
home: const HomePage(),
);
}
}
class HomePage extends StatefulWidget {
const HomePage({super.key});
@override
State<HomePage> createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
int _unread = 0;
Future<void> _openChat() async {
if (widgetId.isEmpty) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text(
'No widget ID. Run with --dart-define=RESOLVE_WIDGET_ID=...',
),
),
);
return;
}
await TermiiLiveChat.open(
context,
widgetId: widgetId,
user: const TermiiUser(email: 'jane@example.com', name: 'Jane Doe'),
onUnreadCountChanged: (count) => setState(() => _unread = count),
onError: (event) => ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text('Chat error: ${event.errorMessage}')),
),
);
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('Termii Live Chat Demo')),
floatingActionButton: Badge(
isLabelVisible: _unread > 0,
label: Text('$_unread'),
child: FloatingActionButton.extended(
onPressed: _openChat,
icon: const Icon(Icons.chat_bubble_outline),
label: const Text('Support'),
),
),
body: const Center(child: Text('Tap "Support" to open the chat.')),
);
}
}