import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:flutter/material.dart';
import 'package:flutter_application_1/Project/Admin/conR.dart';
class inR extends StatefulWidget {
final String an1;
inR({Key? key, required this.an1}) : super(key: key);
@override
State<inR> createState() => _inRState();
}
const Color aColor = Color.fromARGB(219, 58, 168, 50);
const Color cColor = Color.fromARGB(246, 255, 255, 246);
const Color bColor = Color.fromARGB(153, 28, 240, 187);
class _inRState extends State<inR> {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Container(
constraints: const BoxConstraints.expand(),
decoration: const BoxDecoration(
image: DecorationImage(
image: NetworkImage(
"https://i.pinimg.com/originals/77/7b/07/777b07a784b619eb9840734261133cbd.jpg"),
fit: BoxFit.cover,
),
),
child: Padding(
padding: const EdgeInsets.all(8.0),
child: StreamBuilder(
stream:
FirebaseFirestore.instance.collection("products").snapshots(),
builder: (context, snapshot) {
if (snapshot.hasData) {
final matchingDocs = snapshot.data!.docs
.where((doc) =>
doc["Asset_Description"] == widget.an1.toString())
.toList();
if (matchingDocs.isEmpty) {
return const SizedBox.shrink();
}
final matchingDoc = matchingDocs.first;
return Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Row(
children: const [
Spacer(),
Text(
'Please Confirm Return Item',
style: TextStyle(
fontSize: 20, fontWeight: FontWeight.w900),
),
Spacer(),
],
),
const SizedBox(
height: 10,
),
Row(
children: [
const Spacer(),
const Text(
'Item name : ',
style: TextStyle(
fontSize: 15, fontWeight: FontWeight.w900),
),
Text(
widget.an1,
style: const TextStyle(
fontSize: 15, fontWeight: FontWeight.w900),
),
const Spacer(),
],
),
const SizedBox(height: 20),
ElevatedButton(
style:
ElevatedButton.styleFrom(backgroundColor: aColor),
onPressed: () {
var data = {
'Req': '0',
'BorrowingDay': '0',
'ReturnDay': '0',
'Status': '0',
'Reqre': '0',
'EmailUserReq': '0'
};
FirebaseFirestore.instance
.collection('products')
.doc(matchingDoc.id)
.update(data)
.then(
(value) => debugPrint('Updating done!'),
onError: (e) => debugPrint('Error $e'),
);
Navigator.push(
context,
MaterialPageRoute(
builder: ((context) => conAdR(
name1: widget.an1.toString(),
categoryName1: matchingDoc["cat"],
)),
),
);
},
child: const Text('Ok'),
),
],
),
);
} else if (snapshot.hasError) {
return Text('Error: ${snapshot.error}');
} else {
return const CircularProgressIndicator();
}
},
),
),
),
);
}
}