oc-front/lib/pages/catalog.dart

41 lines
1.8 KiB
Dart
Raw Normal View History

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/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<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.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<CatalogPageWidget> {
@override Widget build(BuildContext context) {
return Column( children : [
SizedBox(
width: MediaQuery.of(context).size.width,
2024-07-17 13:28:02 +02:00
height: CatalogFactory.items.isEmpty ? 0 : MediaQuery.of(context).size.height - HeaderConstants.height,
child: CatalogWidget(items: CatalogFactory.items) )
]
);
}
}