onebear_chat 0.1.1
onebear_chat: ^0.1.1 copied to clipboard
OneBear live-chat SDK for Flutter — wraps the native Android/iOS chat SDKs so a customer app can embed the same OneBear agent-console conversation as every other channel.
example/lib/main.dart
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:onebear_chat/onebear_chat.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({super.key});
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
int _unreadCount = 0;
StreamSubscription<int>? _unreadSub;
@override
void initState() {
super.initState();
initOnebearChat();
}
Future<void> initOnebearChat() async {
// Replace with a real public key + API origin before running this example against a
// live environment — this is a placeholder so `flutter run` doesn't crash on launch.
await OnebearChat.configure(publicKey: 'pk_live_replace_me', apiBaseUrl: 'https://app.onebear.example');
_unreadSub = OnebearChat.unreadCount.listen((count) {
if (!mounted) return;
setState(() => _unreadCount = count);
});
}
@override
void dispose() {
_unreadSub?.cancel();
super.dispose();
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(title: const Text('OneBear Chat example')),
body: Center(
child: ElevatedButton(
onPressed: () => OnebearChat.present(),
child: Text('Open chat${_unreadCount > 0 ? ' ($_unreadCount)' : ''}'),
),
),
),
);
}
}