Skip to content

Commit

Permalink
Merge pull request #11 from Team-Optix-3749/barcode-scanner
Browse files Browse the repository at this point in the history
Barcode Functionality
  • Loading branch information
rjawesome committed Jan 5, 2024
2 parents 6eb3054 + cdc9dea commit 4494143
Show file tree
Hide file tree
Showing 7 changed files with 530 additions and 187 deletions.
22 changes: 11 additions & 11 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

48 changes: 45 additions & 3 deletions lib/services/database.dart
Original file line number Diff line number Diff line change
Expand Up @@ -712,6 +712,41 @@ class Database {

return inventory;
}

static Future<Inventory?> modifyInventory(firebase.IdTokenResult idToken,
String barcodeId, String? newStatus, String? newLocation, BuildContext context) async {
var client = http.Client();

Map data = {
'endpoint': 'modify-inventory',
'auth': idToken.token,
'barcodeId': barcodeId,
'status': newStatus,
'location': newLocation
};

var body = json.encode(data);

var result = await client.post(Uri.parse(Constants.SERVER_URL),
headers: {"Content-Type": "application/json"}, body: body);

if (result.statusCode != 200) {
Alert.showAlert(context, jsonDecode(result.body)['err']);
return null;
}

if (jsonDecode(result.body)['inventory'] == null) {
Alert.showAlert(context, "Inventoried tool does not exist!");
return null;
}

final parsed =
jsonDecode(result.body)['inventory'];

var inventory = Inventory.fromJson(parsed);

return inventory;
}
}

final Map<String, String> deliveryMap = {
Expand Down Expand Up @@ -831,21 +866,28 @@ class User {

class Inventory {
final String name;
final String? description;
final String description;
final int count;
final String barcodeId;
final String status;
final String location;
Inventory(
{required this.name,
required this.count,
required this.barcodeId,
required this.description});
required this.description,
required this.status,
required this.location
});

factory Inventory.fromJson(Map<String, dynamic> json) {
return Inventory(
name: json['name'] as String,
count: json['count'] as int,
barcodeId: json['barcodeId'] as String,
description: json['description'] as String?);
description: json['description'] as String,
status: json['status'] as String,
location: json['location'] as String);
}

String toString() {
Expand Down
136 changes: 136 additions & 0 deletions lib/ui/BarcodeResultPage.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
import 'package:flutter/material.dart';
import 'package:OptixToolkit/services/database.dart';
import 'package:google_fonts/google_fonts.dart';

class BarcodeResultPage extends StatelessWidget {
final String barcodeValue;
final Inventory inventory;

const BarcodeResultPage({Key? key, required this.barcodeValue, required this.inventory})
: super(key: key);

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
centerTitle: true,
title: Text(
"BARCODE RESULT",
style: GoogleFonts.rubik(fontWeight: FontWeight.bold),
textAlign: TextAlign.center,
),
backgroundColor: Color(0xff159deb),
),
body: Container(
color: Color.fromARGB(255, 51, 44, 44), // Not sure if this is the right shade of gray
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text( //Tool Name
'Tool Name: ${inventory.name}',
style: TextStyle(fontSize: 25, fontWeight: FontWeight.bold, color: Colors.white),
),
Text( //Barcode Value
'Barcode ID: $barcodeValue',
style: TextStyle(fontSize: 18, fontWeight: FontWeight.w500, color: Colors.white),
),

SizedBox(height: 30),

Text( // Tool Description
'Tool Description: ${inventory.description}',
style: TextStyle(fontSize: 18, fontWeight: FontWeight.normal, color: Colors.white),
),
SizedBox(height: 10),
Text( // Tool Count
'Tool Count: ${inventory.count}',
style: TextStyle(fontSize: 18, fontWeight: FontWeight.normal, color: Colors.white),
),
// Tool Status
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
'Tool Status: ${inventory.status}',
style: TextStyle(fontSize: 18, color: Colors.white),
),
ElevatedButton(
onPressed: () {
_handleChange('Tool Status', inventory.status, context);
},
child: Text('Change',
style: TextStyle(color: Colors.white)),
style: ElevatedButton.styleFrom(
primary: Colors.blue, // Set the button color to blue
),
),
],
),

// Tool Location
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
'Tool Location: ${inventory.location}',
style: TextStyle(fontSize: 18, color: Colors.white),
),
ElevatedButton(
onPressed: () {
_handleChange('Tool Location', inventory.location, context);
},
child: Text('Change',
style: TextStyle(color: Colors.white)),
style: ElevatedButton.styleFrom(
primary: Colors.blue, // Set the button color to blue
),
),
],
),
],
),
),
),
);
}

//This is the function to handle changing tool attributes
void _handleChange(String attributeName, String currentValue, BuildContext context) async {
TextEditingController inputController = TextEditingController();

showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: Text('Change $attributeName'),
content: TextField(
controller: inputController,
keyboardType: TextInputType.text,
decoration: InputDecoration(labelText: 'Enter new $attributeName'),
),
actions: <Widget>[
TextButton(
onPressed: () {
Navigator.of(context).pop();
},
child: Text('Cancel'),
),
TextButton(
onPressed: () {
String newValue = inputController.text.trim();
if (newValue.isNotEmpty) {
Navigator.of(context).pop();
} else {
print("Please enter a valid $attributeName");
}
},
child: Text('Submit'),
),
],
);
},
);
}
}
Loading

0 comments on commit 4494143

Please sign in to comment.