adrian_chat 0.1.0
adrian_chat: ^0.1.0 copied to clipboard
Adrian live chat for Flutter apps. Opens your workspace's chat with forms, action buttons, chat flows and files, and shows an unread badge.
import 'package:adrian_chat/adrian_chat.dart';
import 'package:flutter/material.dart';
final navigatorKey = GlobalKey<NavigatorState>();
void main() {
WidgetsFlutterBinding.ensureInitialized();
// Settings → Chat widget → Install in Adrian. The --dart-define values are for local testing.
Adrian.configure(
workspaceId: const String.fromEnvironment('ADRIAN_WORKSPACE_ID',
defaultValue: 'ws_your_workspace_id'),
widgetUrl: const String.fromEnvironment('ADRIAN_WIDGET_URL',
defaultValue: Adrian.defaultWidgetUrl),
appId: 'com.adrianhq.example',
navigatorKey: navigatorKey,
);
runApp(const ExampleApp());
}
class ExampleApp extends StatelessWidget {
const ExampleApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Acme',
navigatorKey: navigatorKey,
navigatorObservers: [AdrianNavigatorObserver()],
debugShowCheckedModeBanner: false,
theme: ThemeData(
colorSchemeSeed: const Color(0xFF2554EB), useMaterial3: true),
home: const HomePage(),
);
}
}
class HomePage extends StatefulWidget {
const HomePage({super.key});
@override
State<HomePage> createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
bool _signedIn = false;
void _toggleAccount() {
if (_signedIn) {
Adrian.reset();
} else {
Adrian.identify(name: 'Ada Obi', email: 'ada@example.com');
}
setState(() => _signedIn = !_signedIn);
}
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
return Scaffold(
appBar: AppBar(title: const Text('Acme'), centerTitle: true),
floatingActionButton: const AdrianLauncher(),
body: ListView(
padding: const EdgeInsets.all(20),
children: [
Text('Good afternoon',
style: theme.textTheme.bodyMedium
?.copyWith(color: theme.colorScheme.outline)),
Text(_signedIn ? 'Ada Obi' : 'Welcome',
style: theme.textTheme.headlineMedium
?.copyWith(fontWeight: FontWeight.bold)),
const SizedBox(height: 16),
const _Tile(
icon: Icons.credit_card,
title: 'Pay a bill',
detail: 'Taxes, levies and fees'),
const _Tile(
icon: Icons.receipt_long,
title: 'Verify a receipt',
detail: 'Check a payment reference'),
const _Tile(
icon: Icons.history,
title: 'History',
detail: 'Your last 12 payments'),
ValueListenableBuilder<int>(
valueListenable: Adrian.unreadCount,
builder: (context, unread, _) => _Tile(
icon: Icons.help_outline,
title: 'Help & support',
detail: unread > 0
? '$unread new ${unread == 1 ? 'reply' : 'replies'}'
: 'Chat with our team',
onTap: () => Adrian.present(context),
),
),
const SizedBox(height: 8),
Align(
alignment: Alignment.centerLeft,
child: TextButton(
onPressed: _toggleAccount,
child: Text(_signedIn ? 'Sign out' : 'Sign in as Ada')),
),
],
),
);
}
}
class _Tile extends StatelessWidget {
const _Tile(
{required this.icon,
required this.title,
required this.detail,
this.onTap});
final IconData icon;
final String title;
final String detail;
final VoidCallback? onTap;
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
return Padding(
padding: const EdgeInsets.only(bottom: 12),
child: Material(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(16),
side: BorderSide(color: theme.colorScheme.outlineVariant),
),
clipBehavior: Clip.antiAlias,
child: ListTile(
contentPadding:
const EdgeInsets.symmetric(horizontal: 16, vertical: 6),
leading: Icon(icon),
title:
Text(title, style: const TextStyle(fontWeight: FontWeight.w600)),
subtitle: Text(detail),
trailing: onTap == null ? null : const Icon(Icons.chevron_right),
onTap: onTap,
),
),
);
}
}