incomme_flutter_commerce 0.0.6 copy "incomme_flutter_commerce: ^0.0.6" to clipboard
incomme_flutter_commerce: ^0.0.6 copied to clipboard

A Incomme SDK applications

example/lib/main.dart

// ignore_for_file: use_build_context_synchronously

import 'package:flutter/material.dart';
import 'package:incomme_flutter_commerce/components/upper_snackbar.dart';
import 'package:incomme_flutter_commerce/domain/entity/wishlist/wishlist.dart';
import 'package:incomme_flutter_commerce/extensions/extended_navigator.dart';
import 'package:incomme_flutter_commerce/incomme_plugin.dart';
import 'package:incomme_flutter_commerce/package/income_widget.dart';
import 'package:incomme_flutter_commerce/presentation/home/scanner/incomme_scanner.dart';
import 'package:incomme_flutter_commerce/presentation/home/widgets/incomme_home_category_event_collection.dart';
import 'package:incomme_flutter_commerce/presentation/product/product_args/product_detail_arg.dart';
import 'package:incomme_flutter_commerce/presentation/promo_voucher/incomme_promo_voucher.dart';
import 'package:incomme_flutter_commerce/presentation/wishlist/wishlist_sdk.dart';

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await Incomme().initialize(
    IncommeConfig(
      sdkKey: "j6bY1IGi0C5s7iksVRmCg1Gm4hO+CemwQvij1xVls5k=",
      langCur: IncommeLangCurr.idIDR,
      merchantId: "35ce0773-a226-11ef-a82a-f23c955fa867",
      merchantName: "PT.Indivara-sejahtera-mandiri",
      userEmail: "testing.incomme@walkthrough.com",
      userFullName: 'Testing Incomme',
      userPhoneNumber: "081234567891",
      themeColor: "#045A9D",
      fontFamily: IncommeFont.poppins,
      appLogo: "https://brand.com/logo.png",
    ),
    onError: (e) {
      debugPrint(e.success.toString());
    },
  );
  IncommeHome.initialize();
  runApp(const MyApp());
}

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

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  @override
  void initState() {
    super.initState();
    // getNotif();
  }

  // void getNotif() async {
  //   await IncommeNotification.getNotifications();
  // }

  @override
  Widget build(BuildContext context) {
    return IncommeMaterialApp(
      home: Scaffold(
        appBar: AppBar(title: const Text('Plugin example app')),

        // body: IncommePaymentConfirmation(
        //   orderGroupID: "ECOMM_ID_25050300001",
        //   paymentResult:
        //       CheckoutPaymentDto.fromJson(
        //         ResultPaymentDummy.checkoutPayment,
        //       ).jsonResult,
        // ),
        // body: WishlistExample(),
        body: IncommeWidget(
          child: SingleChildScrollView(
            child: Column(
              children: [
                HomeSection(),
                HomeDeliverySection(),
                HomeCategorySection(),
                IncommeHomeCategoryEventCollection(),
              ],
            ),
          ),
        ),
      ),
      // !359 "Tulis Review" page
      // body: IncommeWriteReviewProduct(
      //   orderGroupID: "ORDER_GROUP_1",
      //   orderId: 1,
      //   orderItems:
      //       SummaryReceiptDto.map(ReceiptDummy.summaryReceiptDummy)
      //           .jsonObject
      //           .orders
      //           .mapMany((e) => e.orderDeliveries)
      //           .mapMany((e) => e.orderItems)
      //           .toList(),
      //   onItemTap: (item, orderGroupID, orderId, skuId) {
      //     //
      //   },
      // ),
      // !359 "write review bottom sheet" (step 1)
      // body: IncommeMyReviewProductList(
      //   product: ProductDetailDto.fromJson(dummyProductJson).jsonObject,
      //   onReviewProductTapped: (
      //     productId,
      //     productCode,
      //     productName,
      //     skuId,
      //     orderId,
      //   ) {
      //     // !359 "write review bottom sheet" (step 2)
      //     //! call IncommeWriteReviewForm, not directly from "main" class
      //   },
      // ),
      // )
    );
  }
}

class WishlistExample extends StatelessWidget {
  const WishlistExample({super.key});

  @override
  Widget build(BuildContext context) {
    return Center(
      child: ElevatedButton(
        onPressed: () {
          IncommeWishlistFunction.addWishlist(
            CustomerWishlist(
              customerWishListID: 76,
              customerWishlistName: '',
              skuID: 1377,
              branchID: 10001,
              deliveryMethod: 0,
            ),
          ).then((_) {
            Navigator.push(
              context,
              MaterialPageRoute(
                builder: (_) {
                  return IncommeWishlist();
                },
              ),
            );
          });
        },
        child: Text("TES WISHLIST"),
      ),
    );
  }
}

class HomeSection extends StatelessWidget {
  const HomeSection({super.key});

  @override
  Widget build(BuildContext context) {
    return IncommeHomeHeader(
      brandName: 'Brand Name',
      onSearchTap: () {
        context.to(
          IncommeSearchProduct(
            onTapProduct: (data) {
              Get.to(IncommeProductDetail(
                productArg: ProductDetailArgs(code: data.code),
                onTapCart: () {
                  Get.to(IncommeCart(
                    onCheckout: () {
                      Get.to(IncommeCheckout(
                        onCheckoutPay: (orderGroupId) {
                          Get.to(
                              IncommePaymentMethod(orderGroupID: orderGroupId));
                        },
                      ));
                    },
                  ));
                },
              ));
            },
            onTapOffers: (data) {
              showDTSnackBarError(context, data.rewardName);
            },
          ),
        );
      },
      onTapNotification: () {
        Navigator.push(
          context,
          MaterialPageRoute(
            builder: (context) {
              return IncommeWishlist();
            },
          ),
        );
      },
      onTapChangeStore: () async {
        Navigator.push(
          context,
          MaterialPageRoute(
            builder: (context) {
              return IncommeChangeStore();
            },
          ),
        );
      },
      onScanProductsCam: () {
        Navigator.push(
          context,
          MaterialPageRoute(
            builder: (context) {
              return IncommeScanner();
            },
          ),
        );
      },
    );
  }
}

class HomeCategorySection extends StatelessWidget {
  const HomeCategorySection({super.key});

  @override
  Widget build(BuildContext context) {
    return IncommeHomeCategory(
      onTapShopByCategory: () {
        Navigator.push(
          context,
          MaterialPageRoute(
            builder: (_) {
              return IncommeProductDetail(
                productArg: ProductDetailArgs(code: '10002-1000000004362'),
                onAddToCart: (_) {},
                onShareProduct: (_) {},
                onWishListProduct: (_) {},
                onTapReview: (_) {},
                onTapChangeStore: () {},
              );
            },
          ),
        );
      },
      onTapRamblaOffers: () {
        Navigator.push(
          context,
          MaterialPageRoute(
            builder: (_) {
              return IncommePromoVoucher(
                onCouponRedeemed: (String message) {},
                onVoucherRedeemed: (String message) {},
              );
            },
          ),
        );
      },
    );
  }
}

class HomeDeliverySection extends StatelessWidget {
  const HomeDeliverySection({super.key});

  @override
  Widget build(BuildContext context) {
    return IncommeHomeDelivery(

        // onTapPickUpInStore: () {
        //   showModalBottomSheet(
        //       shape: RoundedRectangleBorder(
        //         borderRadius: BorderRadius.vertical(
        //           top: Radius.circular(16.0),
        //         ),
        //       ),
        //       context: context,
        //       builder: (_) {
        //         return DeliverySheet(
        //           deliveryMethod: 'Pick Up In Store',
        //           body: Text('You can pick up your order at the store.'),
        //           onPressedButton: () {
        //             context.to(Scaffold(
        //               body: SafeArea(child: IncommeCategoryEventCollection()),
        //             ));
        //           },
        //         );
        //       });
        // },
        );
  }
}