import 'package:flutter/material.dart'; import 'package:go_router/go_router.dart'; import 'package:oc_front/core/models/workspace_local.dart'; 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 key = GlobalKey(); @override bool searchFill() { return false; } @override Widget factory(GoRouterState state, List args) { var id = state.pathParameters[args.first]; try { var item = CatalogFactory.items.firstWhere( (element) => element.id == id ); return CatalogItemPageWidget(item : item); } catch (e) { var item = WorkspaceLocal.getItem(id ?? ""); if (item != null) { return CatalogItemPageWidget(item : item); } return Container(); } } @override void search(BuildContext context) { } } class CatalogItemPageWidget extends StatefulWidget { AbstractItem item; CatalogItemPageWidget ({ required this.item }) : super(key: CatalogItemFactory.key); @override CatalogItemPageWidgetState createState() => CatalogItemPageWidgetState(); } class CatalogItemPageWidgetState extends State { @override Widget build(BuildContext context) { return Column( children: [ ItemRowWidget(contextWidth: MediaQuery.of(context).size.width, item: widget.item, readOnly: true,), ItemWidget(item: widget.item,), ]); } }