import 'package:alert_banner/exports.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:oc_front/models/logs.dart'; import 'package:oc_front/widgets/dialog/alert.dart'; class LogsWidget extends StatefulWidget { final List items; LogsWidget ({ Key? key, required this.items }): super(key: key); @override LogsWidgetState createState() => LogsWidgetState(); } class LogsWidgetState extends State { @override Widget build(BuildContext context) { List itemRows = widget.items.map((e) => LogWidget(item: e)).toList(); return SingleChildScrollView( child: Column( children: itemRows ) ); } } class LogWidget extends StatefulWidget { final Log item; bool expanded = false; LogWidget ({ Key? key, required this.item }): super(key: key); @override LogWidgetState createState() => LogWidgetState(); } class LogWidgetState extends State { @override Widget build(BuildContext context) { return Padding( padding: const EdgeInsets.only(top: 10, left: 30, right: 30), child: Wrap( children: [ Row( mainAxisAlignment: MainAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.center, children: [ Container( width: 10, height: 15, color: widget.item.level?.toLowerCase() == "info" ? Colors.green : ( widget.item.level?.toLowerCase() == "error" ? Colors.red : ( widget.item.level?.toLowerCase() == "warning" ? Colors.orange : Colors.blue))), InkWell( mouseCursor: widget.item.map.isEmpty ? MouseCursor.defer : SystemMouseCursors.click, onTap: () { if (widget.item.map.isNotEmpty ) { setState(() { widget.expanded = !widget.expanded; }); } }, child: Container( height: 20, child: Padding( padding: EdgeInsets.symmetric(horizontal: widget.expanded ? 0 : 5), child: Icon( widget.expanded ? Icons.keyboard_arrow_down_outlined : Icons.arrow_forward_ios, size: widget.expanded ? 25 : 15, color: widget.item.map.isEmpty ? Colors.grey : Colors.black, weight: widget.expanded ? 100 : 1000,)))), Padding( padding: const EdgeInsets.only(right: 10), child: Text("${widget.item.timestamp?.toString()}", style: const TextStyle(fontSize: 13, color: Colors.black, fontWeight: FontWeight.w500))), Tooltip( message : "copy to clipboard", child: InkWell( child: const Icon(Icons.copy, size: 15, color: Colors.grey), onTap: () { if (widget.item.message != null) { Clipboard.setData(ClipboardData(text: widget.item.message!)); showAlertBanner(context, () {}, const InfoAlertBannerChild(text: "Copy to clipboard"), // <-- Put any widget here you want! alertBannerLocation: AlertBannerLocation.bottom,); } })), ]), widget.expanded ? Container( margin: const EdgeInsets.symmetric(vertical: 10), decoration: BoxDecoration( color: Colors.grey, borderRadius: BorderRadius.circular(4)), padding: const EdgeInsets.all(10), child: Column( children: widget.item.map.keys.map((e) => Padding( padding: const EdgeInsets.all(2), child: Row( mainAxisAlignment: MainAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start, children: [Flexible( child:Text("$e: \"${widget.item.map[e]}\"", style: const TextStyle(fontSize: 11, color: Colors.white))), ]) )).toList() )) : Container(), Row( mainAxisAlignment: MainAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start, children: [Flexible( child:Text(widget.item.message ?? "unknown message", style: const TextStyle(fontSize: 14, color: Colors.black))), ]) ])); } }