import 'package:cdb_ui/api.dart' as API; import 'package:cdb_ui/pages/flow/create_flow_page.dart'; import 'package:cdb_ui/pages/flow/end_flow_page.dart'; import 'package:cdb_ui/pages/flow/flow_note.dart'; import 'package:cdb_ui/pages/transaction.dart'; import 'package:flutter/material.dart'; class ActiveFlowPage extends StatefulWidget { final API.Flow flow; final API.FlowInfo info; const ActiveFlowPage(this.flow, this.info, {super.key}); @override State createState() => _ActiveFlowPageState(); } class _ActiveFlowPageState extends State { _refresh() { setState(() {}); } @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text(widget.info.name), actions: [ IconButton( onPressed: () async { if (widget.info.produces?.isNotEmpty ?? false) { Navigator.of(context).push(MaterialPageRoute( builder: (context) => EndFlowWithProduce(widget.flow, widget.info))); return; } // simple dialog var confirm = await showDialog( context: context, builder: (context) => AlertDialog( title: const Text('Are you sure?'), content: const Text('This will end the flow.'), actions: [ TextButton( onPressed: () => Navigator.of(context).pop(false), child: const Text('Cancel'), ), ElevatedButton( onPressed: () => Navigator.of(context).pop(true), child: const Text('End'), ), ], ), ); if (confirm) { await API .API() .endFlow(widget.flow.id) .then((x) => Navigator.of(context).pop()); } }, icon: const Icon(Icons.stop)), // todo : continue next flow if (widget.info.next != null) IconButton( onPressed: () { API.API().getFlowInfo(widget.info.next!).then((newInfo) { Navigator.of(context).push(MaterialPageRoute( builder: (context) { return CreateFlowPage( newInfo, () {}, previousFlow: widget.flow, ); }, )); }); }, icon: const Icon(Icons.arrow_forward)), ], ), body: Column( children: [ Text("ID: ${widget.flow.id}"), Text("Started since: ${tsFormat(widget.flow.started)}"), if (widget.flow.input != null) ...widget.flow.input!.map((x) => Text("Input: $x")).toList(), if (widget.flow.done != null) ...[ Text("Ended: ${tsFormat(widget.flow.done!.ended)}"), if (widget.flow.done!.next != null) Text("Next: ${widget.flow.done!.next!}"), ...widget.flow.done!.produced! .map((x) => Text("Produced: $x")) .toList(), ], const Divider(), FutureBuilder( future: API.API().getNotesOfFlow(widget.flow.id), builder: (context, snapshot) { if (!snapshot.hasData) { return const CircularProgressIndicator(); } var data = snapshot.data!; return Expanded( child: ListView( children: data .map( (x) => FlowNoteCard(x), ) .toList())); }, ) ], ), floatingActionButton: FloatingActionButton( onPressed: () { Navigator.of(context).push(MaterialPageRoute( builder: (context) => AddNotePage(widget.flow, _refresh))); }, child: const Icon(Icons.note_add), ), ); } }