cdb_ui/lib/pages/flow.dart
2024-09-19 08:46:48 +02:00

82 lines
2.3 KiB
Dart

import 'package:cdb_ui/api.dart';
import 'package:flutter/material.dart';
class FlowsPage extends StatelessWidget {
const FlowsPage({super.key});
@override
Widget build(BuildContext context) {
// todo : flows by item produced
return Scaffold(
appBar: AppBar(title: const Text("Flows")),
body: FutureBuilder(
future: API().getFlows(),
builder: (ctx, snap) {
if (!snap.hasData) {
return const CircularProgressIndicator();
}
var data = snap.data!;
return ListView(
children: data.values.map((x) {
return ListTile(
title: Text(x.name),
onTap: () {
Navigator.of(context).push(MaterialPageRoute(
builder: (context) => FlowPage(x),
));
},
);
}).toList());
}));
}
}
class FlowPage extends StatelessWidget {
final FlowInfo info;
const FlowPage(this.info, {super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text(info.name)),
body: Column(
children: [
// todo : ui improve
if (info.next != null) Text("Next: ${info.next}"),
if (info.depends.isNotEmpty)
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
const Text("Flow can use: "),
...info.depends.map((x) => Text(x)).toList(),
],
),
if (info.produces?.isNotEmpty ?? false)
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
const Text("Flow can produce: "),
...info.produces!.map((x) => Text(x)).toList(),
],
),
const Divider(),
FutureBuilder(
future: API().getActiveFlowsOf(info.id),
builder: (context, snapshot) {
if (!snapshot.hasData) {
return const CircularProgressIndicator();
}
var data = snapshot.data!;
return ListView(children: data.map((x) => Text(x.id)).toList());
},
)
],
),
);
}
}