0% found this document useful (0 votes)
6 views

working_2_21_10_sidenavbar

The document is a Flutter widget implementation for an Alarms and Alerts sidebar, featuring collapsible panels for different alert types and priorities. It includes functionality to filter and display alerts based on their type and priority, and allows users to view detailed information about each alert. The widget utilizes a custom scroll view and draggable alert cards for enhanced user interaction.

Uploaded by

Dastagiri Saheb
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

working_2_21_10_sidenavbar

The document is a Flutter widget implementation for an Alarms and Alerts sidebar, featuring collapsible panels for different alert types and priorities. It includes functionality to filter and display alerts based on their type and priority, and allows users to view detailed information about each alert. The widget utilizes a custom scroll view and draggable alert cards for enhanced user interaction.

Uploaded by

Dastagiri Saheb
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 8

// Automatic FlutterFlow imports

import '/backend/backend.dart';
import '/backend/schema/structs/index.dart';
import '/flutter_flow/flutter_flow_theme.dart';
import '/flutter_flow/flutter_flow_util.dart';
import '/custom_code/widgets/index.dart'; // Imports other custom widgets
import '/flutter_flow/custom_functions.dart'; // Imports custom functions
import 'package:flutter/material.dart';
// Begin custom widget code
// DO NOT REMOVE OR MODIFY THE CODE ABOVE!

import
'package:sliver_sticky_collapsable_panel/sliver_sticky_collapsable_panel.dart';
import 'package:intl/intl.dart';

class AlarmsEventssideBar extends StatefulWidget {


const AlarmsEventssideBar({
super.key,
this.width,
this.height,
this.alaramEventsfeed,
// this.minorAlerts,
// this.lowAlerts,
// this.majorAlarms,
// this.minorAlarms,
// this.lowAlarms,
// this.event,
});

final double? width;


final double? height;
final List<AlertEventStruct>? alaramEventsfeed;
// final List<AlertEventStruct>? minorAlerts;
// final List<AlertEventStruct>? lowAlerts;
// final List<AlertEventStruct>? majorAlarms;
// final List<AlertEventStruct>? minorAlarms;
// final List<AlertEventStruct>? lowAlarms;
// final List<AlertEventStruct>? event;

@override
State<AlarmsEventssideBar> createState() => _AlarmsEventssideBarState();
}

class _AlarmsEventssideBarState extends State<AlarmsEventssideBar> {


final ScrollController _scrollController = ScrollController();

// Controllers for Alerts segment


final alertsController =
StickyCollapsablePanelController(key: 'alerts_segment');
final alertsMajorController =
StickyCollapsablePanelController(key: 'alerts_major');
final alertsMinorController =
StickyCollapsablePanelController(key: 'alerts_minor');
final alertsLowController =
StickyCollapsablePanelController(key: 'alerts_low');

// Controllers for Alarms segment


final alarmsController =
StickyCollapsablePanelController(key: 'alarms_segment');
final alarmsMajorController =
StickyCollapsablePanelController(key: 'alarms_major');
final alarmsMinorController =
StickyCollapsablePanelController(key: 'alarms_minor');
final alarmsLowController =
StickyCollapsablePanelController(key: 'alarms_low');

// Helper function to filter and map feed data


List<AlertItem> _filterAndMapFeed(String type, String priority) {
return widget.alaramEventsfeed
?.where((event) =>
event.alert_type == type && event.priority == priority)
.map((event) => AlertItem(
id: event.alertID,
title: event.cause_description ?? "Unknown Title",
description: event.situation_details ?? "No details provided",
timestamp: event.originDate ?? DateTime.now(),
status: event.alarm_status ?? "unknown",
priority: event.priority,
))
.toList() ??
[];
}

// Sample Data for Alerts


final List<AlertItem> majorAlerts = [
AlertItem(
id: '1',
title: 'Critical System Failure',
description: 'Main server down',
timestamp: DateTime.now(),
status: 'active',
priority: 'major',
),
AlertItem(
id: '2',
title: 'Security Breach',
description: 'Unauthorized access detected',
timestamp: DateTime.now(),
status: 'active',
priority: 'major',
),
];

final List<AlertItem> minorAlerts = [


AlertItem(
id: '3',
title: 'Performance Warning',
description: 'High CPU usage detected',
timestamp: DateTime.now(),
status: 'active',
priority: 'minor',
),
];

final List<AlertItem> lowAlerts = [


AlertItem(
id: '4',
title: 'Update Available',
description: 'New system update ready',
timestamp: DateTime.now(),
status: 'active',
priority: 'low',
),
];

// Sample Data for Alarms


final List<AlertItem> majorAlarms = [
AlertItem(
id: '5',
title: 'Fire Alarm',
description: 'Fire detected in Server Room',
timestamp: DateTime.now(),
status: 'active',
priority: 'major',
),
];

final List<AlertItem> minorAlarms = [


AlertItem(
id: '6',
title: 'Temperature Warning',
description: 'Temperature above threshold',
timestamp: DateTime.now(),
status: 'active',
priority: 'minor',
),
];

final List<AlertItem> lowAlarms = [


AlertItem(
id: '7',
title: 'Maintenance Due',
description: 'Regular maintenance check required',
timestamp: DateTime.now(),
status: 'active',
priority: 'low',
),
];

/*
Widget _buildAlertCard(AlertItem alert, Color color) {
return Card(
margin: EdgeInsets.symmetric(horizontal: 8, vertical: 4),
child: ListTile(
leading: Icon(Icons.notification_important, color: color),
title: Text(alert.title),
subtitle: Text(alert.description),
trailing: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
DateFormat('HH:mm').format(alert.timestamp),
style: TextStyle(fontSize: 12),
),
Text(
alert.status,
style: TextStyle(
color: color,
fontSize: 12,
fontWeight: FontWeight.bold,
),
),
],
),
onTap: () => _showAlertDetails(alert),
),
);
}
*/

Widget _buildAlertCard(AlertItem alert, Color color) {


return Draggable<AlertItem>(
data: alert, // Pass the alert data as the draggable payload
feedback: Material(
elevation: 4,
child: Card(
margin: EdgeInsets.symmetric(horizontal: 8, vertical: 4),
child: ListTile(
leading: Icon(Icons.notification_important, color: color),
title: Text(alert.title),
subtitle: Text(alert.description),
),
),
),
childWhenDragging: Opacity(
opacity: 0.5,
child: Card(
margin: EdgeInsets.symmetric(horizontal: 8, vertical: 4),
child: ListTile(
leading: Icon(Icons.notification_important, color: color),
title: Text(alert.title),
subtitle: Text(alert.description),
),
),
),
child: Card(
margin: EdgeInsets.symmetric(horizontal: 8, vertical: 4),
child: ListTile(
leading: Icon(Icons.notification_important, color: color),
title: Text(alert.title),
subtitle: Text(alert.description),
trailing: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
DateFormat('HH:mm').format(alert.timestamp),
style: TextStyle(fontSize: 12),
),
Text(
alert.status,
style: TextStyle(
color: color,
fontSize: 12,
fontWeight: FontWeight.bold,
),
),
],
),
onTap: () => _showAlertDetails(alert),
),
),
);
}

@override
Widget build(BuildContext context) {
return Scaffold(
body: CustomScrollView(
controller: _scrollController,
slivers: [
// Alerts Segment
_buildMainSegment(
controller: alertsController,
title: 'Alerts',
color: Colors.purple,
majorItems: majorAlerts,
minorItems: minorAlerts,
lowItems: lowAlerts,
majorController: alertsMajorController,
minorController: alertsMinorController,
lowController: alertsLowController,
),

// Alarms Segment
_buildMainSegment(
controller: alarmsController,
title: 'Alarms',
color: Colors.teal,
majorItems: majorAlarms,
minorItems: minorAlarms,
lowItems: lowAlarms,
majorController: alarmsMajorController,
minorController: alarmsMinorController,
lowController: alarmsLowController,
),
],
),
);
}

Widget _buildMainSegment({
required StickyCollapsablePanelController controller,
required String title,
required Color color,
required List<AlertItem> majorItems,
required List<AlertItem> minorItems,
required List<AlertItem> lowItems,
required StickyCollapsablePanelController majorController,
required StickyCollapsablePanelController minorController,
required StickyCollapsablePanelController lowController,
}) {
return SliverStickyCollapsablePanel(
scrollController: _scrollController,
controller: controller,
iOSStyleSticky: true,
headerBuilder: (context, status) =>
_buildSegmentHeader(title, color, status.isExpanded),
sliverPanel: SliverList(
delegate: SliverChildListDelegate([
Container(
padding: EdgeInsets.all(0),
child: Column(
spacing: 0,
children: [
// Major Items Section
_buildSubSection(
title: 'Major $title',
color: Colors.red,
items: majorItems,
controller: majorController,
),
// Minor Items Section
_buildSubSection(
title: 'Minor $title',
color: Colors.orange,
items: minorItems,
controller: minorController,
),
// Low Priority Items Section
_buildSubSection(
title: 'Low Priority $title',
color: Colors.blue,
items: lowItems,
controller: lowController,
),
],
),
),
]),
),
);
}

Widget _buildSubSection({
required String title,
required Color color,
required List<AlertItem> items,
required StickyCollapsablePanelController controller,
}) {
return ExpansionTile(
title: _buildSubHeader(title, color, true),
backgroundColor: Colors.transparent,
collapsedBackgroundColor: Colors.transparent,
tilePadding: EdgeInsets.zero, // Set background color when collapsed
childrenPadding: const EdgeInsets.all(0), // Padding for children
children: items.map((item) => _buildAlertCard(item, color)).toList(),
);
}

Widget _buildSegmentHeader(String title, Color color, bool isExpanded) {


return Container(
width: double.infinity,
height: 30,
color: color,
child: Stack(
children: [
Center(
child: Text(
title,
style: const TextStyle(
color: Colors.white,
fontSize: 16,
fontWeight: FontWeight.bold,
),
),
),
Align(
alignment: Alignment.centerRight,
child: Padding(
padding: EdgeInsets.only(right: 16),
child: AnimatedRotation(
duration: Duration(milliseconds: 200),
turns: isExpanded ? 0 : 0.5,
child: Icon(Icons.expand_more, color: Colors.white),
),
),
),
],
),
);
}

Widget _buildSubHeader(String title, Color color, bool isExpanded) {


return Container(
width: double.infinity,
height: 30,
decoration: BoxDecoration(
// Set the background color
color: Colors.lightGreen,
// Add a border with a custom color and thickness
border: Border.all(
width: 1.0,
color: const Color.fromRGBO(33, 150, 243, 1),
),
// Optional: add rounded corners using borderRadius
borderRadius: BorderRadius.circular(20.0),
),
child: Stack(
children: [
Padding(
padding: EdgeInsets.only(left: 16),
child: Row(
children: [
Icon(Icons.warning, color: Colors.white),
SizedBox(width: 8),
Text(
title,
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
),
),
],
),
),
],
),
);
}

void _showAlertDetails(AlertItem alert) {


showDialog(
context: context,
builder: (context) => AlertDialog(
title: Text(alert.title),
content: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text('Description: ${alert.description}'),
Text('Priority: ${alert.priority}'),
Text('Status: ${alert.status}'),
Text(
'Time: ${DateFormat('yyyy-MM-dd HH:mm').format(alert.timestamp)}'),
],
),
actions: [
TextButton(
onPressed: () => Navigator.pop(context),
child: Text('Close'),
),
],
),
);
}
}

class AlertItem {
final String id;
final String title;
final String description;
final DateTime timestamp;
final String status;
final String priority;

AlertItem({
required this.id,
required this.title,
required this.description,
required this.timestamp,
required this.status,
required this.priority,
});
}

You might also like