Asset-Borrowing-App / lib / Project / Admin / conB.dart
conB.dart
Raw
// ignore_for_file: camel_case_types

import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:flutter/material.dart';
import 'package:flutter_application_1/Project/Admin/Borrowed.dart';

const Color aColor = Color.fromARGB(255, 0, 0, 0);
const Color bColor = Color.fromARGB(255, 255, 255, 255);
const Color cColor = Color.fromRGBO(93, 176, 116, 1);

class conAdB extends StatefulWidget {
  final String name;
  final String categoryName;
  const conAdB({Key? key, required this.name, required this.categoryName})
      : super(key: key);

  @override
  State<conAdB> createState() => _conAdBState();
}

class _conAdBState extends State<conAdB> {
  @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: StreamBuilder<QuerySnapshot>(
          stream: FirebaseFirestore.instance
              .collection("Categories")
              .doc('pnVca0ijTvmowHmN8cXq')
              .collection(widget.categoryName)
              .snapshots(),
          builder: (context, snapshot) {
            if (snapshot.hasData) {
              final docs = snapshot.data!.docs;
              final matchingDocs = docs
                  .where((doc) =>
                      doc["Asset_Description"] == widget.name.toString())
                  .toList();
              if (matchingDocs.isEmpty) {
                return const SizedBox.shrink();
              }
              final matchingDoc = matchingDocs.first;

              return Padding(
                padding: const EdgeInsets.all(8.0),
                child: Column(
                  mainAxisAlignment: MainAxisAlignment.center,
                  children: [
                    const Icon(
                      Icons.check_circle_outline,
                      size: 100,
                      color: cColor,
                    ),
                    Row(
                      children: const [
                        Spacer(),
                        Text(
                          "Order Confirmed!",
                          style: TextStyle(
                              fontSize: 30, fontWeight: FontWeight.w900),
                        ),
                        Spacer(),
                      ],
                    ),
                    const SizedBox(
                      height: 15,
                    ),
                    Row(
                      children: const [
                        Spacer(),
                        Text(
                          "You confirmed order Name : ",
                          style: TextStyle(
                              fontSize: 15, fontWeight: FontWeight.w700),
                        ),
                        Spacer(),
                      ],
                    ),
                    Row(
                      children: [
                        const Spacer(),
                        Text(
                          "${widget.name}",
                          style: const TextStyle(
                              fontSize: 15, fontWeight: FontWeight.w700),
                        ),
                        const Spacer(),
                      ],
                    ),
                    const SizedBox(
                      height: 10,
                    ),
                    Row(
                      children: const [
                        Spacer(),
                        Text(
                          "Update Status!",
                          style: TextStyle(
                              fontSize: 15, fontWeight: FontWeight.w600),
                        ),
                        Spacer(),
                      ],
                    ),
                    const SizedBox(
                      height: 30,
                    ),
                    Row(
                      children: [
                        const Spacer(),
                        ElevatedButton(
                          style: ElevatedButton.styleFrom(
                            backgroundColor: cColor,
                          ),
                          onPressed: () {
                            var data = {'Status': '1'};
                            FirebaseFirestore.instance
                                .collection('Categories')
                                .doc('pnVca0ijTvmowHmN8cXq')
                                .collection(widget.categoryName)
                                .doc(matchingDoc.id)
                                .update(data)
                                .then(
                                  (value) => debugPrint('Updating done!'),
                                  onError: (e) => debugPrint('Error $e'),
                                );
                            Navigator.push(
                              context,
                              MaterialPageRoute(
                                builder: ((context) => BorrowAdmin()),
                              ),
                            );
                          },
                          child: const Text("Go to Home"),
                        ),
                        const Spacer(),
                      ],
                    ),
                  ],
                ),
              );
            } else if (snapshot.hasError) {
              return Text('Error: ${snapshot.error}');
            } else {
              return const CircularProgressIndicator();
            }
          },
        ),
      ),
    );
  }
}