oc-front/lib/pages/catalog.dart
2024-08-08 08:42:32 +02:00

43 lines
2.0 KiB
Dart

import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'package:oc_front/core/sections/header/header.dart';
import 'package:oc_front/core/services/specialized_services/resource_service.dart';
import 'package:oc_front/models/search.dart';
import 'package:oc_front/widgets/catalog.dart';
import 'package:oc_front/pages/abstract_page.dart';
import 'package:oc_front/core/sections/header/search.dart';
import 'package:oc_front/widgets/menu_clipper/workspace_menu.dart';
class CatalogFactory implements AbstractFactory {
static List<AbstractItem> items = [];
static GlobalKey<CatalogPageWidgetState> key = GlobalKey<CatalogPageWidgetState>();
@override bool searchFill() { return CatalogFactory.items.isEmpty; }
@override Widget factory(GoRouterState state, List<String> args) { return CatalogPageWidget(); }
@override void search(BuildContext context) {
CatalogFactory.key.currentState?.widget.search.search(context, [ SearchConstants.get()! ], {}).then((value) {
if (value.data == null) { return; }
CatalogFactory.items = [ ...value.data!.workflows,
...value.data!.processings, ...value.data!.datas, ...value.data!.storages, ...value.data!.datacenters,];
searchWidgetKey.currentState?.setState(() {});
CatalogFactory.key.currentState?.setState(() {});
});
}
}
class CatalogPageWidget extends StatefulWidget {
final ResourceService search = ResourceService();
CatalogPageWidget (): super(key: CatalogFactory.key);
@override CatalogPageWidgetState createState() => CatalogPageWidgetState();
}
class CatalogPageWidgetState extends State<CatalogPageWidget> {
@override Widget build(BuildContext context) {
return Column( children : [
CatalogFactory.items.isEmpty ? Container() : MenuWorkspaceWidget(),
SizedBox(
width: MediaQuery.of(context).size.width,
height: CatalogFactory.items.isEmpty ? 0 : MediaQuery.of(context).size.height - HeaderConstants.height - 50,
child: CatalogWidget(items: CatalogFactory.items) )
]
);
}
}