cdb_ui/lib/pages/flow.dart
2024-09-23 10:31:40 +02:00

111 lines
3 KiB
Dart

import 'package:cdb_ui/api.dart' as API;
import 'package:flutter/material.dart';
class FlowsPage extends StatelessWidget {
const FlowsPage({super.key});
Widget listAllFlowInfos(
BuildContext context, Map<String, API.FlowInfo> infos) {
return ListView(
children: infos.values.map((x) {
return ListTile(
title: Text(x.name),
onTap: () {
Navigator.of(context).push(MaterialPageRoute(
builder: (context) => FlowPage(x),
));
},
);
}).toList());
}
@override
Widget build(BuildContext context) {
// todo : flows (info) by item produced
// todo : list currently active
// todo : flows by item needed (show only avail)
return Scaffold(
appBar: AppBar(title: const Text("Flows")),
body: FutureBuilder(
future: API.API().getFlows(),
builder: (ctx, snap) {
if (!snap.hasData) {
return const CircularProgressIndicator();
}
var data = snap.data!;
return listAllFlowInfos(context, data);
}));
}
}
class FlowPage extends StatelessWidget {
final API.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.API().getActiveFlowsOf(info.id),
builder: (context, snapshot) {
if (!snapshot.hasData) {
return const CircularProgressIndicator();
}
var data = snapshot.data!;
return ListView(
children: data
.map((x) => ListTile(
title: Text(x.id),
onTap: () =>
Navigator.of(context).push(MaterialPageRoute(
builder: (context) => ActiveFlowPage(x),
))))
.toList());
},
)
],
),
);
}
}
class ActiveFlowPage extends StatelessWidget {
late API.Flow flow;
ActiveFlowPage(this.flow);
@override
Widget build(BuildContext context) {
return Scaffold(
body: Column(
children: [],
));
}
}