cdb_ui/lib/pages/flow/flow_info_page.dart

86 lines
2.8 KiB
Dart
Raw Permalink Normal View History

2024-09-24 16:00:13 +00:00
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<FlowInfoPage> createState() => _FlowInfoPageState();
}
class _FlowInfoPageState extends State<FlowInfoPage> {
void refresh() {
setState(() {});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text(widget.info.name)),
body: Column(
children: [
// todo : ui improve
2024-09-26 19:35:28 +00:00
if (widget.info.next != null)
Text("Next: ${API.API().getFlowInfo(widget.info.next!).name}"),
2024-09-24 16:00:13 +00:00
if (widget.info.depends.isNotEmpty)
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
const Text("Flow can use: "),
2024-09-26 19:35:28 +00:00
...widget.info.depends.map((x) {
var (item, variant) = API.itemVariant(x);
return Text(API.API().getItem(item).variants[variant]!.name);
}).toList(),
2024-09-24 16:00:13 +00:00
],
),
if (widget.info.produces?.isNotEmpty ?? false)
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
const Text("Flow can produce: "),
2024-09-26 19:35:28 +00:00
...widget.info.produces!.map((x) {
var (item, variant) = API.itemVariant(x);
return Text(API.API().getItem(item).variants[variant]!.name);
}).toList(),
2024-09-24 16:00:13 +00:00
],
),
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)),
);
}
}