Skip to content

Commit

Permalink
chore(recipients_app): Enable copy paste for OTP input (#597)
Browse files Browse the repository at this point in the history
* Adding mechanism to fix copy paste behaviour for otp input

* Bump version

* Add default value for phone param

* Bump version
  • Loading branch information
MDikkii authored Nov 4, 2023
1 parent 73ad16c commit a038fbd
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 4 deletions.
2 changes: 1 addition & 1 deletion recipients_app/lib/data/models/phone.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ part "phone.g.dart";

@JsonSerializable()
class Phone extends Equatable {
@JsonKey(name: "phone")
@JsonKey(name: "phone", defaultValue: 0)
final int phoneNumber;

const Phone(this.phoneNumber);
Expand Down
2 changes: 1 addition & 1 deletion recipients_app/lib/data/models/phone.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions recipients_app/lib/view/widgets/welcome/otp_input.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,24 @@ class _OtpInputState extends State<OtpInput> {
digit4Controller = TextEditingController();
digit5Controller = TextEditingController();
digit6Controller = TextEditingController();

final controllers = [
digit1Controller,
digit2Controller,
digit3Controller,
digit4Controller,
digit5Controller,
digit6Controller,
];

digit1Controller.addListener(() {
final text = digit1Controller.text;
if (text.length > 1) {
for (int i = 0; i < text.length; i++) {
controllers[i].text = text[i];
}
}
});
}

@override
Expand Down Expand Up @@ -54,6 +72,7 @@ class _OtpInputState extends State<OtpInput> {
}
_checkCodeStatus();
},
isFirstField: true,
),
OtpInputField(
controller: digit2Controller,
Expand Down
4 changes: 3 additions & 1 deletion recipients_app/lib/view/widgets/welcome/otp_input_field.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ import "package:flutter/material.dart";
class OtpInputField extends StatelessWidget {
final TextEditingController? controller;
final Function(String?)? onChanged;
final bool isFirstField;

const OtpInputField({
super.key,
this.controller,
this.onChanged,
this.isFirstField = false,
});

@override
Expand Down Expand Up @@ -43,7 +45,7 @@ class OtpInputField extends StatelessWidget {
validator: null,
textAlign: TextAlign.center,
keyboardType: TextInputType.number,
maxLength: 1,
maxLength: isFirstField ? 6 : 1,
),
),
),
Expand Down
2 changes: 1 addition & 1 deletion recipients_app/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: app
description: Social Income App

publish_to: "none"
version: 1.1.8+20
version: 1.1.8+22

environment:
sdk: ">=3.1.0 <4.0.0"
Expand Down

0 comments on commit a038fbd

Please sign in to comment.