add location scanning + overview
This commit is contained in:
parent
d3827c96c4
commit
1c4c0dbc69
2 changed files with 117 additions and 56 deletions
|
@ -1,14 +1,69 @@
|
|||
import 'package:cdb_ui/api.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 LocationsPage extends StatelessWidget {
|
||||
class LocationsPage extends StatefulWidget {
|
||||
const LocationsPage({super.key});
|
||||
|
||||
@override
|
||||
State<LocationsPage> createState() => _LocationsPageState();
|
||||
}
|
||||
|
||||
class _LocationsPageState extends State<LocationsPage> {
|
||||
Map<String, Location>? locations;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
API().getLocations().then(
|
||||
(value) {
|
||||
setState(() {
|
||||
locations = value;
|
||||
});
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
// todo : add locations tree view
|
||||
return const Scaffold();
|
||||
|
||||
if (locations == null) {
|
||||
return const Scaffold(
|
||||
body: CircularProgressIndicator(),
|
||||
);
|
||||
}
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text("Locations"),
|
||||
),
|
||||
body: null,
|
||||
floatingActionButton: FloatingActionButton(
|
||||
onPressed: () {
|
||||
// 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;
|
||||
}
|
||||
|
||||
Navigator.of(context).push(MaterialPageRoute(
|
||||
builder: (context) => LocationView(locations![code]!),
|
||||
));
|
||||
},
|
||||
);
|
||||
},
|
||||
child: const Icon(Icons.qr_code),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -34,53 +89,59 @@ class _LocationViewState extends State<LocationView> {
|
|||
appBar: AppBar(
|
||||
title: Text(widget.location.name),
|
||||
),
|
||||
body: Column(
|
||||
children: [
|
||||
Card(
|
||||
child: Column(
|
||||
body: Padding(
|
||||
padding: EdgeInsets.symmetric(horizontal: 10.0),
|
||||
child: Column(
|
||||
children: [
|
||||
Card(
|
||||
child: Column(
|
||||
children: [
|
||||
if (widget.location.parent != null)
|
||||
Text("Inside: ${widget.location.parent!}"),
|
||||
if (widget.location.conditions?.temperature != null)
|
||||
Text(
|
||||
"Temperature: ${widget.location.conditions!.temperature} C°")
|
||||
],
|
||||
),
|
||||
),
|
||||
Row(
|
||||
children: [
|
||||
if (widget.location.parent != null)
|
||||
Text("Inside: ${widget.location.parent!}"),
|
||||
if (widget.location.conditions?.temperature != null)
|
||||
Text(
|
||||
"Temperature: ${widget.location.conditions!.temperature} C°")
|
||||
Checkbox(
|
||||
value: !recursive,
|
||||
onChanged: (bool? newValue) {
|
||||
setState(() {
|
||||
recursive = !(newValue ?? false);
|
||||
});
|
||||
},
|
||||
),
|
||||
const Expanded(
|
||||
child: Text(
|
||||
'Show only exact matches with location',
|
||||
style: TextStyle(fontSize: 16),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
Row(
|
||||
children: [
|
||||
Checkbox(
|
||||
value: !recursive,
|
||||
onChanged: (bool? newValue) {
|
||||
setState(() {
|
||||
recursive = !(newValue ?? false);
|
||||
});
|
||||
Expanded(
|
||||
child: FutureBuilder(
|
||||
future: API().getTransactionsOfLocation(widget.location.id,
|
||||
recursive: recursive),
|
||||
builder: (context, snapshot) {
|
||||
if (!snapshot.hasData) {
|
||||
return const CircularProgressIndicator();
|
||||
}
|
||||
|
||||
var data = snapshot.data!;
|
||||
|
||||
return ListView(
|
||||
children: data
|
||||
.map((x) => TransactionCard(x, refresh))
|
||||
.toList());
|
||||
},
|
||||
),
|
||||
const Expanded(
|
||||
child: Text(
|
||||
'Show only exact matches with location',
|
||||
style: TextStyle(fontSize: 16),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
FutureBuilder(
|
||||
future: API().getTransactionsOfLocation(widget.location.id,
|
||||
recursive: recursive),
|
||||
builder: (context, snapshot) {
|
||||
if (!snapshot.hasData) {
|
||||
return const CircularProgressIndicator();
|
||||
}
|
||||
|
||||
var data = snapshot.data!;
|
||||
|
||||
return ListView(
|
||||
children:
|
||||
data.map((x) => TransactionCard(x, refresh)).toList());
|
||||
},
|
||||
)
|
||||
],
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue