0

This is my code where I am showing list of pending invoices.But when i accept the it should reload the pending invoice widget after clicking on snack bar action button.When user clicks on accept button its showing snack bar and when pressed accept action button snack bar it navigate back to same widget where I needs to update that widget along with new list of pending invoices without the invoice which we have accepted

class PendingInvoiceWidget extends StatelessWidget {
  final double maxWidth;
  final double maxHeight;
  final bool isOverdue;
  final String amount;
  final String savedAmount;
  final String invoiceDate;
  final String dueDate;
  Invoice fullDetails;
  int index;
  bool userConsentGiven = false;

  final String companyName;
  PendingInvoiceWidget(
      {required this.fullDetails,
      required this.maxWidth,
      required this.maxHeight,
      required this.amount,
      required this.savedAmount,
      required this.index,
      required this.invoiceDate,
      required this.dueDate,
      required this.companyName,
      required this.isOverdue});

  @override
  Widget build(BuildContext context) {
    TextEditingController acceptController = TextEditingController();
    TextEditingController rejectController = TextEditingController();
    List<Invoice> pendingInvoice =
        Provider.of<TransactionManager>(context).pendingInvoice;
    String? invoiceId = fullDetails.sId;
    String invAmt = double.parse(amount).toStringAsFixed(2);

    DateTime id = DateTime.parse(invoiceDate);
    DateTime dd = DateTime.parse(dueDate);
    DateTime currentDate = DateTime.now();
    Duration dif = dd.difference(currentDate);
    int daysLeft = dif.inDays;
    String idueDate = DateFormat("dd-MMM-yyyy").format(dd);
    String invDate = DateFormat("dd-MMM-yyyy").format(id);

    double h1p = maxHeight * 0.01;
    double h10p = maxHeight * 0.1;
    double w10p = maxWidth * 0.1;
    return ProgressHUD(child: Builder(builder: (context) {
      final progress = ProgressHUD.of(context);
      return ExpandableNotifier(
        child: Padding(
          padding: EdgeInsets.symmetric(horizontal: w10p * .5, vertical: 10),
          child: Expandable(
              collapsed: ExpandableButton(
                child: Card(
                  child: Container(
                    padding: EdgeInsets.all(10),
                    decoration: BoxDecoration(
                      borderRadius: BorderRadius.circular(10),
                      color: Colours.offWhite,
                    ),
                    child: Row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        children: [
                          Column(
                            crossAxisAlignment: CrossAxisAlignment.start,
                            children: [
                              isOverdue
                                  ? Padding(
                                      padding: EdgeInsets.symmetric(
                                          vertical: h1p * 1),
                                      child: Container(
                                        // height: h1p * 4.5,
                                        // width: w10p * 1.7,
                                        decoration: BoxDecoration(
                                          borderRadius:
                                              BorderRadius.circular(5),
                                          color: Colours.failPrimary,
                                        ),
                                        child: const Center(
                                          child: Padding(
                                            padding: EdgeInsets.all(4),
                                            child: Text(
                                              "Overdue",
                                              style: TextStyles.overdue,
                                            ),
                                          ),
                                        ),
                                      ),
                                    )
                                  : Container(),

                              Row(
                                children: [
                                  Text(
                                    "${fullDetails.invoiceNumber}",
                                    style: TextStyles.textStyle6,
                                  ),
                                  SvgPicture.asset(
                                      "assets/images/home_images/arrow-circle-right.svg"),
                                ],
                              ),

                              
              expanded: Column(
                children: [
                  ExpandableButton(
                    child: Card(
                      child: Container(
                        padding: EdgeInsets.all(10),
                        decoration: BoxDecoration(
                          borderRadius: BorderRadius.circular(10),
                          color: Colours.offWhite,
                        ),
                              Column(
                                crossAxisAlignment: CrossAxisAlignment.end,
                                children: [
                                  isOverdue
                                      ? Text(
                                          "$daysLeft days Overdue",
                                          style: TextStyles.textStyle57,
                                        )
                                      : Text(
                                          "$daysLeft days left",
                                          style: TextStyles.textStyle57,
                                        ),
                                  Text(
                                    "₹ $invAmt",
                                    style: TextStyles.textStyle58,
                                  ),
                                ],
                              )
                            ]),
                      ),
                    ),
                  ),
                  Card(
                    elevation: .5,
                    child: Padding(
                      padding: const EdgeInsets.all(10.0),
                      child: Row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        children: [
                          Column(
                            crossAxisAlignment: CrossAxisAlignment.start,
                            children: [
                              const SizedBox(
                                height: 4,
                              ),
                              const Text(
                                "Invoice Date",
                                style: TextStyles.textStyle62,
                              ),
                              Text(
                                invDate,
                                style: TextStyles.textStyle63,
                              ),
                              // Text(
                              //   companyName,
                              //   style: TextStyles.companyName,
                              // ),
                            ],
                          ),
                          SvgPicture.asset("assets/images/arrow.svg"),
                          Column(
                            crossAxisAlignment: CrossAxisAlignment.end,
                            children: [
                              const SizedBox(
                                height: 4,
                              ),
                              const Text(
                                "Due Date",
                                style: TextStyles.textStyle62,
                              ),
                              Text(
                                idueDate,
                                style: TextStyles.textStyle63,
                              ),
                              // Text(
                              //  companyName,
                              //   style: TextStyles.companyName,
                              // ),
                            ],
                          ),
                        ],
                      ),
                    ),
                  ),
                  Card(
                    child: Container(
                      padding: const EdgeInsets.all(10),
                      decoration: const BoxDecoration(),
                      child: Column(
                        children: [
                          Row(
                            mainAxisAlignment: MainAxisAlignment.spaceBetween,
                            children: [
                              Column(
                                crossAxisAlignment: CrossAxisAlignment.start,
                                children: [
                                  const SizedBox(
                                    height: 4,
                                  ),
                                  const Text(
                                    "Invoice Amount",
                                    style: TextStyles.textStyle62,
                                  ),
                                  Text(
                                    "₹ $invAmt",
                                    style: TextStyles.textStyle65,
                                  )
                                  //    Text("Asian Paints",style: TextStyles.textStyle34,),
                                ],
                              ),
                              Column(
                                crossAxisAlignment: CrossAxisAlignment.end,
                                children: [
                                  const SizedBox(
                                    height: 4,
                                  ),
                                  isOverdue
                                      ? const Text(
                                          "Payabe Amount",
                                          style: TextStyles.textStyle62,
                                        )
                                      : const Text(
                                          "Pay Now",
                                          style: TextStyles.textStyle62,
                                        ),
                                  Text(
                                    "₹ $invAmt",
                                    style: TextStyles.textStyle66,
                                  ),
                                ],
                              ),
                            ],
                          ),
                          SizedBox(
                            height: h1p * 1.5,
                          ),
                          // Row(
                          //   mainAxisAlignment: MainAxisAlignment.start,
                          //   children: [
                          //     Column(
                          //       crossAxisAlignment: CrossAxisAlignment.start,
                          //       children: [
                          //         isOverdue?
                          //         const Text(
                          //           "Interest",
                          //           style: TextStyles.textStyle62,
                          //         ):
                          //         const Text(
                          //           "You Save",
                          //           style: TextStyles.textStyle62,
                          //         ),
                          //         Text(
                          //           "₹ $savedAmount",
                          //           style:isOverdue?
                          //           TextStyles.textStyle73:
                          //           TextStyles.textStyle77,
                          //         ),
                          //       ],
                          //     ),
                          //   ],
                          // ),

                          Padding(
                            padding: const EdgeInsets.symmetric(vertical: 10.0),
                            child: GestureDetector(
                                onTap: () {
                                  progress!.show();
                                  getIt<TransactionManager>()
                                      .changeSelectedInvoice(fullDetails);
                                  progress.dismiss();
                                  Navigator.pushNamed(context, savemoreDetails);
                                },
                                child: Image.asset(
                                    "assets/images/viewetails.png")),
                          ),
                          Row(
                            children: [
                              Expanded(
                                child: InkWell(
                                  onTap: () async {
                                    showDialog(
                                        context: context,
                                        builder: (context) => Padding(
                                              padding:
                                                  const EdgeInsets.symmetric(
                                                      // vertical: h10p * 5,
                                                      ),
                                              child: AlertDialog(
                                                shape:
                                                    const RoundedRectangleBorder(
                                                        borderRadius:
                                                            BorderRadius.all(
                                                                Radius.circular(
                                                                    10.0))),
                                                title: Row(
                                                  children: const [
                                                    Center(
                                                      child: Text("Comment"),
                                                    ),
                                                  ],
                                                ),
                                
                              const SizedBox(
                                width: 10,
                              ),
                              Expanded(
                                child: InkWell(
                                  onTap: () async {
                                    showDialog(
                                        context: context,
                                        builder: (context) => Padding(
                                              padding:
                                                  const EdgeInsets.symmetric(
                                                      // vertical: h10p * 4,
                                                      ),
                                              child: StatefulBuilder(
                                                  builder: (context, setState) {
                                                return AlertDialog(
                                                  shape:
                                                      const RoundedRectangleBorder(
                                                          borderRadius:
                                                              BorderRadius.all(
                                                                  Radius.circular(
                                                                      10.0))),
                                                  title: const Center(
                                                    child: Text("Consent"),
                                                  ),
                                                  content: Column(
                                                    mainAxisSize:
                                                        MainAxisSize.min,
                                                    children: [
                                                      Text(
                                                          "I agree and  approve Xuriti and NBFC Ditya Finance Private Limited to disburse funds to yhe seller $companyName for invoice number -${fullDetails.invoiceNumber} on my behalf"),
                                                      TextField(
                                                        controller:
                                                            acceptController,
                                                        decoration:
                                                            const InputDecoration(
                                                                hintText:
                                                                    "Leave a comment *"),
                                                        onChanged: (_) {
                                                          print(acceptController
                                                              .text);
                                                          acceptController
                                                                  .text.isEmpty
                                                              ? Row(
                                                                  children: const [
                                                                    Text(
                                                                      "Please write a reason",
                                                                      style: TextStyle(
                                                                          color:
                                                                              Colors.red),
                                                                    ),
                                                                  ],
                                                                )
                                                              : Container();
                                                        },
                                                      ),
                                                      SizedBox(
                                                        height: h1p * 4,
                                                      ),
                                                      InkWell(
                                                        onTap: () async {
                                                          userConsentGiven =
                                                              true;
                                                          String timeStamp =
                                                              DateTime.now()
                                                                  .toString();
                                                          if (acceptController
                                                              .text
                                                              .isNotEmpty) {
                                                            progress!.show();

                                                            String? message = await getIt<
                                                                    TransactionManager>()
                                                                .changeInvoiceStatus(
                                                                    invoiceId,
                                                                    "Confirmed",
                                                                    index,
                                                                    fullDetails,
                                                                    timeStamp,
                                                                    userConsentGiven,
                                                                    acceptController
                                                                        .text,
                                                                    "This invoice has been confirmed and Xuriti and its financing partner is authorised to disburse funds to the seller as per the invoice generated on my behalf");
                                                            progress.dismiss();
                                                            ScaffoldMessenger
                                                                    .of(context)
                                                                .showSnackBar(
                                                                    SnackBar(
                                                                        behavior:
                                                                            SnackBarBehavior
                                                                                .floating,
                                                                        content:
                                                                            Text(
                                                                          message!,
                                                                          style:
                                                                              const TextStyle(color: Colors.green),
                                                                        )));
                                                          } else {
                                                            Fluttertoast.showToast(
                                                                msg:
                                                                    "Please write a reason",
                                                                textColor:
                                                                    Colors.red);
                                                          }

                                                          Navigator.pop(
                                                            context,
                                                          );
                                                         
                                                            
                                                          
                                                        },
                                                        child: Container(
                                                          height: h1p * 8,
                                                          width: w10p * 7.5,
                                                          decoration: BoxDecoration(
                                                              borderRadius:
                                                                  BorderRadius
                                                                      .circular(
                                                                          6),
                                                              color: Colours
                                                                  .pumpkin),
                                                          child: const Center(
                                                              child: Text(
                                                            "Accept",
                                                            style: TextStyles
                                                                .subHeading,
                                                          )),
                                                        ),
                                                      ),
                                                    ],
                                                  ),
                                                );
                                              }),
                                            ));
                                  },
                                  child: Container(
                                    height: h1p * 9,
                                    decoration: BoxDecoration(
                                        color: Colours.successPrimary,
                                        borderRadius: BorderRadius.circular(5)),
                                    child: const Center(
                                      child: Text(
                                        "Accept",
                                        style: TextStyles.textStyle46,
                                      ),
                                    ),
                                  ),
                                ),
                              ),
                            ],
                          )
                        ],
                      ),
                    ),
                  ),
                ],
              )),
        ),
      );
    }));
  }
}

1 Answers1

0

Please try to use this code as SnackBar and decorate you want,

 ScaffoldMessenger.of(context).showSnackBar(SnackBar(
                behavior: SnackBarBehavior.floating,
                content: Text(
                  message!,
                  style: const TextStyle(color: Colors.green),
                ),
                backgroundColor: Colors.black,
                action: SnackBarAction(
                    label: "Reload",
                    onPressed: () {
                      setState(() {});
                    })));

I Hope these things are solve your issue,

Romil Mavani
  • 376
  • 6