feat: setting page and setting product page
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
import 'package:enaklo_pos/core/components/buttons.dart';
|
||||
import 'package:enaklo_pos/core/constants/colors.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:enaklo_pos/data/datasources/product_remote_datasource.dart';
|
||||
@@ -27,40 +29,68 @@ class _ProductPageState extends State<ProductPage> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
body: ListView(
|
||||
padding: const EdgeInsets.all(24.0),
|
||||
backgroundColor: AppColors.background,
|
||||
body: Column(
|
||||
children: [
|
||||
const SettingsTitle('Manage Products'),
|
||||
const SizedBox(height: 24),
|
||||
BlocBuilder<GetProductsBloc, GetProductsState>(
|
||||
builder: (context, state) {
|
||||
return state.maybeWhen(orElse: () {
|
||||
return const Center(
|
||||
child: CircularProgressIndicator(),
|
||||
);
|
||||
}, success: (products) {
|
||||
return GridView.builder(
|
||||
padding: EdgeInsets.zero,
|
||||
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
|
||||
childAspectRatio: 1,
|
||||
crossAxisCount: 3,
|
||||
mainAxisSpacing: 12,
|
||||
crossAxisSpacing: 12,
|
||||
),
|
||||
itemCount: products.length + 1,
|
||||
shrinkWrap: true,
|
||||
physics: const ScrollPhysics(),
|
||||
itemBuilder: (BuildContext context, int index) {
|
||||
if (index == 0) {
|
||||
return AddData(
|
||||
title: 'Add New Product',
|
||||
onPressed: () {
|
||||
SettingsTitle(
|
||||
'Kelola Produk',
|
||||
subtitle: 'Kelola produk anda',
|
||||
actionWidget: [
|
||||
Button.outlined(
|
||||
onPressed: () {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) => MultiBlocProvider(
|
||||
providers: [
|
||||
BlocProvider(
|
||||
create: (context) =>
|
||||
AddProductBloc(ProductRemoteDatasource()),
|
||||
),
|
||||
BlocProvider.value(
|
||||
value: context.read<SyncProductBloc>(),
|
||||
),
|
||||
BlocProvider.value(
|
||||
value: context.read<GetProductsBloc>(),
|
||||
),
|
||||
],
|
||||
child: const FormProductDialog(),
|
||||
),
|
||||
);
|
||||
},
|
||||
label: "Tambah Produk",
|
||||
icon: Icon(Icons.add, color: AppColors.primary),
|
||||
)
|
||||
],
|
||||
),
|
||||
Expanded(
|
||||
child: BlocBuilder<GetProductsBloc, GetProductsState>(
|
||||
builder: (context, state) {
|
||||
return state.maybeWhen(orElse: () {
|
||||
return const Center(
|
||||
child: CircularProgressIndicator(),
|
||||
);
|
||||
}, success: (products) {
|
||||
return GridView.builder(
|
||||
padding: EdgeInsets.all(16),
|
||||
gridDelegate: SliverGridDelegateWithMaxCrossAxisExtent(
|
||||
maxCrossAxisExtent: 200,
|
||||
mainAxisSpacing: 30,
|
||||
crossAxisSpacing: 30,
|
||||
childAspectRatio: 0.85,
|
||||
),
|
||||
itemCount: products.length,
|
||||
itemBuilder: (BuildContext context, int index) {
|
||||
final item = products[index];
|
||||
return MenuProductItem(
|
||||
data: item,
|
||||
onTapEdit: () {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) => MultiBlocProvider(
|
||||
providers: [
|
||||
BlocProvider(
|
||||
create: (context) => AddProductBloc(ProductRemoteDatasource()),
|
||||
create: (context) => UpdateProductBloc(
|
||||
ProductRemoteDatasource()),
|
||||
),
|
||||
BlocProvider.value(
|
||||
value: context.read<SyncProductBloc>(),
|
||||
@@ -69,39 +99,16 @@ class _ProductPageState extends State<ProductPage> {
|
||||
value: context.read<GetProductsBloc>(),
|
||||
),
|
||||
],
|
||||
child: const FormProductDialog(),
|
||||
child: FormProductDialog(product: item),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
final item = products[index - 1];
|
||||
return MenuProductItem(
|
||||
data: item,
|
||||
onTapEdit: () {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) => MultiBlocProvider(
|
||||
providers: [
|
||||
BlocProvider(
|
||||
create: (context) => UpdateProductBloc(ProductRemoteDatasource()),
|
||||
),
|
||||
BlocProvider.value(
|
||||
value: context.read<SyncProductBloc>(),
|
||||
),
|
||||
BlocProvider.value(
|
||||
value: context.read<GetProductsBloc>(),
|
||||
),
|
||||
],
|
||||
child: FormProductDialog(product: item),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
});
|
||||
},
|
||||
},
|
||||
);
|
||||
});
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user