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'; import 'package:qr_bar_code/qr/src/qr_code.dart'; import 'package:qr_bar_code/qr/src/types.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 ?? false) { await API .API() .endFlow(widget.flow.id) .then((x) => Navigator.of(context).pop()); } }, icon: const Icon(Icons.stop)), if (widget.info.next != null) IconButton( onPressed: () { var newInfo = API.API().getFlowInfo(widget.info.next!); Navigator.of(context).push(MaterialPageRoute( builder: (context) { return CreateFlowPage( newInfo, () {}, previousFlow: widget.flow, ); }, )); }, icon: const Icon(Icons.arrow_forward)), ], ), body: Padding( padding: const EdgeInsets.symmetric(horizontal: 18.0), child: Column( children: [ Row( children: [ QRCode( data: widget.flow.id, size: 128, eyeStyle: const QREyeStyle(color: Colors.white), dataModuleStyle: const QRDataModuleStyle(color: Colors.white), semanticsLabel: "Transaction UUID", ), const SizedBox( width: 16.0, ), 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), ), ); } }