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

119 lines
6.1 KiB
Dart
Raw Normal View History

import 'dart:convert';
import 'package:flutter/material.dart';
2024-11-08 13:59:22 +01:00
import 'package:oc_front/main.dart';
import 'package:oc_front/models/search.dart';
2024-07-17 13:28:02 +02:00
import 'package:oc_front/core/models/workspace_local.dart';
import 'package:oc_front/core/services/router.dart';
const List<GlobalKey<State>> _empty = [];
// ignore: must_be_immutable
class ItemRowWidget extends StatefulWidget {
bool readOnly = false;
double contextWidth = 0;
AbstractItem item;
2024-07-17 13:28:02 +02:00
bool low = false;
List<GlobalKey<State>> keys = [];
2024-07-17 13:28:02 +02:00
ItemRowWidget ({ super.key, this.low = false,
required this.contextWidth, this.readOnly = false, required this.item, this.keys = _empty });
@override ItemRowWidgetState createState() => ItemRowWidgetState();
}
class ItemRowWidgetState extends State<ItemRowWidget> {
@override Widget build(BuildContext context) {
2024-08-30 12:52:32 +02:00
double imageSize = widget.contextWidth <= 400 ? 0 : 80;
2024-11-08 13:59:22 +01:00
var ratio = getMainWidth(context) != widget.contextWidth ? 0.5 : 1; // 2;
var itemWidth = (((widget.contextWidth - imageSize) / 3) - 80) / ratio;
itemWidth = itemWidth > 100 ? 100 : ( itemWidth < 40 ? 40 : itemWidth );
var endWidth = (itemWidth * ratio) + 80;
Image? image;
if (widget.item.logo != null) {
2024-08-08 08:42:32 +02:00
image = Image.network(widget.item.logo ?? "", width: imageSize, height: imageSize);
}
Widget w = Container(
width: widget.contextWidth,
height: 100,
2024-08-30 12:52:32 +02:00
padding: EdgeInsets.only(left: imageSize == 0 ? 20 : 0),
2024-11-08 13:59:22 +01:00
decoration: BoxDecoration( border: Border(bottom: BorderSide(color: midColor)) ),
child: Row( children: [
2024-08-22 15:46:16 +02:00
widget.low ? Container( padding: const EdgeInsets.only(left: 10),) : Container( padding: const EdgeInsets.all(10),
constraints: BoxConstraints(maxWidth: imageSize, minWidth: imageSize),
child: image ?? Image.network('https://get-picto.com/wp-content/uploads/2024/01/logo-instagram-png.webp',
height: imageSize, width: imageSize)),
Container(
2024-07-17 13:28:02 +02:00
width: widget.low ? widget.contextWidth - 20 : widget.contextWidth - (imageSize + 20) - endWidth,
2024-11-08 13:59:22 +01:00
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: [
2024-07-17 13:28:02 +02:00
widget.low ? Container() : Container(padding: const EdgeInsets.symmetric(vertical: 5, horizontal: 10),
margin: const EdgeInsets.only(right: 20),
decoration: BoxDecoration(
color: isData(widget.item.topic) ? Colors.blue :
isComputing(widget.item.topic) ? Colors.green :
2024-11-08 13:59:22 +01:00
isCompute(widget.item.topic) ? Colors.orange :
isStorage(widget.item.topic) ? redColor : Colors.grey,
borderRadius: BorderRadius.circular(4),
),
2024-11-08 13:59:22 +01:00
child: Text( getMainWidth(context) < 600 ? "" : widget.item.topic.toString(),
style: const TextStyle(fontSize: 10, color: Colors.white, fontWeight: FontWeight.w600)),
),
Expanded( child: Text(widget.item.name?.toUpperCase() ?? "",
2024-07-17 13:28:02 +02:00
style: TextStyle(fontSize: widget.low ? 14 : 20, overflow: TextOverflow.ellipsis, fontWeight: FontWeight.w600, color: Color(0xFFF67C0B9))),
)
]),
Text( "From ${widget.item.owner ?? "unknown owner"}",
2024-08-08 08:42:32 +02:00
style: const TextStyle(fontSize: 14, color: Colors.grey, overflow: TextOverflow.ellipsis)),
Text(widget.item.shortDescription ?? "", style: const TextStyle(fontSize: 12, overflow: TextOverflow.ellipsis)),
],)
)
),
2024-07-17 13:28:02 +02:00
widget.low ? Container() : Container(
width: endWidth,
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children : [
InkWell(
mouseCursor: SystemMouseCursors.click,
onTap: () {
setState(() {
if (WorkspaceLocal.hasItem(widget.item)) { WorkspaceLocal.removeItem(widget.item);
} else { WorkspaceLocal.addItem(widget.item); }
});
for (var key in widget.keys) { key.currentState?.setState(() {}); }
},
child: Container(
height: 40,
constraints: const BoxConstraints(maxWidth: 80),
width: itemWidth,
decoration: BoxDecoration(
2024-11-08 13:59:22 +01:00
boxShadow: [BoxShadow(color: midColor, spreadRadius: 1, blurRadius: 1, offset: const Offset(0, 1))],
color: (WorkspaceLocal.hasItem(widget.item) ? redColor : lightColor ),
borderRadius: BorderRadius.circular(4),
),
child: Icon(WorkspaceLocal.hasItem(widget.item) ? Icons.remove_shopping_cart : Icons.add_shopping_cart,
color: Colors.white, size: 20 ))
),
...(ratio > 1 ? [Padding( padding: const EdgeInsets.only(left: 20),
child: InkWell(
mouseCursor: SystemMouseCursors.click,
onTap: () { },
child: Container(
height: 40,
constraints: const BoxConstraints(maxWidth: 80, minWidth: 40),
width: itemWidth,
decoration: BoxDecoration(
2024-11-08 13:59:22 +01:00
boxShadow: [BoxShadow(color: midColor, spreadRadius: 1, blurRadius: 1, offset: const Offset(0, 1))],
color: midColor,
borderRadius: BorderRadius.circular(4),
),
child: const Icon(Icons.favorite_border, color: Colors.white, size: 20 ))
)
)] : [])
])
)]),
);
2024-07-17 13:28:02 +02:00
return widget.readOnly || widget.low ? w : InkWell( mouseCursor: SystemMouseCursors.click,
onTap: () { AppRouter.catalogItem.go(context, { "id" : widget.item.id ?? "" }); },
child: w );
}
}