97 lines
3.4 KiB
Dart
97 lines
3.4 KiB
Dart
|
|
import 'package:enaklo_pos/core/constants/colors.dart';
|
||
|
|
import 'package:enaklo_pos/data/models/response/customer_response_model.dart';
|
||
|
|
import 'package:enaklo_pos/presentation/customer/bloc/customer_loader/customer_loader_bloc.dart';
|
||
|
|
import 'package:enaklo_pos/presentation/customer/widgets/customer_card.dart';
|
||
|
|
import 'package:enaklo_pos/presentation/customer/widgets/customer_title.dart';
|
||
|
|
import 'package:flutter/material.dart';
|
||
|
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||
|
|
|
||
|
|
class CustomerPage extends StatefulWidget {
|
||
|
|
const CustomerPage({super.key});
|
||
|
|
|
||
|
|
@override
|
||
|
|
State<CustomerPage> createState() => _CustomerPageState();
|
||
|
|
}
|
||
|
|
|
||
|
|
class _CustomerPageState extends State<CustomerPage> {
|
||
|
|
Customer? _customer;
|
||
|
|
@override
|
||
|
|
void initState() {
|
||
|
|
super.initState();
|
||
|
|
context
|
||
|
|
.read<CustomerLoaderBloc>()
|
||
|
|
.add(const CustomerLoaderEvent.getCustomer());
|
||
|
|
}
|
||
|
|
|
||
|
|
@override
|
||
|
|
Widget build(BuildContext context) {
|
||
|
|
return SafeArea(
|
||
|
|
child: Scaffold(
|
||
|
|
backgroundColor: AppColors.background,
|
||
|
|
body: Row(
|
||
|
|
children: [
|
||
|
|
Expanded(
|
||
|
|
flex: 2,
|
||
|
|
child: Material(
|
||
|
|
color: AppColors.white,
|
||
|
|
child: Column(
|
||
|
|
children: [
|
||
|
|
CustomerTitle(
|
||
|
|
title: 'Daftar Pelanggan',
|
||
|
|
onChanged: (value) {},
|
||
|
|
),
|
||
|
|
Expanded(
|
||
|
|
child:
|
||
|
|
BlocBuilder<CustomerLoaderBloc, CustomerLoaderState>(
|
||
|
|
builder: (context, state) {
|
||
|
|
return state.maybeWhen(
|
||
|
|
orElse: () => Center(
|
||
|
|
child: CircularProgressIndicator(),
|
||
|
|
),
|
||
|
|
loading: () => Center(
|
||
|
|
child: CircularProgressIndicator(),
|
||
|
|
),
|
||
|
|
error: (message) => Center(
|
||
|
|
child: Text(
|
||
|
|
message,
|
||
|
|
style: TextStyle(
|
||
|
|
fontSize: 16.0,
|
||
|
|
fontWeight: FontWeight.bold,
|
||
|
|
),
|
||
|
|
),
|
||
|
|
),
|
||
|
|
loaded: (customers, totalCustomer) =>
|
||
|
|
ListView.builder(
|
||
|
|
itemCount: customers.length,
|
||
|
|
itemBuilder: (context, index) {
|
||
|
|
final customer = customers[index];
|
||
|
|
return CustomerCard(
|
||
|
|
customer: customer,
|
||
|
|
isActive: customer == _customer,
|
||
|
|
onTap: () {
|
||
|
|
setState(() {
|
||
|
|
_customer = customer;
|
||
|
|
});
|
||
|
|
},
|
||
|
|
);
|
||
|
|
},
|
||
|
|
),
|
||
|
|
);
|
||
|
|
},
|
||
|
|
),
|
||
|
|
),
|
||
|
|
],
|
||
|
|
),
|
||
|
|
),
|
||
|
|
),
|
||
|
|
Expanded(
|
||
|
|
flex: 4,
|
||
|
|
child: Container(),
|
||
|
|
),
|
||
|
|
],
|
||
|
|
),
|
||
|
|
),
|
||
|
|
);
|
||
|
|
}
|
||
|
|
}
|