fyral_comms 0.4.2
fyral_comms: ^0.4.2 copied to clipboard
Communication feature package for Fleet Glide Admin
example/lib/main.dart
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'package:fyral_comms/comms.dart';
void main() {
runApp(const CommsExampleApp());
}
/// A premium Example Application demonstrating the usage of the `comms` package.
class CommsExampleApp extends StatelessWidget {
const CommsExampleApp({super.key});
static final GoRouter _router = GoRouter(
initialLocation: '/',
routes: [
GoRoute(
path: '/',
builder: (context, state) => CommsPage(
currentUserId: 2,
showBroadcast: true,
broadcastTitle: 'Broadcast',
onBroadcastTap: () => context.push("/chat/Broadcast"),
onConversationSelected: (conversation) =>
context.push("/chat/${conversation.name}"),
conversations: [
CommsGroup.fromJson(const {
"id": 1,
"group_type": "topic",
"name": "General Support",
"driver_user_id": 8,
"allow_replies": true,
"status": "open",
"created_at": "2026-08-31T10:41:43.225729",
"updated_at": "2026-08-31T13:44:05.899550",
"participants": [
{
"id": 2,
"group_id": 1,
"user_id": 1,
"last_read_message_id": 39,
"unread_count": 0,
"tagged_message": null,
"user": {
"id": 1,
"username": "Admin",
"email": "admin@fleetglide.com",
"phone": null,
"profile_pic": null,
"role_id": 1,
"is_active": true,
"role": {
"id": 1,
"name": "admin",
"description": "Full system access with all permissions",
"created_at": "2026-08-31T10:16:43.789356",
"updated_at": "2026-08-31T10:16:43.789375"
}
}
},
{
"id": 1,
"group_id": 1,
"user_id": 8,
"last_read_message_id": 39,
"unread_count": 0,
"tagged_message": null,
"user": {
"id": 8,
"username": "Abdifath faysal Ahmednoor",
"email": "urban.abdifatahahmed@gmail.com",
"phone": "6129977143",
"profile_pic": null,
"role_id": 3,
"is_active": true,
"role": {
"id": 3,
"name": "driver",
"description": "Access to view assignments and update trip details",
"created_at": "2026-08-31T10:16:43.804281",
"updated_at": "2026-08-31T10:16:43.804312"
}
}
}
],
"driver_user": {
"id": 8,
"username": "Abdifath faysal Ahmednoor",
"email": "urban.abdifatahahmed@gmail.com",
"phone": "6129977143",
"profile_pic": null,
"role_id": 3,
"is_active": true,
"role": {
"id": 3,
"name": "driver",
"description": "Access to view assignments and update trip details",
"created_at": "2026-08-31T10:16:43.804281",
"updated_at": "2026-08-31T10:16:43.804312"
}
},
"creator": {
"id": 8,
"username": "Abdifath faysal Ahmednoor",
"email": "urban.abdifatahahmed@gmail.com",
"phone": "6129977143",
"profile_pic": null,
"role_id": 3,
"is_active": true,
"role": {
"id": 3,
"name": "driver",
"description": "Access to view assignments and update trip details",
"created_at": "2026-08-31T10:16:43.804281",
"updated_at": "2026-08-31T10:16:43.804312"
}
},
"last_message": {
"id": 39,
"message_content": "green",
"created_at": "2026-08-31T13:44:05.888700",
"sender": {
"id": 8,
"username": "Abdifath faysal Ahmednoor"
},
"attachments": []
},
"unread_count": 5
}),
CommsGroup.fromJson(const {
"id": 4,
"group_type": "topic",
"name": "General Support",
"driver_user_id": 11,
"allow_replies": true,
"status": "open",
"created_at": "2026-08-31T13:21:37.068921",
"updated_at": "2026-08-31T13:21:37.069328",
"participants": [
{
"id": 5,
"group_id": 4,
"user_id": 11,
"last_read_message_id": null,
"unread_count": 0,
"tagged_message": null,
"user": {
"id": 11,
"username": "Abdirahman Awad",
"email": "urban.awad@gmail.com",
"phone": "6129977160",
"profile_pic": null,
"role_id": 3,
"is_active": true,
"role": {
"id": 3,
"name": "driver",
"description": "Access to view assignments and update trip details",
"created_at": "2026-08-31T10:16:43.804281",
"updated_at": "2026-08-31T10:16:43.804312"
}
}
}
],
"driver_user": {
"id": 11,
"username": "Abdirahman Awad",
"email": "urban.awad@gmail.com",
"phone": "6129977160",
"profile_pic": null,
"role_id": 3,
"is_active": true,
"role": {
"id": 3,
"name": "driver",
"description": "Access to view assignments and update trip details",
"created_at": "2026-08-31T10:16:43.804281",
"updated_at": "2026-08-31T10:16:43.804312"
}
},
"creator": {
"id": 11,
"username": "Abdirahman Awad",
"email": "urban.awad@gmail.com",
"phone": "6129977160",
"profile_pic": null,
"role_id": 3,
"is_active": true,
"role": {
"id": 3,
"name": "driver",
"description": "Access to view assignments and update trip details",
"created_at": "2026-08-31T10:16:43.804281",
"updated_at": "2026-08-31T10:16:43.804312"
}
},
"last_message": null,
"unread_count": 0
}),
CommsGroup.fromJson(const {
"id": 3,
"group_type": "topic",
"name": "General Support",
"driver_user_id": 10,
"allow_replies": true,
"status": "open",
"created_at": "2026-08-31T13:10:48.789794",
"updated_at": "2026-08-31T13:10:48.790035",
"participants": [
{
"id": 4,
"group_id": 3,
"user_id": 10,
"last_read_message_id": null,
"unread_count": 0,
"tagged_message": null,
"user": {
"id": 10,
"username": "Abdirahman Abdikarin Nur",
"email": "urban.anurr@gmail.com",
"phone": "3139803948",
"profile_pic": null,
"role_id": 3,
"is_active": true,
"role": {
"id": 3,
"name": "driver",
"description": "Access to view assignments and update trip details",
"created_at": "2026-08-31T10:16:43.804281",
"updated_at": "2026-08-31T10:16:43.804312"
}
}
}
],
"driver_user": {
"id": 10,
"username": "Abdirahman Abdikarin Nur",
"email": "urban.anurr@gmail.com",
"phone": "3139803948",
"profile_pic": null,
"role_id": 3,
"is_active": true,
"role": {
"id": 3,
"name": "driver",
"description": "Access to view assignments and update trip details",
"created_at": "2026-08-31T10:16:43.804281",
"updated_at": "2026-08-31T10:16:43.804312"
}
},
"creator": {
"id": 10,
"username": "Abdirahman Abdikarin Nur",
"email": "urban.anurr@gmail.com",
"phone": "3139803948",
"profile_pic": null,
"role_id": 3,
"is_active": true,
"role": {
"id": 3,
"name": "driver",
"description": "Access to view assignments and update trip details",
"created_at": "2026-08-31T10:16:43.804281",
"updated_at": "2026-08-31T10:16:43.804312"
}
},
"last_message": null,
"unread_count": 0
}),
CommsGroup.fromJson(const {
"id": 2,
"group_type": "topic",
"name": "General Support",
"driver_user_id": 4,
"allow_replies": true,
"status": "open",
"created_at": "2026-08-31T12:11:13.049524",
"updated_at": "2026-08-31T12:33:35.660044",
"participants": [
{
"id": 3,
"group_id": 2,
"user_id": 4,
"last_read_message_id": 31,
"unread_count": 0,
"tagged_message": null,
"user": {
"id": 4,
"username": "Aaron Donald Pouncy",
"email": "adpouncy@gmail.com",
"phone": "6125924918",
"profile_pic": null,
"role_id": 3,
"is_active": true,
"role": {
"id": 3,
"name": "driver",
"description": "Access to view assignments and update trip details",
"created_at": "2026-08-31T10:16:43.804281",
"updated_at": "2026-08-31T10:16:43.804312"
}
}
}
],
"driver_user": {
"id": 4,
"username": "Aaron Donald Pouncy",
"email": "adpouncy@gmail.com",
"phone": "6125924918",
"profile_pic": null,
"role_id": 3,
"is_active": true,
"role": {
"id": 3,
"name": "driver",
"description": "Access to view assignments and update trip details",
"created_at": "2026-08-31T10:16:43.804281",
"updated_at": "2026-08-31T10:16:43.804312"
}
},
"creator": {
"id": 4,
"username": "Aaron Donald Pouncy",
"email": "adpouncy@gmail.com",
"phone": "6125924918",
"profile_pic": null,
"role_id": 3,
"is_active": true,
"role": {
"id": 3,
"name": "driver",
"description": "Access to view assignments and update trip details",
"created_at": "2026-08-31T10:16:43.804281",
"updated_at": "2026-08-31T10:16:43.804312"
}
},
"last_message": {
"id": 31,
"message_content": "✅ RTS Approved\nAdmin Notes: test",
"created_at": "2026-08-31T12:33:35.638074",
"sender": {
"id": 1,
"username": "Admin"
},
"attachments": []
},
"unread_count": 0
}),
],
),
),
GoRoute(
path: '/chat/:title',
builder: (context, state) {
final title = state.pathParameters['title'] ?? 'Chat';
return ConversationDetailPage(
title: title,
addDemoData: true,
userId: 2,
showBackButton: true,
onReactionSelected: (message, reaction) {
final scaffoldMessenger = ScaffoldMessenger.of(context);
scaffoldMessenger.clearSnackBars();
scaffoldMessenger.showSnackBar(
SnackBar(
content: Text(
'Reaction "$reaction" added to message: "${message['text']}"',
),
duration: const Duration(seconds: 2),
),
);
},
);
},
),
],
);
@override
Widget build(BuildContext context) {
return MaterialApp.router(
title: 'Comms Package Example',
themeMode: ThemeMode.system,
debugShowCheckedModeBanner: false,
// Premium Light Theme
theme: ThemeData(
useMaterial3: true,
brightness: Brightness.light,
colorScheme: ColorScheme.fromSeed(
seedColor: const Color(0xFF653DAA), // Modern purple seed color
primary: const Color(0xFF653DAA),
secondary: const Color(0xFFF97316), // Vibrant orange
surface: Colors.white,
onSurface: const Color(0xFF1E293B),
),
scaffoldBackgroundColor: const Color(0xFFF8FAFC),
appBarTheme: const AppBarTheme(
backgroundColor: Colors.transparent,
elevation: 0,
centerTitle: false,
),
),
// Premium Dark Theme
darkTheme: ThemeData(
useMaterial3: true,
brightness: Brightness.dark,
colorScheme: ColorScheme.fromSeed(
seedColor: const Color(0xFF8B5CF6),
brightness: Brightness.dark,
primary: const Color(0xFFA78BFA),
secondary: const Color(0xFFFB923C),
surface: const Color(0xFF0F172A),
onSurface: const Color(0xFFF1F5F9),
),
scaffoldBackgroundColor: const Color(0xFF020617),
appBarTheme: const AppBarTheme(
backgroundColor: Colors.transparent,
elevation: 0,
centerTitle: false,
),
),
routerConfig: _router,
);
}
}