cdb_ui/lib/pages/flow/flow_info_page.dart
2024-09-24 18:00:13 +02:00

78 lines
2.5 KiB
Dart

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
if (widget.info.next != null) Text("Next: ${widget.info.next}"),
if (widget.info.depends.isNotEmpty)
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
const Text("Flow can use: "),
...widget.info.depends.map((x) => Text(x)).toList(),
],
),
if (widget.info.produces?.isNotEmpty ?? false)
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
const Text("Flow can produce: "),
...widget.info.produces!.map((x) => Text(x)).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)),
);
}
}