diff --git a/lib/api.dart b/lib/api.dart index 5595117..ae2f339 100644 --- a/lib/api.dart +++ b/lib/api.dart @@ -4,12 +4,16 @@ import 'package:http/http.dart' as http; import 'package:shared_preferences/shared_preferences.dart'; // todo : api errors -// todo : api caching class API { late SharedPreferences pref; static final API _instance = API._internal(); + // cache + List? items; + Map? locations; + Map? flowInfos; + factory API() { return _instance; } @@ -57,9 +61,14 @@ class API { // /items Future> getItems() async { + if (items != null) { + return items!; + } + var resp = jsonDecode(await getRequest("$instance/items")); var lst = resp["items"] as List; - return lst.map((x) => Item(x)).toList(); + items = lst.map((x) => Item(x)).toList(); + return items!; } Future getGlobalItemStat() async { @@ -82,12 +91,21 @@ class API { } Future> getLocations() async { + if (locations != null) { + return locations!; + } + var resp = jsonDecode(await getRequest("$instance/locations")) as Map; - return resp.map((key, value) => MapEntry(key, Location(value))); + locations = resp.map((key, value) => MapEntry(key, Location(value))); + return locations!; } Future getItem(String item) async { + if (items != null) { + return items!.firstWhere((x) => x.id == item); + } + return Item(jsonDecode(await getRequest("$instance/item/$item"))); } @@ -219,14 +237,23 @@ class API { // /flows Future> getFlows() async { + if (flowInfos != null) { + return flowInfos!; + } + var resp = jsonDecode(await getRequest("$instance/flows")) as Map; - return resp.map((key, value) => MapEntry(key, FlowInfo(value))); + flowInfos = resp.map((key, value) => MapEntry(key, FlowInfo(value))); + return flowInfos!; } // /flow//info Future getFlowInfo(String id) async { + if (flowInfos != null) { + return flowInfos![id]!; + } + return FlowInfo(jsonDecode(await getRequest("$instance/flow/$id/info"))); } @@ -288,6 +315,10 @@ class API { } Future getLocation(String id) async { + if (locations != null) { + return locations![id]!; + } + var resp = jsonDecode(await getRequest("$instance/location/$id")); return Location(resp); } diff --git a/lib/pages/flow/active_flow_page.dart b/lib/pages/flow/active_flow_page.dart index c0aef7f..47fc691 100644 --- a/lib/pages/flow/active_flow_page.dart +++ b/lib/pages/flow/active_flow_page.dart @@ -62,7 +62,6 @@ class _ActiveFlowPageState extends State { } }, icon: const Icon(Icons.stop)), - // todo : continue next flow if (widget.info.next != null) IconButton( onPressed: () { diff --git a/lib/pages/flow/create_flow_page.dart b/lib/pages/flow/create_flow_page.dart index 351215f..2d66a66 100644 --- a/lib/pages/flow/create_flow_page.dart +++ b/lib/pages/flow/create_flow_page.dart @@ -3,7 +3,6 @@ import 'package:cdb_ui/pages/flow/active_flow_page.dart'; import 'package:cdb_ui/pages/transaction.dart'; import 'package:flutter/material.dart'; - class CreateFlowPage extends StatefulWidget { final API.FlowInfo info; final Function refresh; @@ -77,13 +76,30 @@ class _CreateFlowPageState extends State { }).toList()); } + Widget flowContinuation() { + return Row( + children: [ + Card( + child: Text(widget.previousFlow!.kind), + ), + const Text(" -> "), + Card( + child: Text(widget.info.name), + ) + ], + ); + } + @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar(title: Text("Create new ${widget.info.name} Flow")), body: Column( children: [ - // todo : flow continuation overview + if (widget.previousFlow != null) ...[ + flowContinuation(), + const Divider() + ], buildInputSelection(context), const Divider(), Card( @@ -99,4 +115,4 @@ class _CreateFlowPageState extends State { ), ); } -} \ No newline at end of file +} diff --git a/lib/pages/flow/end_flow_page.dart b/lib/pages/flow/end_flow_page.dart index 66c70ef..212aaef 100644 --- a/lib/pages/flow/end_flow_page.dart +++ b/lib/pages/flow/end_flow_page.dart @@ -78,7 +78,6 @@ class _EndFlowWithProduceState extends State { @override Widget build(BuildContext context) { - // todo : show end screen with produce return Scaffold( appBar: AppBar( title: Text("End ${widget.info.name} Flow"), @@ -87,7 +86,6 @@ class _EndFlowWithProduceState extends State { children: [ ...addProduceButtons(), const Divider(), - // todo : add produced list ...produces.map((x) { return TransactionCard( x.transaction(locations), diff --git a/lib/pages/supply.dart b/lib/pages/supply.dart index 985a72d..342a352 100644 --- a/lib/pages/supply.dart +++ b/lib/pages/supply.dart @@ -50,7 +50,6 @@ class _SupplyPageState extends State { _formKey.currentState!.save(); if (widget.onCreate != null) { - // todo : create shadow transaction var t = SupplyForm( itemID: widget.item.id, variant: variant,