class OtpScreen extends StatefulWidget {
const OtpScreen({Key? key}) : super(key: key);
@override
State<OtpScreen> createState() => _OtpScreenState();
}
class _OtpScreenState extends State<OtpScreen> {
late String otp1;
late String otp2;
late String otp3;
late String otp4;
late String otp5;
late String otp6;
late OtpModel _futureotp;
final _formKey = GlobalKey<FormState>();
late TextEditingController controller;
@override
void initState() {
controller = TextEditingController();
controller.addListener(() {
_onChanged();
});
super.initState();
}
@override
void dispose() {
controller.dispose();
super.dispose();
}
void _onChanged() {
try {
dynamic sendotp = ApiHelper().otpValidation();
if (sendotp is OtpModel) {
setState(() {
_futureotp = sendotp;
});
}
if (sendotp.status == 'success') {
Routes.sailor.navigate(
'/signIn',
navigationType: NavigationType.pushAndRemoveUntil,
removeUntilPredicate: (routes) => false,
transitions: [SailorTransition.fade_in],
);
} else {
print(sendotp.message);
}
} catch (e) {
print(e);
}
}
[1
I'm trying to create an OTP screen with textformfield and I have 6 TextEditingControllers but I want to send the value I get from them as one controller. How can I do that? and How would you do it if you were to create an otp screen that sends data to the backend without a button?
p.s: I tried creating 6 controllers and putting an adlistener at the last controller.