2025-08-05 15:25:10 +07:00
|
|
|
import 'package:enaklo_pos/core/components/buttons.dart';
|
2025-08-03 12:56:13 +07:00
|
|
|
import 'package:enaklo_pos/core/components/custom_modal_dialog.dart';
|
2025-08-05 15:25:10 +07:00
|
|
|
import 'package:enaklo_pos/core/components/spaces.dart';
|
2025-08-04 13:15:03 +07:00
|
|
|
import 'package:enaklo_pos/core/extensions/build_context_ext.dart';
|
2025-08-03 12:56:13 +07:00
|
|
|
import 'package:enaklo_pos/presentation/home/bloc/outlet_loader/outlet_loader_bloc.dart';
|
2025-08-05 15:25:10 +07:00
|
|
|
import 'package:enaklo_pos/presentation/home/bloc/user_update_outlet/user_update_outlet_bloc.dart';
|
|
|
|
|
import 'package:enaklo_pos/presentation/home/models/outlet_model.dart';
|
2025-08-03 12:56:13 +07:00
|
|
|
import 'package:enaklo_pos/presentation/home/widgets/outlet_card.dart';
|
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
|
|
|
|
|
2025-08-04 13:15:03 +07:00
|
|
|
class OutletDialog extends StatefulWidget {
|
2025-08-03 12:56:13 +07:00
|
|
|
const OutletDialog({super.key});
|
|
|
|
|
|
2025-08-04 13:15:03 +07:00
|
|
|
@override
|
|
|
|
|
State<OutletDialog> createState() => _OutletDialogState();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class _OutletDialogState extends State<OutletDialog> {
|
2025-08-05 15:25:10 +07:00
|
|
|
Outlet? selectedOutlet;
|
|
|
|
|
|
|
|
|
|
void selectOutlet(Outlet outlet) {
|
|
|
|
|
setState(() {
|
|
|
|
|
if (selectedOutlet == outlet) {
|
|
|
|
|
selectedOutlet = null; // Deselect jika outlet yang sama diklik
|
|
|
|
|
} else {
|
|
|
|
|
selectedOutlet =
|
|
|
|
|
outlet; // Select outlet baru (akan mengganti selection sebelumnya)
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-04 13:15:03 +07:00
|
|
|
@override
|
|
|
|
|
void initState() {
|
|
|
|
|
super.initState();
|
|
|
|
|
context.read<OutletLoaderBloc>().add(OutletLoaderEvent.getOutlet());
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-03 12:56:13 +07:00
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
return CustomModalDialog(
|
|
|
|
|
title: 'Outlet',
|
|
|
|
|
subtitle: 'Silahkan pilih outlet',
|
2025-08-04 13:15:03 +07:00
|
|
|
minWidth: context.deviceWidth * 0.4,
|
2025-08-03 12:56:13 +07:00
|
|
|
contentPadding:
|
|
|
|
|
const EdgeInsets.symmetric(horizontal: 16.0, vertical: 24.0),
|
|
|
|
|
child: BlocBuilder<OutletLoaderBloc, OutletLoaderState>(
|
|
|
|
|
builder: (context, state) {
|
|
|
|
|
return state.maybeWhen(
|
|
|
|
|
orElse: () => Center(
|
|
|
|
|
child: Text('Error has occured'),
|
|
|
|
|
),
|
|
|
|
|
loading: () => Center(child: CircularProgressIndicator()),
|
|
|
|
|
error: (message) => Center(
|
|
|
|
|
child: Text(message),
|
|
|
|
|
),
|
|
|
|
|
loaded: (outlets) => Column(
|
2025-08-05 15:25:10 +07:00
|
|
|
children: [
|
|
|
|
|
...List.generate(
|
|
|
|
|
outlets.length,
|
|
|
|
|
(index) => GestureDetector(
|
|
|
|
|
onTap: () {
|
|
|
|
|
selectOutlet(outlets[index]);
|
|
|
|
|
},
|
|
|
|
|
child: OutletCard(
|
|
|
|
|
outlet: outlets[index],
|
|
|
|
|
isSelected: selectedOutlet == outlets[index],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
SpaceHeight(24),
|
|
|
|
|
BlocBuilder<UserUpdateOutletBloc, UserUpdateOutletState>(
|
|
|
|
|
builder: (context, state) {
|
|
|
|
|
return state.maybeWhen(
|
|
|
|
|
orElse: () => Button.filled(
|
|
|
|
|
onPressed: selectedOutlet == null
|
|
|
|
|
? null
|
|
|
|
|
: () {
|
|
|
|
|
context.read<UserUpdateOutletBloc>().add(
|
|
|
|
|
UserUpdateOutletEvent.update(
|
|
|
|
|
selectedOutlet!.id ?? ""));
|
|
|
|
|
},
|
|
|
|
|
label: 'Terapkan',
|
|
|
|
|
),
|
|
|
|
|
loading: () => Center(
|
|
|
|
|
child: CircularProgressIndicator(),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
},
|
2025-08-03 12:56:13 +07:00
|
|
|
),
|
2025-08-05 15:25:10 +07:00
|
|
|
],
|
2025-08-03 12:56:13 +07:00
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|