oc-front/lib/widgets/items/shallow_item_row.dart

151 lines
7.4 KiB
Dart
Raw Normal View History

2024-08-30 12:52:32 +02:00
import 'dart:math';
import 'package:flutter/material.dart';
2024-11-19 15:06:22 +01:00
import 'package:flutter_flow_chart/flutter_flow_chart.dart';
2024-11-08 13:59:22 +01:00
import 'package:oc_front/main.dart';
2024-08-30 12:52:32 +02:00
import 'package:oc_front/models/response.dart';
const List<GlobalKey<State>> _empty = [];
// ignore: must_be_immutable
class ShallowItemRowWidget extends StatefulWidget {
bool readOnly = false;
double contextWidth = 0;
2024-11-19 15:06:22 +01:00
Color? color;
2024-08-30 12:52:32 +02:00
ShallowData item;
IconData? icon;
bool low = false;
bool show = false;
2024-11-19 15:06:22 +01:00
List<Widget> badges = [];
2024-08-30 12:52:32 +02:00
void Function(String?)? delete;
void Function(String?)? edit;
List<GlobalKey<State>> keys = [];
2024-11-19 15:06:22 +01:00
ShallowItemRowWidget ({ super.key, this.low = false, this.icon, this.delete, this.edit, this.color, this.badges = const [],
2024-08-30 12:52:32 +02:00
required this.contextWidth, this.readOnly = false, required this.item, this.keys = _empty });
@override ShallowItemRowWidgetState createState() => ShallowItemRowWidgetState();
}
class ShallowItemRowWidgetState extends State<ShallowItemRowWidget> {
@override Widget build(BuildContext context) {
Widget w = Tooltip( message: widget.item.getName(), child: MouseRegion(
onHover: (e) => setState(() {
widget.show = true;
}),
onExit: (e) => setState(() {
widget.show = false;
}),
child: Container(
height: widget.contextWidth, width: widget.contextWidth,
2024-11-19 15:06:22 +01:00
padding: const EdgeInsets.all(10),
margin: const EdgeInsets.all(10),
decoration: BoxDecoration( borderRadius: BorderRadius.circular(4), color: widget.color ?? Colors.white,
boxShadow: const [BoxShadow(color: Colors.grey, spreadRadius: 1, blurRadius: 1, offset: Offset(0, 1))]),
child: Stack( children: [
widget.show ? Positioned( left: 0, top: 0,
child: Row( children: [
Padding( padding: const EdgeInsets.only(right: 5),
child: widget.edit == null ? Container() : InkWell( mouseCursor: SystemMouseCursors.click,
onTap: () => widget.edit!(widget.item.getID() + "~" + widget.item.getName()), child: const Icon(Icons.edit, color: Colors.grey,))),
Padding( padding: const EdgeInsets.only(right: 5),
child: widget.delete == null ? Container() : InkWell( mouseCursor: SystemMouseCursors.click,
onTap: () => widget.delete!(widget.item.getID()), child: const Icon(Icons.delete, color: Colors.grey,))),
] )) : Container(),
Positioned( right: 0, top: 0, child: Row( children: widget.badges )),
Column( children: [
widget.low || widget.icon == null ? Container( padding: const EdgeInsets.only(left: 10),) : Container( padding: const EdgeInsets.all(10),
constraints: BoxConstraints(maxWidth: widget.contextWidth, minWidth: widget.contextWidth),
child: Icon( widget.icon!, size: widget.contextWidth / 1.9, color: const Color(0xFFF67C0B9),)),
Container(
child: Padding(padding: widget.contextWidth != getMainWidth(context) ?
const EdgeInsets.symmetric(horizontal: 10) : const EdgeInsets.symmetric(horizontal: 20),
child: Column(crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.center, children: [
Row( children: [
Expanded( child: Center( child: Text(widget.item.getName().toUpperCase(),
style: const TextStyle(fontSize: 15,
overflow: TextOverflow.ellipsis,
fontWeight: FontWeight.w600, color: Colors.grey)),
))
]),
],)
)
),
])
]))));
return widget.readOnly || widget.low ? w : InkWell( mouseCursor: SystemMouseCursors.click,
onTap: () { },
child: w );
}
}
class ShallowItemFlowDataRowWidget extends StatefulWidget {
bool readOnly = false;
double contextWidth = 0;
Color? color;
FlowData item;
IconData? icon;
bool low = false;
bool show = false;
List<Widget> badges = [];
List<Widget> bottomBadges = [];
void Function(String?)? delete;
void Function(String?)? edit;
List<GlobalKey<State>> keys = [];
ShallowItemFlowDataRowWidget ({ super.key, this.low = false, this.icon, this.delete, this.bottomBadges = const [],
this.edit, this.color, this.badges = const [],
required this.contextWidth, this.readOnly = false, required this.item, this.keys = _empty });
@override ShallowItemFlowDataRowWidgetState createState() => ShallowItemFlowDataRowWidgetState();
}
class ShallowItemFlowDataRowWidgetState extends State<ShallowItemFlowDataRowWidget> {
@override Widget build(BuildContext context) {
Widget w = Tooltip( message: widget.item.getName(), child: MouseRegion(
onHover: (e) => setState(() {
widget.show = true;
}),
onExit: (e) => setState(() {
widget.show = false;
}),
child: Container(
height: widget.contextWidth, width: widget.contextWidth,
padding: const EdgeInsets.all(10),
margin: const EdgeInsets.all(10),
decoration: BoxDecoration( borderRadius: BorderRadius.circular(4), color: widget.color ?? Colors.white,
2024-08-30 12:52:32 +02:00
boxShadow: const [BoxShadow(color: Colors.grey, spreadRadius: 1, blurRadius: 1, offset: Offset(0, 1))]),
child: Stack( children: [
widget.show ? Positioned( left: 0, top: 0,
child: Row( children: [
Padding( padding: const EdgeInsets.only(right: 5),
child: widget.edit == null ? Container() : InkWell( mouseCursor: SystemMouseCursors.click,
onTap: () => widget.edit!(widget.item.getID() + "~" + widget.item.getName()), child: const Icon(Icons.edit, color: Colors.grey,))),
Padding( padding: const EdgeInsets.only(right: 5),
child: widget.delete == null ? Container() : InkWell( mouseCursor: SystemMouseCursors.click,
onTap: () => widget.delete!(widget.item.getID()), child: const Icon(Icons.delete, color: Colors.grey,))),
] )) : Container(),
Positioned( right: 0, top: 0,
2024-11-19 15:06:22 +01:00
child: Row( children: widget.badges )),
Positioned( left: 0, bottom: 0,
child: Row( children: widget.bottomBadges )),
2024-08-30 12:52:32 +02:00
Column( children: [
widget.low || widget.icon == null ? Container( padding: const EdgeInsets.only(left: 10),) : Container( padding: const EdgeInsets.all(10),
constraints: BoxConstraints(maxWidth: widget.contextWidth, minWidth: widget.contextWidth),
child: Icon( widget.icon!, size: widget.contextWidth / 1.9, color: const Color(0xFFF67C0B9),)),
Container(
2024-11-08 13:59:22 +01:00
child: Padding(padding: widget.contextWidth != getMainWidth(context) ?
2024-08-30 12:52:32 +02:00
const EdgeInsets.symmetric(horizontal: 10) : const EdgeInsets.symmetric(horizontal: 20),
child: Column(crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.center, children: [
Row( children: [
Expanded( child: Center( child: Text(widget.item.getName().toUpperCase(),
style: const TextStyle(fontSize: 15,
overflow: TextOverflow.ellipsis,
fontWeight: FontWeight.w600, color: Colors.grey)),
))
]),
],)
)
),
])
]))));
return widget.readOnly || widget.low ? w : InkWell( mouseCursor: SystemMouseCursors.click,
onTap: () { },
child: w );
}
}