zeba_academy_notification_hub 1.0.0
zeba_academy_notification_hub: ^1.0.0 copied to clipboard
Smart AI-powered notification toolkit for Flutter apps with predictive timing, summaries, smart content suggestions, and in-app notification widgets.
example/lib/main.dart
import 'package:flutter/material.dart';
import 'package:zeba_academy_notification_hub/zeba_academy_notification_hub.dart';
void main() {
WidgetsFlutterBinding.ensureInitialized();
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: 'Zeba Academy Notification Hub Example',
theme: ThemeData(primarySwatch: Colors.blue),
home: const HomeScreen(),
);
}
}
class HomeScreen extends StatefulWidget {
const HomeScreen({super.key});
@override
State<HomeScreen> createState() => _HomeScreenState();
}
class _HomeScreenState extends State<HomeScreen> {
List<NotificationItem> notifications = [];
@override
void initState() {
super.initState();
// Add example notifications
notifications = [
NotificationItem(
id: '1',
title: 'Welcome',
message: NotificationContentSuggester.generate(),
timestamp: DateTime.now(),
),
NotificationItem(
id: '2',
title: 'Daily Update',
message: NotificationContentSuggester.generate(),
timestamp: DateTime.now(),
),
];
for (var notif in notifications) {
NotificationHub.add(notif);
}
}
void _showDigest() {
String digest = NotificationSummary.generateDigest(NotificationHub.getAll());
showDialog(
context: context,
builder: (_) => AlertDialog(
title: const Text('Notification Digest'),
content: Text(digest),
actions: [
TextButton(
onPressed: () => Navigator.pop(context),
child: const Text('Close'),
),
],
),
);
}
void _showInAppNotification() {
showDialog(
context: context,
builder: (_) => InAppNotification(
title: 'New Alert',
message: NotificationContentSuggester.generate(),
),
);
}
void _syncPushToken() async {
await PushSyncHelper.syncToken(
token: 'EXAMPLE_DEVICE_TOKEN',
serverUrl: 'https://your-backend.com/api/save-token',
);
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('Push token synced!')),
);
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('Zeba Notification Hub Example')),
body: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
ElevatedButton(
onPressed: _showDigest,
child: const Text('Show Notification Digest'),
),
const SizedBox(height: 10),
ElevatedButton(
onPressed: _showInAppNotification,
child: const Text('Show In-App Notification'),
),
const SizedBox(height: 10),
ElevatedButton(
onPressed: _syncPushToken,
child: const Text('Sync Push Token'),
),
],
),
),
);
}
}