42 lines
1.8 KiB
Dart
42 lines
1.8 KiB
Dart
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/main.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<CatalogItemPageWidgetState> key = GlobalKey<CatalogItemPageWidgetState>();
|
|
@override void clear() { }
|
|
@override GlobalKey getKey() { return key; }
|
|
@override bool searchFill() { return false; }
|
|
@override Widget factory(GoRouterState state, List<String> args) {
|
|
var id = state.pathParameters[args.first];
|
|
try {
|
|
var item = CatalogFactory.key.currentState?.widget.items.firstWhere( (element) => element.id == id );
|
|
return CatalogItemPageWidget(item : item!);
|
|
} catch (e) {
|
|
var item = WorkspaceLocal.getItem(id ?? "", false);
|
|
if (item != null) { return CatalogItemPageWidget(item : item as AbstractItem); }
|
|
return Container();
|
|
}
|
|
}
|
|
@override void search(BuildContext context, bool special) { }
|
|
}
|
|
|
|
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: [
|
|
ItemRowWidget(contextWidth: getMainWidth(context), item: widget.item, readOnly: true,),
|
|
ItemWidget(item: widget.item,),
|
|
]);
|
|
}
|
|
} |