Untitled
unknown
plain_text
4 months ago
6.0 kB
8
Indexable
import 'package:reservation/models/materials.dart';
import 'package:reservation/pages/customers/reservation/create_reservation/create_reservation_ctrl.dart';
import 'package:reservation/utils/my_import.dart';
import 'package:reservation/widgets/buttons/button_submit.dart';
import '../../../../../providers/common_data.dart';
class MaterialReservationComponent extends StatefulWidget {
const MaterialReservationComponent({Key? key}) : super(key: key);
@override
State<MaterialReservationComponent> createState() =>
_MaterialReservationComponentState();
}
class _MaterialReservationComponentState
extends State<MaterialReservationComponent>
with TickerProviderStateMixin<MaterialReservationComponent> {
final controller = Get.put(ReservationController());
@override
Widget build(BuildContext context) {
return Obx(() {
return Column(
children: [
Padding(
padding: const EdgeInsets.all(8.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
controller.materialList.length > 0 ||
controller.materialList != []
? _buildListMaterials()
: Container(),
_buildSelectedMaterialItem(context),
// Round Trip checkbox — hanya untuk isAutoAssignNearest
if (controller.isAutoAssignNearest.value == true)
_buildRoundTripCheckbox(),
],
),
),
],
);
});
}
Widget _buildListMaterials() {
return ListView.builder(
shrinkWrap: true,
physics: NeverScrollableScrollPhysics(),
itemBuilder: (BuildContext context, index) {
return _buildMaterialItem(controller.materialList[index], index);
},
itemCount: controller.materialList.length,
);
}
Widget _buildMaterialItem(Materials? materialList, int index) {
return Card(
shape: RoundedRectangleBorder(
side: new BorderSide(color: Colors.grey, width: 0.2),
borderRadius: BorderRadius.circular(10.0),
),
child: Container(
decoration: BoxDecoration(
// color: Colors.red,
borderRadius: BorderRadius.circular(10.0),
),
child: Padding(
padding: EdgeInsets.all(10),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Expanded(
child: Container(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
padding: EdgeInsets.all(8.0),
child: Text(
materialList?.name ?? "-",
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.bold,
),
),
),
// Container(
// padding: EdgeInsets.fromLTRB(8, 16, 8, 6),
// alignment: Alignment.centerLeft,
// child: Text("COUNT".tr +
// " @${materialList?.materialUnit?.name} "),
// ),
// _buildQtyPicker(index, materialList),
],
),
),
)
],
),
],
),
),
),
);
}
Widget _buildSelectedMaterialItem(BuildContext context) {
return ButtonSubmitWidget(
width: Get.width / 2.5,
textColor: Colors.white,
bgColor: Colors.blue,
title: controller.isSelected.value == true ? "CHANGE_SERVICE_TYPE".tr : "SElECT_RESERVATION".tr,
onPressed: () async {
dismissTextFieldFocus();
await showModalBottomSheet(
context: context,
isScrollControlled: true, // makes modal fullscreen
backgroundColor: Colors.transparent,
builder: (context) {
return MaterialReservationBottomSheet(
hintText: "SEARCH_RESERVATION".tr,
onPicked: () {
// controller.onMaterialPicked(materials);
setState(() {
controller.isSelected.value = true;
controller.multiTrip.clear();
controller.multiTripShuttle.clear();
controller.selectedValue.value = itemDestinationType[0].title;
// Reset round trip saat service type diganti
controller.isRoundTrip.value = false;
controller.roundTripInSiteTrips.clear();
});
});
},
);
},
loading: false,
);
}
Widget _buildRoundTripCheckbox() {
return Obx(() => CheckboxListTile(
title: Text(
"Round Trip",
style: TextStyle(fontSize: 14),
),
value: controller.isRoundTrip.value,
onChanged: (val) {
controller.isRoundTrip.value = val ?? false;
if (!(val ?? false)) {
// Reset round trip fields jika uncheck
controller.roundTripInSiteTrips.clear();
}
},
controlAffinity: ListTileControlAffinity.leading,
contentPadding: EdgeInsets.symmetric(horizontal: 0),
dense: true,
));
}
}
Editor is loading...
Leave a Comment