import 'package:cdb_ui/api.dart' as API; import 'package:cdb_ui/pages/flow/active_flow_page.dart'; import 'package:cdb_ui/pages/flow/create_flow_page.dart'; import 'package:flutter/material.dart'; class FlowInfoPage extends StatefulWidget { final API.FlowInfo info; const FlowInfoPage(this.info, {super.key}); @override State createState() => _FlowInfoPageState(); } class _FlowInfoPageState extends State { void refresh() { setState(() {}); } @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar(title: Text(widget.info.name)), body: Column( children: [ // todo : ui improve if (widget.info.next != null) Text("Next: ${API.API().getFlowInfo(widget.info.next!).name}"), if (widget.info.depends.isNotEmpty) Row( mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [ const Text("Flow can use: "), ...widget.info.depends.map((x) { var (item, variant) = API.itemVariant(x); return Text(API.API().getItem(item).variants[variant]!.name); }).toList(), ], ), if (widget.info.produces?.isNotEmpty ?? false) Row( mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [ const Text("Flow can produce: "), ...widget.info.produces!.map((x) { var (item, variant) = API.itemVariant(x); return Text(API.API().getItem(item).variants[variant]!.name); }).toList(), ], ), const Divider(), FutureBuilder( future: API.API().getActiveFlowsOf(widget.info.id), builder: (context, snapshot) { if (!snapshot.hasData) { return const CircularProgressIndicator(); } var data = snapshot.data!; return Expanded( child: ListView( children: data .map((x) => ListTile( title: Text(x.id), onTap: () => Navigator.of(context).push(MaterialPageRoute( builder: (context) => ActiveFlowPage(x, widget.info), )))) .toList()), ); }, ) ], ), floatingActionButton: FloatingActionButton( onPressed: () { Navigator.of(context).push(MaterialPageRoute( builder: (context) => CreateFlowPage(widget.info, refresh))); }, child: const Icon(Icons.add)), ); } }