Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import 'package:accurate_lite/core/components/space/space_component.dart';
- import 'package:accurate_lite/core/config/router/router.dart';
- import 'package:accurate_lite/core/module/init/presentation/cubit/new_init_cubit.dart';
- import 'package:auto_route/auto_route.dart';
- import 'package:flutter/material.dart';
- import 'package:flutter_bloc/flutter_bloc.dart';
- import 'package:flutter_screenutil/flutter_screenutil.dart';
- import 'package:flutter_svg/flutter_svg.dart';
- import '../../../../core/config/theme/theme.dart';
- class MenuWidget extends StatelessWidget {
- const MenuWidget({super.key});
- @override
- Widget build(BuildContext context) {
- final _theme = Theme.of(context);
- final _listMenu = getMenuItems(context); // Fetch the menu items
- final _listCreateMenu =
- getCreateMenuItems(context); // Fetch the create menu items
- return Container(
- padding: EdgeInsets.all(kDefLeftRight),
- margin: EdgeInsets.only(bottom: 50.r),
- child: Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- mainAxisSize: MainAxisSize.min,
- children: [
- Text(
- 'Fitur Anda',
- style: _theme.textTheme.titleLarge,
- textAlign: TextAlign.start,
- ),
- SpaceComponentHeight(
- height: 20.h,
- ),
- SizedBox(
- height: 100.h,
- child: GridView.builder(
- physics: const NeverScrollableScrollPhysics(),
- gridDelegate: SliverGridDelegateWithMaxCrossAxisExtent(
- maxCrossAxisExtent: 90.r,
- ),
- itemCount: _listMenu.length,
- itemBuilder: (context, index) {
- final menuItem = _listMenu[index];
- return GestureDetector(
- onTap: () => menuItem.onTapCallback(context),
- child: Column(
- mainAxisAlignment: MainAxisAlignment.start,
- crossAxisAlignment: CrossAxisAlignment.center,
- children: [
- Padding(
- padding: EdgeInsets.all(6.r),
- child: SvgPicture.asset(menuItem.image),
- ),
- Text(
- menuItem.title,
- style: _theme.textTheme.bodyMedium,
- textAlign: TextAlign.center,
- ),
- ],
- ),
- );
- },
- ),
- ),
- Text(
- 'Buat Transaksi Baru',
- style: _theme.textTheme.titleLarge,
- textAlign: TextAlign.start,
- ),
- SpaceComponentHeight(
- height: 20.h,
- ),
- SizedBox(
- height: 100.h,
- child: GridView.builder(
- physics: const NeverScrollableScrollPhysics(),
- gridDelegate: SliverGridDelegateWithMaxCrossAxisExtent(
- maxCrossAxisExtent: 90.r,
- mainAxisExtent: 100.r,
- ),
- itemBuilder: (context, index) {
- final createMenuItem = _listCreateMenu[index];
- return GestureDetector(
- onTap: () => createMenuItem.onTapCallback(context),
- child: Column(
- mainAxisAlignment: MainAxisAlignment.start,
- crossAxisAlignment: CrossAxisAlignment.center,
- children: [
- SvgPicture.asset(
- createMenuItem.image,
- ),
- Text(
- createMenuItem.title,
- style: _theme.textTheme.bodyMedium,
- textAlign: TextAlign.center,
- ),
- ],
- ),
- );
- },
- itemCount: _listCreateMenu.length,
- ),
- ),
- ],
- ),
- );
- }
- List<MenuItem> getMenuItems(BuildContext context) {
- final activeMenu = context.read<NewInitCubit>().activeMenu;
- final menuItems = [
- MenuItem(
- image: "assets/svg/menu/ic_sales_order.svg",
- title: "Pesanan Penjualan",
- isActive: activeMenu.salesOrder ?? false,
- onTapCallback: (context) {
- context.pushRoute(SalesOrderRoute());
- },
- ),
- MenuItem(
- image: "assets/svg/menu/ic_product_stock.svg",
- title: "Stok Produk",
- isActive: activeMenu.item ?? false,
- onTapCallback: (context) {
- context.pushRoute(ProductStockListRoute());
- },
- ),
- MenuItem(
- image: "assets/svg/menu/ic_customer.svg",
- title: "Pelanggan",
- isActive: activeMenu.customer ?? false,
- onTapCallback: (context) {
- context.pushRoute(CustomerRoute());
- },
- ),
- MenuItem(
- image: "assets/svg/menu/ic_report.svg",
- title: "Laporan",
- isActive: activeMenu.report ?? false,
- onTapCallback: (context) {
- context.pushRoute(ReportListRoute());
- },
- ),
- ];
- // Filter the menu items to return only those with isActive == true
- return menuItems.where((menuItem) => menuItem.isActive).toList();
- }
- List<MenuItem> getCreateMenuItems(BuildContext context) {
- final activeMenu = context.read<NewInitCubit>().activeMenu;
- return [
- MenuItem(
- image: "assets/svg/menu/ic_create_sales_order.svg",
- title: "Pesanan Penjualan",
- isActive: activeMenu.salesOrder ?? false,
- onTapCallback: (context) {
- context.pushRoute(SalesOrderAddUpdateRoute());
- },
- ),
- ];
- }
- }
- class MenuItem {
- final String image;
- final String title;
- final bool isActive;
- final Function(BuildContext) onTapCallback;
- MenuItem({
- required this.image,
- required this.title,
- required this.isActive,
- required this.onTapCallback,
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement