diff --git a/lib/views/widgets/bottom_sheets/rejection_reason_bottom_sheet.dart b/lib/views/widgets/bottom_sheets/rejection_reason_bottom_sheet.dart index 0e3c0f5e..72f57261 100644 --- a/lib/views/widgets/bottom_sheets/rejection_reason_bottom_sheet.dart +++ b/lib/views/widgets/bottom_sheets/rejection_reason_bottom_sheet.dart @@ -9,19 +9,36 @@ import 'package:test_sa/new_views/common_widgets/app_text_form_field.dart'; import 'package:test_sa/new_views/common_widgets/single_item_drop_down_menu.dart'; import 'package:test_sa/providers/service_request_providers/reject_reason_provider.dart'; -class RejectionReasonBottomSheet extends StatelessWidget { +class RejectionReasonBottomSheet extends StatefulWidget { final Future Function(int reasonId, String comment) onRejectPressed; final VoidCallback? onRefreshed; - RejectionReasonBottomSheet({Key? key, this.onRefreshed, required this.onRejectPressed}) : super(key: key); + const RejectionReasonBottomSheet({Key? key, this.onRefreshed, required this.onRejectPressed}) : super(key: key); @override - Widget build(BuildContext context) { - TextEditingController _commentController = TextEditingController(); - final GlobalKey _formKey = GlobalKey(); + State createState() => _RejectionReasonBottomSheetState(); +} + +class _RejectionReasonBottomSheetState extends State { + late TextEditingController _commentController; + late GlobalKey _formKey; + Lookup? selectedReason; + + @override + void initState() { + super.initState(); + _commentController = TextEditingController(); + _formKey = GlobalKey(); + } - Lookup? selectedReason; + @override + void dispose() { + _commentController.dispose(); + super.dispose(); + } + @override + Widget build(BuildContext context) { return Form( key: _formKey, child: Column( @@ -67,11 +84,11 @@ class RejectionReasonBottomSheet extends StatelessWidget { if (_formKey.currentState!.validate()) { _formKey.currentState!.save(); Utils.showLoading(context); - bool isSuccess = await onRejectPressed(selectedReason!.id!, _commentController.text); + bool isSuccess = await widget.onRejectPressed(selectedReason!.id!, _commentController.text); Utils.hideLoading(context); if (isSuccess) { Navigator.of(context).pop(); - onRefreshed?.call(); + widget.onRefreshed?.call(); } } },