Untitled

mail@pastecode.io avatar
unknown
plain_text
12 days ago
9.0 kB
3
Indexable
Never
// ignore_for_file: use_named_constants, avoid_bool_literals_in_conditional_expressions

import '../../../utils/base_import.dart';
import '../../views/widgets/billing_items.dart';
import '../blocs/billing_bloc.dart';
import '../repositories/models/to_do_list_model.dart';

class Billing extends StatefulWidget {
  const Billing({super.key});

  @override
  State<Billing> createState() => _BillingState();
}

class _BillingState extends State<Billing> {
  @override
  void initState() {
    context.read<BillingBloc>().add(GetToDoList(
          // partnerId: getHive(key: "extCode"),
          partnerId: "10011",
          status: "0",
        ));
    super.initState();
  }

  @override
  void dispose() {
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    final Size size = MediaQuery.of(context).size;
    final NumberFormat formatter = NumberFormat('#,###,000');

    return Scaffold(
      body: SizedBox(
        width: size.width,
        height: size.height,
        child: CustomScrollView(
          slivers: <Widget>[
            SliverAppBar(
              shadowColor: Colors.transparent,
              backgroundColor: whiteColor,
              foregroundColor: whiteColor,
              surfaceTintColor: whiteColor,
              flexibleSpace: header(size),
              floating: true,
              pinned: false,
              elevation: 0,
              expandedHeight: 80,
              automaticallyImplyLeading: false,
            ),
            SliverToBoxAdapter(
              child: Column(
                children: <Widget>[
                  Padding(
                    padding: const EdgeInsets.symmetric(horizontal: 20),
                    child: SizedBox(
                      width: size.width,
                      child: Text(
                        "To Do List Penagihan",
                        style: boldInterTextStyle.copyWith(
                            height: 1,
                            fontSize: 15,
                            fontWeight: FontWeight.w800),
                      ),
                    ),
                  ),
                  const Gap(20),
                  BlocBuilder<BillingBloc, BillingState>(
                    builder: (BuildContext context, BillingState state) {
                      if (state is BillingDataLoading) {
                        return const Column(
                          children: <Widget>[
                            Gap(100),
                            Center(child: CircularProgressIndicator()),
                          ],
                        );
                      } else if (state is BillingLoaded) {
                        return state.items.isNotEmpty
                            ? ListView.builder(
                                itemCount: state.items.length,
                                scrollDirection: Axis.vertical,
                                padding: const EdgeInsets.only(top: 0),
                                shrinkWrap: true,
                                physics: const NeverScrollableScrollPhysics(),
                                itemBuilder: (BuildContext context, int index) {
                                  final ToDoListModel item = state.items[index];
                                  return Padding(
                                    padding: const EdgeInsets.symmetric(
                                        horizontal: 20, vertical: 5),
                                    child: BillingItemsWisget(
                                      size: size,
                                      name: item.customerName!,
                                      number: item.contractNo,
                                      address: item.addressColc!,
                                      price:
                                          "Rp ${formatter.format(item.amountTagihan)}",
                                      isBadge: item.statusDesc != null
                                          ? item.statusDesc == "Janji Bayar"
                                              ? true
                                              : false
                                          : false,
                                      colorStatus: item.statusDesc != null
                                          ? item.statusDesc! == "Janji Bayar"
                                              ? statusWaiting
                                              : null
                                          : null,
                                      colorTxtStatus: item.statusDesc != null
                                          ? item.statusDesc! == "Janji Bayar"
                                              ? primaryOrangeColor
                                              : null
                                          : null,
                                      titleStatus: item.statusDesc,
                                      onPressed: () {
                                        context.router.push(DetailBilling(
                                            contractNo: item.contractNo!,
                                            status: item.statusDesc ?? "string",
                                            branchId: item.branchId!,
                                            todoListId: item.todoListId!));
                                      },
                                    ),
                                  );
                                },
                              )
                            : Column(
                                mainAxisAlignment: MainAxisAlignment.center,
                                crossAxisAlignment: CrossAxisAlignment.center,
                                children: <Widget>[
                                  const Gap(50),
                                  SvgPicture.asset(
                                    "assets/images/empty.svg",
                                    width: 300,
                                    height: 150,
                                  ),
                                  Text(
                                    "Tidak Ada Data",
                                    style: boldInterTextStyle.copyWith(
                                        fontSize: 13, height: 1),
                                  ),
                                ],
                              );
                      } else if (state is BillingDataError) {
                        return Column(
                          mainAxisAlignment: MainAxisAlignment.center,
                          crossAxisAlignment: CrossAxisAlignment.center,
                          children: <Widget>[
                            const Gap(50),
                            SvgPicture.asset(
                              "assets/images/empty.svg",
                              width: 300,
                              height: 150,
                            ),
                            Text(
                              "Data Tidak Ditemukan",
                              style: boldInterTextStyle.copyWith(
                                  fontSize: 13, height: 1),
                            ),
                            const Gap(10),
                            Text(
                              "Mohon periksa kembali koneksi anda",
                              style: interTextStyle.copyWith(
                                  fontSize: 11, height: 1),
                            )
                          ],
                        );
                      }
                      return Container();
                    },
                  ),
                ],
              ),
            )
          ],
        ),
      ),
    );
  }

  Container header(Size size) {
    return Container(
      width: size.width,
      height: 100,
      decoration: const BoxDecoration(
          image: DecorationImage(
              image: AssetImage("assets/images/bagan-melingkar.png"),
              fit: BoxFit.cover)),
      child: Padding(
        padding: const EdgeInsets.symmetric(horizontal: 20),
        child: Row(
          children: <Widget>[
            SvgPicture.asset(
              "assets/images/logo_one_ex_orange.svg",
              width: 71,
              height: 22,
            ),
            const Spacer(),
            InkWell(
              onTap: () {
                context.router.replace(const HomeRoute());
              },
              child: Container(
                width: 40,
                height: 40,
                decoration: BoxDecoration(
                  border: Border.all(width: 1, color: greyColor2),
                  borderRadius: BorderRadius.circular(8),
                ),
                child: Padding(
                  padding: const EdgeInsets.all(8),
                  child: SvgPicture.asset(
                    "assets/icons/home.svg",
                  ),
                ),
              ),
            )
          ],
        ),
      ),
    );
  }
}
Leave a Comment