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/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/core/services/specialized_services/search_service.dart'; class CatalogFactory implements AbstractFactory { static List items = []; static GlobalKey key = GlobalKey(); @override bool searchFill() { return CatalogFactory.items.isEmpty; } @override Widget factory(GoRouterState state, List args) { return CatalogPageWidget(); } @override void search(BuildContext context) { CatalogFactory.key.currentState?.widget.search.get(context, SearchConstants.get()!).then((value) { if (value.data == null) { return; } CatalogFactory.items = [ ...value.data!.computing, ...value.data!.data, ...value.data!.storage, ...value.data!.datacenter,]; searchWidgetKey.currentState?.setState(() {}); CatalogFactory.key.currentState?.setState(() {}); }); } } class CatalogPageWidget extends StatefulWidget { final SearchService search = SearchService(); CatalogPageWidget (): super(key: CatalogFactory.key); @override CatalogPageWidgetState createState() => CatalogPageWidgetState(); } class CatalogPageWidgetState extends State { @override Widget build(BuildContext context) { return Column( children : [ SizedBox( width: MediaQuery.of(context).size.width, height: CatalogFactory.items.isEmpty ? 0 : MediaQuery.of(context).size.height - HeaderConstants.height, child: CatalogWidget(items: CatalogFactory.items) ) ] ); } }