Skip to content

Commit

Permalink
fix : fixing submit button review validation
Browse files Browse the repository at this point in the history
  • Loading branch information
crosbydoo committed Feb 17, 2024
1 parent be58807 commit e34edfc
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 12 deletions.
2 changes: 1 addition & 1 deletion ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,4 @@ SPEC CHECKSUMS:

PODFILE CHECKSUM: f567b6369f8842e77ccf6611a4baf3e2181f3f05

COCOAPODS: 1.13.0
COCOAPODS: 1.15.2
18 changes: 7 additions & 11 deletions lib/resources/widgets/common_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,44 +5,42 @@ class CommonButton extends StatelessWidget {
final String text;
final VoidCallback onPressed;
final bool outlined;
final bool disabled; // New property for button disabled state
final bool disabled;

const CommonButton({
Key? key,
required this.text,
required this.onPressed,
this.outlined = false,
this.disabled = false, // Default value is false (button is enabled)
this.disabled = false,
});

factory CommonButton.normalButton({
Key? key,
required String text,
required VoidCallback onPressed,
bool disabled = false, // New parameter with default value
bool disabled = false,
}) {
return CommonButton(
key: key,
text: text,
onPressed: onPressed,
disabled:
disabled, // Assign the disabled parameter to the disabled property
disabled: disabled,
);
}

factory CommonButton.outlinedButton({
Key? key,
required String text,
required VoidCallback onPressed,
bool disabled = false, // New parameter with default value
bool disabled = false,
}) {
return CommonButton(
key: key,
text: text,
onPressed: onPressed,
outlined: true,
disabled:
disabled, // Assign the disabled parameter to the disabled property
disabled: disabled,
);
}

Expand All @@ -51,9 +49,7 @@ class CommonButton extends StatelessWidget {
return SizedBox(
width: double.infinity,
child: ElevatedButton(
onPressed: disabled
? null
: onPressed, // Disable the button if disabled is true
onPressed: disabled ? null : onPressed,
style: ElevatedButton.styleFrom(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(16),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class _FormReviewComponentState extends State<FormReviewComponent> {

final _formKey = GlobalKey<FormState>();
late RestaurantBloc bloc;
bool isSubmitDisabled = true;

@override
void initState() {
Expand All @@ -32,9 +33,17 @@ class _FormReviewComponentState extends State<FormReviewComponent> {
usecase: GetIt.instance(),
reviewUsecase: GetIt.instance(),
);
nameInput.addListener(updateSubmitButton);
reviewInput.addListener(updateSubmitButton);
super.initState();
}

void updateSubmitButton() {
setState(() {
isSubmitDisabled = nameInput.text.isEmpty || reviewInput.text.isEmpty;
});
}

@override
Widget build(BuildContext context) {
return Container(
Expand Down Expand Up @@ -83,6 +92,7 @@ class _FormReviewComponentState extends State<FormReviewComponent> {
context.pop(true);
}
},
disabled: isSubmitDisabled,
text: 'Submit',
),
)
Expand Down

0 comments on commit e34edfc

Please sign in to comment.