diff --git a/lib/api.dart b/lib/api.dart index 36d88e7..739a772 100644 --- a/lib/api.dart +++ b/lib/api.dart @@ -2,6 +2,8 @@ import 'dart:convert'; import 'package:http/http.dart' as http; import 'package:shared_preferences/shared_preferences.dart'; +// todo : api errors + class API { late SharedPreferences pref; static final API _instance = API._internal(); diff --git a/lib/pages/flow.dart b/lib/pages/flow.dart index 05c3b20..484441a 100644 --- a/lib/pages/flow.dart +++ b/lib/pages/flow.dart @@ -4,10 +4,24 @@ import 'package:flutter/material.dart'; class FlowsPage extends StatelessWidget { const FlowsPage({super.key}); + Widget listAllFlowInfos( + BuildContext context, Map 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 by item produced - // todo : list all flow kinds + // todo : flows (info) by item produced // todo : list currently active // todo : flows by item needed (show only avail) return Scaffold( @@ -21,17 +35,7 @@ class FlowsPage extends StatelessWidget { 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()); + return listAllFlowInfos(context, data); })); } } diff --git a/lib/pages/items.dart b/lib/pages/items.dart index fb28f1f..fa5db2f 100644 --- a/lib/pages/items.dart +++ b/lib/pages/items.dart @@ -1,6 +1,8 @@ import 'package:cdb_ui/api.dart'; import 'package:cdb_ui/pages/itemview.dart'; +import 'package:cdb_ui/pages/transaction.dart'; import 'package:flutter/material.dart'; +import 'package:qr_bar_code_scanner_dialog/qr_bar_code_scanner_dialog.dart'; class ItemsPage extends StatelessWidget { const ItemsPage({super.key}); @@ -25,6 +27,25 @@ class ItemsPage extends StatelessWidget { return ItemTile(x); }).toList()); }), + floatingActionButton: FloatingActionButton( + onPressed: () { + // scan transaction code + QrBarCodeScannerDialog().getScannedQrBarCode( + context: context, + onCode: (code) { + // library is retarded + code = code!.replaceFirst("Code scanned = ", ""); + + API().getTransaction(code).then((t) { + Navigator.of(context).push(MaterialPageRoute( + builder: (context) => TransactionPage(t), + )); + }); + }, + ); + }, + child: const Icon(Icons.qr_code), + ), ); } }