update
This commit is contained in:
parent
b13b385cb7
commit
fcecb5aad5
11 changed files with 186 additions and 129 deletions
|
@ -39,9 +39,10 @@ class API {
|
|||
flowInfos = flowResp.map((key, value) => MapEntry(key, FlowInfo(value)));
|
||||
}
|
||||
|
||||
Future<void> init() async {
|
||||
Future<void> init(Function refresh) async {
|
||||
pref = await SharedPreferences.getInstance();
|
||||
instance = pref!.getString("instance") ?? "";
|
||||
refresh();
|
||||
}
|
||||
|
||||
bool isInit() {
|
||||
|
|
|
@ -20,11 +20,15 @@ class MyApp extends StatefulWidget {
|
|||
class _MyAppState extends State<MyApp> {
|
||||
bool init = false;
|
||||
|
||||
refresh() {
|
||||
setState(() {});
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
() async {
|
||||
await API().init();
|
||||
await API().init(refresh);
|
||||
if (API().isInit()) {
|
||||
await API().prefetch();
|
||||
setState(() {
|
||||
|
@ -47,7 +51,7 @@ class _MyAppState extends State<MyApp> {
|
|||
? (API().isPrefetched()
|
||||
? const MyHomePage()
|
||||
: const Scaffold(
|
||||
body: CircularProgressIndicator(),
|
||||
body: Center(child: CircularProgressIndicator()),
|
||||
))
|
||||
: const SetupPage());
|
||||
}
|
||||
|
|
|
@ -2,9 +2,8 @@ import 'package:cdb_ui/api.dart' as API;
|
|||
import 'package:cdb_ui/pages/expandable_list.dart';
|
||||
import 'package:cdb_ui/pages/flow/active_flow_page.dart';
|
||||
import 'package:cdb_ui/pages/flow/flow_info_page.dart';
|
||||
import 'package:cdb_ui/pages/transaction.dart';
|
||||
import 'package:cdb_ui/pages/supply.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:qr_bar_code_scanner_dialog/qr_bar_code_scanner_dialog.dart';
|
||||
|
||||
class FlowsPage extends StatefulWidget {
|
||||
const FlowsPage({super.key});
|
||||
|
@ -156,24 +155,18 @@ class _FlowsPageState extends State<FlowsPage> {
|
|||
_ => const Text("..."),
|
||||
},
|
||||
floatingActionButton: FloatingActionButton(
|
||||
onPressed: () {
|
||||
onPressed: () async {
|
||||
// scan flow code
|
||||
QrBarCodeScannerDialog().getScannedQrBarCode(
|
||||
context: context,
|
||||
onCode: (code) {
|
||||
// library is retarded
|
||||
code = code!.replaceFirst("Code scanned = ", "");
|
||||
var code = await scanQRCode(context, title: "Scan Flow Code");
|
||||
|
||||
API.API().getFlow(code).then((flow) {
|
||||
var info = API.API().getFlowInfo(flow.kind);
|
||||
Navigator.of(context).push(MaterialPageRoute(
|
||||
builder: (context) {
|
||||
return ActiveFlowPage(flow, info);
|
||||
},
|
||||
));
|
||||
});
|
||||
},
|
||||
);
|
||||
API.API().getFlow(code!).then((flow) {
|
||||
var info = API.API().getFlowInfo(flow.kind);
|
||||
Navigator.of(context).push(MaterialPageRoute(
|
||||
builder: (context) {
|
||||
return ActiveFlowPage(flow, info);
|
||||
},
|
||||
));
|
||||
});
|
||||
},
|
||||
child: const Icon(Icons.qr_code),
|
||||
),
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
import 'package:cdb_ui/api.dart';
|
||||
import 'package:cdb_ui/pages/itemview.dart';
|
||||
import 'package:cdb_ui/pages/supply.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});
|
||||
|
@ -18,21 +18,15 @@ class ItemsPage extends StatelessWidget {
|
|||
return ItemTile(x);
|
||||
}).toList()),
|
||||
floatingActionButton: FloatingActionButton(
|
||||
onPressed: () {
|
||||
onPressed: () async {
|
||||
// scan transaction code
|
||||
QrBarCodeScannerDialog().getScannedQrBarCode(
|
||||
context: context,
|
||||
onCode: (code) {
|
||||
// library is retarded
|
||||
code = code!.replaceFirst("Code scanned = ", "");
|
||||
var code = await scanQRCode(context, title: "Scan Transaction Code");
|
||||
|
||||
API().getTransaction(code).then((t) {
|
||||
Navigator.of(context).push(MaterialPageRoute(
|
||||
builder: (context) => TransactionPage(t),
|
||||
));
|
||||
});
|
||||
},
|
||||
);
|
||||
API().getTransaction(code!).then((t) {
|
||||
Navigator.of(context).push(MaterialPageRoute(
|
||||
builder: (context) => TransactionPage(t),
|
||||
));
|
||||
});
|
||||
},
|
||||
child: const Icon(Icons.qr_code),
|
||||
),
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
import 'package:cdb_ui/api.dart';
|
||||
import 'package:cdb_ui/pages/supply.dart';
|
||||
import 'package:cdb_ui/pages/transaction.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_simple_treeview/flutter_simple_treeview.dart';
|
||||
import 'package:qr_bar_code_scanner_dialog/qr_bar_code_scanner_dialog.dart';
|
||||
|
||||
class LocationsPage extends StatefulWidget {
|
||||
const LocationsPage({super.key});
|
||||
|
@ -63,25 +63,20 @@ class _LocationsPageState extends State<LocationsPage> {
|
|||
return buildTree(context, key);
|
||||
}).toList()),
|
||||
floatingActionButton: FloatingActionButton(
|
||||
onPressed: () {
|
||||
onPressed: () async {
|
||||
// scan location code
|
||||
QrBarCodeScannerDialog().getScannedQrBarCode(
|
||||
context: context,
|
||||
onCode: (code) {
|
||||
// library is retarded
|
||||
code = code!.replaceFirst("Code scanned = ", "");
|
||||
if (!locations!.containsKey(code)) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text('The location $code does not exist.')),
|
||||
);
|
||||
return;
|
||||
}
|
||||
var code = await scanQRCode(context, title: "Scan Location Code");
|
||||
|
||||
Navigator.of(context).push(MaterialPageRoute(
|
||||
builder: (context) => LocationView(locations![code]!),
|
||||
));
|
||||
},
|
||||
);
|
||||
if (!locations!.containsKey(code)) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text('The location $code does not exist.')),
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
Navigator.of(context).push(MaterialPageRoute(
|
||||
builder: (context) => LocationView(locations![code]!),
|
||||
));
|
||||
},
|
||||
child: const Icon(Icons.qr_code),
|
||||
),
|
||||
|
|
|
@ -1,6 +1,21 @@
|
|||
import 'package:cdb_ui/api.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:qr_bar_code_scanner_dialog/qr_bar_code_scanner_dialog.dart';
|
||||
import 'package:simple_barcode_scanner/enum.dart';
|
||||
import 'package:simple_barcode_scanner/simple_barcode_scanner.dart';
|
||||
|
||||
Future<String?> scanQRCode(BuildContext context,
|
||||
{String title = "Scan QR Code"}) async {
|
||||
var res = await Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => SimpleBarcodeScannerPage(
|
||||
scanType: ScanType.qr,
|
||||
appBarTitle: title,
|
||||
),
|
||||
));
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
class SupplyPage extends StatefulWidget {
|
||||
final Item item;
|
||||
|
@ -202,15 +217,13 @@ class _SupplyPageState extends State<SupplyPage> {
|
|||
width: 12,
|
||||
),
|
||||
IconButton(
|
||||
onPressed: () {
|
||||
QrBarCodeScannerDialog().getScannedQrBarCode(
|
||||
context: context,
|
||||
onCode: (code) {
|
||||
setState(() {
|
||||
_selectedLocation = code!;
|
||||
});
|
||||
},
|
||||
);
|
||||
onPressed: () async {
|
||||
var code = await scanQRCode(context);
|
||||
setState(() {
|
||||
if (API().getLocations().keys.contains(code)) {
|
||||
_selectedLocation = code!;
|
||||
}
|
||||
});
|
||||
},
|
||||
icon: const Icon(Icons.qr_code),
|
||||
),
|
||||
|
@ -240,7 +253,7 @@ class _SupplyPageState extends State<SupplyPage> {
|
|||
}
|
||||
|
||||
Future<Map<String, dynamic>> _fetchData() async {
|
||||
var locations = await API().getLocations();
|
||||
var locations = API().getLocations();
|
||||
var origins = await API().getUniqueField(widget.item.id, variant, "origin");
|
||||
origins.insert(0, "");
|
||||
locations[""] = Location.zero();
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
import 'package:cdb_ui/api.dart';
|
||||
import 'package:cdb_ui/pages/consume.dart';
|
||||
import 'package:cdb_ui/pages/supply.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:qr_bar_code/qr/qr.dart';
|
||||
import 'package:qr_bar_code_scanner_dialog/qr_bar_code_scanner_dialog.dart';
|
||||
|
||||
class TransactionPage extends StatefulWidget {
|
||||
final Transaction transaction;
|
||||
|
@ -78,34 +78,27 @@ class _TransactionPageState extends State<TransactionPage> {
|
|||
}).toList(),
|
||||
),
|
||||
IconButton(
|
||||
onPressed: () {
|
||||
onPressed: () async {
|
||||
var locations = API().getLocations();
|
||||
QrBarCodeScannerDialog().getScannedQrBarCode(
|
||||
context: context,
|
||||
onCode: (code) {
|
||||
// library is retarded
|
||||
code = code!
|
||||
.replaceFirst("Code scanned = ", "");
|
||||
if (!locations.containsKey(code)) {
|
||||
ScaffoldMessenger.of(context)
|
||||
.showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(
|
||||
'The location $code does not exist.')),
|
||||
);
|
||||
return;
|
||||
}
|
||||
var code = await scanQRCode(context,
|
||||
title: "Scan Location Code");
|
||||
if (!locations.containsKey(code)) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(
|
||||
'The location $code does not exist.')),
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
API()
|
||||
.moveTransaction(
|
||||
widget.transaction.uuid,
|
||||
selectedLocationID!)
|
||||
.then(
|
||||
(x) {
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
);
|
||||
});
|
||||
API()
|
||||
.moveTransaction(widget.transaction.uuid,
|
||||
selectedLocationID!)
|
||||
.then(
|
||||
(x) {
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
);
|
||||
setState(() {});
|
||||
},
|
||||
icon: const Icon(Icons.qr_code))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue