2024-07-05 09:24:40 +02:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:go_router/go_router.dart';
|
2024-07-17 13:28:02 +02:00
|
|
|
import 'package:oc_front/core/models/workspace_local.dart';
|
2024-11-08 13:59:22 +01:00
|
|
|
import 'package:oc_front/main.dart';
|
2024-07-05 09:24:40 +02:00
|
|
|
import 'package:oc_front/models/search.dart';
|
|
|
|
import 'package:oc_front/pages/abstract_page.dart';
|
|
|
|
import 'package:oc_front/pages/catalog.dart';
|
|
|
|
import 'package:oc_front/widgets/items/item.dart';
|
|
|
|
import 'package:oc_front/widgets/items/item_row.dart';
|
|
|
|
|
|
|
|
class CatalogItemFactory implements AbstractFactory {
|
|
|
|
static GlobalKey<CatalogItemPageWidgetState> key = GlobalKey<CatalogItemPageWidgetState>();
|
2024-11-08 13:59:22 +01:00
|
|
|
@override GlobalKey getKey() { return key; }
|
2024-07-05 09:24:40 +02:00
|
|
|
@override bool searchFill() { return false; }
|
|
|
|
@override Widget factory(GoRouterState state, List<String> args) {
|
|
|
|
var id = state.pathParameters[args.first];
|
|
|
|
try {
|
2024-11-08 13:59:22 +01:00
|
|
|
var item = CatalogFactory.key.currentState?.widget.items.firstWhere( (element) => element.id == id );
|
|
|
|
return CatalogItemPageWidget(item : item!);
|
2024-07-05 09:24:40 +02:00
|
|
|
} catch (e) {
|
2024-08-08 08:42:32 +02:00
|
|
|
var item = WorkspaceLocal.getItem(id ?? "", false);
|
|
|
|
if (item != null) { return CatalogItemPageWidget(item : item as AbstractItem); }
|
2024-07-05 09:24:40 +02:00
|
|
|
return Container();
|
|
|
|
}
|
|
|
|
}
|
2024-11-08 13:59:22 +01:00
|
|
|
@override void search(BuildContext context, bool special) { }
|
2024-07-05 09:24:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
class CatalogItemPageWidget extends StatefulWidget {
|
|
|
|
AbstractItem item;
|
|
|
|
CatalogItemPageWidget ({ required this.item }) : super(key: CatalogItemFactory.key);
|
|
|
|
@override CatalogItemPageWidgetState createState() => CatalogItemPageWidgetState();
|
|
|
|
}
|
|
|
|
class CatalogItemPageWidgetState extends State<CatalogItemPageWidget> {
|
|
|
|
@override Widget build(BuildContext context) {
|
|
|
|
return Column( children: [
|
2024-11-08 13:59:22 +01:00
|
|
|
ItemRowWidget(contextWidth: getMainWidth(context), item: widget.item, readOnly: true,),
|
2024-07-05 09:24:40 +02:00
|
|
|
ItemWidget(item: widget.item,),
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
}
|