pilot_ui 0.0.6
pilot_ui: ^0.0.6 copied to clipboard
A dynamic, theme-aware JSON UI rendering engine for Flutter with extensible parsers, action handlers, and ready-to-use smart dispatch & RTS action components.
example/lib/main.dart
import 'package:flutter/material.dart';
import 'package:pilot_ui/pilot.dart';
void main() {
runApp(const PilotExampleApp());
}
class PilotExampleApp extends StatelessWidget {
const PilotExampleApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Pilot Example',
debugShowCheckedModeBanner: false,
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
useMaterial3: true,
textTheme: const TextTheme(
titleMedium: TextStyle(fontWeight: FontWeight.w600, color: Colors.black87),
bodyLarge: TextStyle(fontWeight: FontWeight.w600, color: Colors.black87),
),
elevatedButtonTheme: ElevatedButtonThemeData(
style: ElevatedButton.styleFrom(
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(8)),
elevation: 0,
backgroundColor: const Color(0xFF7C4DFF),
foregroundColor: Colors.white,
),
),
textButtonTheme: TextButtonThemeData(
style: TextButton.styleFrom(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8),
side: const BorderSide(color: Color(0xFFE0E0E0)),
),
foregroundColor: const Color(0xFF5C6BC0),
),
),
),
home: const RtsDashboardScreen(),
);
}
}
class RtsDashboardScreen extends StatefulWidget {
const RtsDashboardScreen({super.key});
@override
State<RtsDashboardScreen> createState() => _RtsDashboardScreenState();
}
class _RtsDashboardScreenState extends State<RtsDashboardScreen> {
// Dummy RTS Events matching the UI mockups
final List<Map<String, dynamic>> _dummyEvents = [
{
"id": 99,
"event_type": "rts",
"title": "Route TX84 Operating Ahead of Pace (+15 stops)",
"description": "⢠**Driver:** Mohamed Salem Mobarak\n⢠**Pace Variance:** +15 stops ahead of schedule",
"severity": "info",
"status": "informational",
"created_at": "2026-09-05T19:59:00.000000Z",
"initially_expanded": true,
"actions": []
},
{
"id": 27,
"event_type": "rts",
"title": "DriverRTSRequest-AbdifathAhmednoor",
"description": "Driver AbdifathAhmednoor (ID: 6) has requested to return to the station due to 7 undeliverable packages.",
"severity": "warning",
"ai_diagnosis": "Driver AbdifathAhmednoor has reported 7 undeliverable packages and is requesting to return to the station. Given the number of packages, approving this RTS request seems appropriate to prevent further delays and ensure proper handling of the undeliverables.",
"is_actionable": true,
"action_type": "APPROVE_RTS",
"action_label": "Approve",
"action_payload": {
"user_id": 8,
"driver_id": 6,
"status": "approved",
"reason": "Given the 7 reported undeliverable packages, it's best to approve Abdifath's request to return to the station. This will allow for efficient processing of the returns and prevent further delays on the route."
},
"actions": [
{
"action_type": "APPROVE_RTS",
"action_label": "Approve",
"action_payload": {
"user_id": 8,
"driver_id": 6,
"status": "approved",
"reason": ""
}
},
{
"action_type": "APPROVE_RTS",
"action_label": "Reject",
"action_payload": {
"user_id": 8,
"driver_id": 6,
"status": "rejected",
"reason": ""
}
}
],
"ui_schema": {
"component_type": "RtsActionCard",
"data": {
"id": 3,
"attendance_id": 2,
"user_id": 8,
"driver_id": 6,
"driver_name": "AbdifathfaysalAhmednoor",
"transporter_id": "AP2PQMWCBVOPV",
"reason": "Undeliverable packages return",
"undeliverables_count": 7,
"status": "rts_pending",
"latitude": null,
"longitude": null,
"location_name": null,
"requested_at": "2026-09-01T10:22:56.249557",
"has_conversation": true,
"unread_message_count": 0,
"last_message": {
"id": 45,
"message": "šØ RTS Requested Undeliverables: 7 Reason: Undeliverable packages return",
"message_content": "šØ RTS Requested Undeliverables: 7 Reason: Undeliverable packages return",
"sender_id": 8,
"sender_name": "AbdifathfaysalAhmednoor",
"sender_role": "driver",
"attachments": [],
"attachment_url": null,
"created_at": "2026-09-01T10:31:17.717009"
}
}
},
"status": "pending",
"created_at": "2026-09-01T10:31:25.604351Z"
},
{
"id": 17,
"event_type": "rts",
"title": "Driver Aaron Pouncy RTS Request - 50 Undeliverables",
"description": "Driver Aaron Donald Pouncy (ID: 2) has requested to return to the station early, stating a need to leave earlier. There are currently 50 packages still pending delivery.",
"severity": "warning",
"ai_diagnosis": "Driver Aaron Donald Pouncy's request to return to station early due to a personal need to leave earlier is not sufficient given the 50 pending undeliverable packages. The primary objective is to complete deliveries. Recommend rejecting this RTS request and instructing the driver to continue their route.",
"action_type": "APPROVE_RTS",
"action_label": "ā Reject Return to Station",
"action_payload": {
"user_id": 3,
"driver_id": 2,
"status": "rejected",
"reason": ""
},
"actions": [
{
"action_type": "APPROVE_RTS",
"action_label": "ā” Approve Return to Station",
"action_payload": {
"user_id": 3,
"driver_id": 2,
"status": "approved",
"reason": ""
}
},
{
"action_type": "APPROVE_RTS",
"action_label": "ā Reject Return to Station",
"action_payload": {
"user_id": 3,
"driver_id": 2,
"status": "rejected",
"reason": ""
}
}
],
"status": "pending",
"created_at": "2026-08-28T06:17:51.860860Z"
},
{
"id": 2,
"event_type": "rts",
"title": "Driver RTS Request - Aaron Donald Pouncy",
"description": "Driver Aaron Donald Pouncy (ID: 2) has requested to return to station with 5000 undeliverable items, citing a highly...",
"severity": "critical",
"ai_diagnosis": "Driver Aaron Donald Pouncy submitted an RTS request with a concerning reason: 'I am going to sell them...'",
"status": "resolved",
"created_at": "2026-08-26T10:33:46.000000Z",
"actions": []
},
{
"id": 3,
"event_type": "rts",
"title": "Critical: Driver RTS Request with Theft Intent",
"description": "Driver Aaron Donald Pouncy (ID: 2) has requested to return to station after reporting missing packages...",
"severity": "critical",
"ai_diagnosis": "High risk flag detected. Intent to sell items declared by driver in reason field.",
"status": "pending",
"created_at": "2026-08-26T10:30:40.000000Z",
"actions": [
{
"action_type": "APPROVE_RTS",
"action_label": "ā” Approve Return to Station",
"action_payload": {"status": "approved"}
},
{
"action_type": "REJECT_RTS",
"action_label": "ā Reject",
"action_payload": {"status": "rejected"}
}
]
},
{
"id": 4,
"event_type": "rts",
"title": "Dismissed: Package Access Warning",
"description": "Driver Aaron Donald Pouncy (ID: 2) flagged access code expired for gate 4B.",
"severity": "warning",
"ai_diagnosis": "Gate access issue manually handled and resolved via dispatch phone call.",
"status": "dismissed",
"created_at": "2026-08-26T10:15:10.000000Z",
"actions": []
},
{
"id": 5,
"event_type": "rts",
"title": "Routine Route Telemetry Update",
"description": "Telemetry feed indicates driver has completed 80% of route on schedule.",
"severity": "info",
"ai_diagnosis": "⢠**Driver:** Mahema Khadro Abdikadir ⢠**Pace Variance:** +1 stops ahead of schedule ⢠**Workload Remaining:** 124 stops remaining ⢠**Early Arrival Estimate:** Early arrival is anticipated, but a precise estimate is not available at this time.",
"status": "informational",
"created_at": "2026-08-26T10:00:00.000000Z",
"actions": []
},
];
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('RTS Driver Requests', style: TextStyle(fontWeight: FontWeight.bold, fontSize: 18)),
backgroundColor: Colors.white,
elevation: 0.5,
surfaceTintColor: Colors.transparent,
),
body: ListView.builder(
padding: const EdgeInsets.all(12),
itemCount: _dummyEvents.length,
itemBuilder: (context, index) {
final event = _dummyEvents[index];
return RtsActionCard(
data: event,
onButtonTap: (action) async {
// Simulate async network request
await Future.delayed(const Duration(milliseconds: 1200));
if (!context.mounted) return;
final isApprove = action?.actionLabel.toLowerCase().contains('approve') ?? false;
setState(() {
event['status'] = isApprove ? 'resolved' : 'dismissed';
});
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text('Triggered Action: ${action?.actionPayload} (${action?.actionType})'),
behavior: SnackBarBehavior.floating,
backgroundColor: isApprove
? const Color(0xFF00B074)
: const Color(0xFFEF4444),
),
);
},
);
},
),
);
}
}