app/lib/components/otp_body.dart

289 lines
11 KiB
Dart
Raw Normal View History

2022-05-16 02:51:47 +02:00
import 'package:lottie/lottie.dart';
2022-05-13 07:57:43 +02:00
import 'package:flutter/services.dart';
2022-05-21 12:29:48 +02:00
import 'package:flutter/material.dart';
2022-04-29 09:11:05 +02:00
2022-05-22 20:06:14 +02:00
import 'package:nekoya_flutter/api/api.dart';
import 'package:nekoya_flutter/components/menu.dart';
import 'package:nekoya_flutter/data/auth.dart';
2022-04-29 09:11:05 +02:00
class OtpBody extends StatefulWidget {
2022-05-22 20:06:14 +02:00
const OtpBody({Key? key, required this.otpToken}) : super(key: key);
final String otpToken;
2022-04-29 09:11:05 +02:00
@override
State<OtpBody> createState() => _OtpBodyState();
}
class _OtpBodyState extends State<OtpBody> {
2022-05-22 20:06:14 +02:00
TextEditingController otpCode1 = TextEditingController();
TextEditingController otpCode2 = TextEditingController();
TextEditingController otpCode3 = TextEditingController();
TextEditingController otpCode4 = TextEditingController();
TextEditingController otpCode5 = TextEditingController();
TextEditingController otpCode6 = TextEditingController();
Future submitForm(BuildContext context) async {
if (otpCode1.text.isEmpty || otpCode2.text.isEmpty || otpCode3.text.isEmpty || otpCode4.text.isEmpty || otpCode5.text.isEmpty || otpCode6.text.isEmpty) {
return 999;
} else {
Map<String, dynamic> data = {
"token": widget.otpToken,
"code": "${otpCode1.text}${otpCode2.text}${otpCode3.text}${otpCode4.text}${otpCode5.text}${otpCode6.text}"
};
var response = await otpPost(data);
return {'statusCode': response['statusCode'], 'data': response['data']};
}
}
2022-04-29 09:11:05 +02:00
@override
Widget build(BuildContext context) {
2022-05-13 07:57:43 +02:00
return Container(
padding: const EdgeInsets.all(25),
child: ListView(children: [
Container(
2022-05-16 02:53:52 +02:00
child: Lottie.asset('assets/lottie/otp.json'),
2022-05-13 07:57:43 +02:00
),
Container(
2022-05-14 18:44:03 +02:00
padding: const EdgeInsets.only(top: 15),
child: const Text(
2022-05-15 21:10:37 +02:00
'Check your Telegram app for 2FA code',
2022-05-13 07:57:43 +02:00
textAlign: TextAlign.center,
style: TextStyle(fontSize: 15, color: Colors.white),
),
),
Form(
child: Container(
2022-05-14 18:44:03 +02:00
padding: const EdgeInsets.only(top: 15),
2022-05-13 07:57:43 +02:00
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Container(
decoration: BoxDecoration(
border: Border.all(color: Colors.white),
),
child: SizedBox(
height: 50,
width: 50,
child: TextFormField(
2022-05-22 20:06:14 +02:00
controller: otpCode1,
2022-05-13 07:57:43 +02:00
onChanged: (value) {
if (value.length == 1) {
FocusScope.of(context).nextFocus();
2022-05-14 18:44:03 +02:00
} else if (value.isEmpty) {
2022-05-13 07:57:43 +02:00
FocusScope.of(context).previousFocus();
}
},
onSaved: (pin1) {},
2022-05-14 18:44:03 +02:00
decoration: const InputDecoration(
2022-05-15 21:10:37 +02:00
hintText: "",
2022-05-13 07:57:43 +02:00
focusColor: Colors.white,
hintStyle: TextStyle(color: Colors.white),
),
textAlign: TextAlign.center,
2022-05-14 18:44:03 +02:00
style: const TextStyle(color: Colors.white),
2022-05-13 07:57:43 +02:00
keyboardType: TextInputType.number,
inputFormatters: [
LengthLimitingTextInputFormatter(1),
FilteringTextInputFormatter.digitsOnly,
],
),
),
),
Container(
decoration: BoxDecoration(
border: Border.all(color: Colors.white),
),
child: SizedBox(
height: 50,
width: 50,
child: TextFormField(
2022-05-22 20:06:14 +02:00
controller: otpCode2,
2022-05-13 07:57:43 +02:00
onChanged: (value) {
if (value.length == 1) {
FocusScope.of(context).nextFocus();
2022-05-14 18:44:03 +02:00
} else if (value.isEmpty) {
2022-05-13 07:57:43 +02:00
FocusScope.of(context).previousFocus();
}
},
onSaved: (pin1) {},
2022-05-14 18:44:03 +02:00
decoration: const InputDecoration(
2022-05-15 21:10:37 +02:00
hintText: "",
2022-05-13 07:57:43 +02:00
focusColor: Colors.white,
hintStyle: TextStyle(color: Colors.white),
),
textAlign: TextAlign.center,
2022-05-14 18:44:03 +02:00
style: const TextStyle(color: Colors.white),
2022-05-13 07:57:43 +02:00
keyboardType: TextInputType.number,
inputFormatters: [
LengthLimitingTextInputFormatter(1),
FilteringTextInputFormatter.digitsOnly,
],
),
),
),
Container(
decoration: BoxDecoration(
border: Border.all(color: Colors.white),
),
child: SizedBox(
height: 50,
width: 50,
child: TextFormField(
2022-05-22 20:06:14 +02:00
controller: otpCode3,
2022-05-13 07:57:43 +02:00
onChanged: (value) {
if (value.length == 1) {
FocusScope.of(context).nextFocus();
2022-05-14 18:44:03 +02:00
} else if (value.isEmpty) {
2022-05-13 07:57:43 +02:00
FocusScope.of(context).previousFocus();
}
},
onSaved: (pin1) {},
2022-05-14 18:44:03 +02:00
decoration: const InputDecoration(
2022-05-15 21:10:37 +02:00
hintText: "",
2022-05-13 07:57:43 +02:00
focusColor: Colors.white,
hintStyle: TextStyle(color: Colors.white),
),
textAlign: TextAlign.center,
2022-05-14 18:44:03 +02:00
style: const TextStyle(color: Colors.white),
2022-05-13 07:57:43 +02:00
keyboardType: TextInputType.number,
inputFormatters: [
LengthLimitingTextInputFormatter(1),
FilteringTextInputFormatter.digitsOnly,
],
),
),
),
Container(
decoration: BoxDecoration(
border: Border.all(color: Colors.white),
),
child: SizedBox(
height: 50,
width: 50,
child: TextFormField(
2022-05-22 20:06:14 +02:00
controller: otpCode4,
2022-05-13 07:57:43 +02:00
onChanged: (value) {
if (value.length == 1) {
FocusScope.of(context).nextFocus();
2022-05-14 18:44:03 +02:00
} else if (value.isEmpty) {
2022-05-13 07:57:43 +02:00
FocusScope.of(context).previousFocus();
}
},
onSaved: (pin1) {},
2022-05-14 18:44:03 +02:00
decoration: const InputDecoration(
2022-05-15 21:10:37 +02:00
hintText: "",
2022-05-13 07:57:43 +02:00
focusColor: Colors.white,
hintStyle: TextStyle(color: Colors.white),
),
textAlign: TextAlign.center,
2022-05-14 18:44:03 +02:00
style: const TextStyle(color: Colors.white),
2022-05-13 07:57:43 +02:00
keyboardType: TextInputType.number,
inputFormatters: [
LengthLimitingTextInputFormatter(1),
FilteringTextInputFormatter.digitsOnly,
],
),
),
),
Container(
decoration: BoxDecoration(
border: Border.all(color: Colors.white),
),
child: SizedBox(
height: 50,
width: 50,
child: TextFormField(
2022-05-22 20:06:14 +02:00
controller: otpCode5,
2022-05-13 07:57:43 +02:00
onChanged: (value) {
if (value.length == 1) {
FocusScope.of(context).nextFocus();
2022-05-14 18:44:03 +02:00
} else if (value.isEmpty) {
2022-05-13 07:57:43 +02:00
FocusScope.of(context).previousFocus();
}
},
onSaved: (pin1) {},
2022-05-14 18:44:03 +02:00
decoration: const InputDecoration(
2022-05-15 21:10:37 +02:00
hintText: "",
2022-05-13 07:57:43 +02:00
focusColor: Colors.white,
hintStyle: TextStyle(color: Colors.white),
),
textAlign: TextAlign.center,
2022-05-14 18:44:03 +02:00
style: const TextStyle(color: Colors.white),
2022-05-13 07:57:43 +02:00
keyboardType: TextInputType.number,
inputFormatters: [
LengthLimitingTextInputFormatter(1),
FilteringTextInputFormatter.digitsOnly,
],
),
),
),
Container(
decoration: BoxDecoration(
border: Border.all(color: Colors.white),
),
child: SizedBox(
height: 50,
width: 50,
child: TextFormField(
2022-05-22 20:06:14 +02:00
controller: otpCode6,
2022-05-13 07:57:43 +02:00
onChanged: (value) {
if (value.length == 1) {
FocusScope.of(context).nextFocus();
2022-05-14 18:44:03 +02:00
} else if (value.isEmpty) {
2022-05-13 07:57:43 +02:00
FocusScope.of(context).previousFocus();
}
},
onSaved: (pin1) {},
2022-05-14 18:44:03 +02:00
decoration: const InputDecoration(
2022-05-15 21:10:37 +02:00
hintText: "",
2022-05-13 07:57:43 +02:00
focusColor: Colors.white,
hintStyle: TextStyle(color: Colors.white),
),
textAlign: TextAlign.center,
2022-05-14 18:44:03 +02:00
style: const TextStyle(color: Colors.white),
2022-05-13 07:57:43 +02:00
keyboardType: TextInputType.number,
inputFormatters: [
LengthLimitingTextInputFormatter(1),
FilteringTextInputFormatter.digitsOnly,
],
),
),
),
],
),
)),
ElevatedButton(
style: ButtonStyle(
foregroundColor:
MaterialStateProperty.all(const Color(0xff8B0000)),
backgroundColor:
MaterialStateProperty.all(const Color(0xff8B0000)),
shape: MaterialStateProperty.all<RoundedRectangleBorder>(
RoundedRectangleBorder(
borderRadius: BorderRadius.circular(18.0),
2022-05-15 21:10:37 +02:00
side: const BorderSide(color: Colors.black)))),
2022-05-13 07:57:43 +02:00
onPressed: () {
2022-05-22 20:06:14 +02:00
submitForm(context).then((res) {
if (res['statusCode'] == 200) {
addSession(res['data']['id'], res['data']['session_token']);
Navigator.pop(context);
Navigator.pop(context);
Navigator.pushReplacement(context, MaterialPageRoute(
builder: (context) => const Menu(initialScreen: 2)
));
}
});
2022-05-13 07:57:43 +02:00
},
child: const Text(
2022-05-15 21:10:37 +02:00
'Submit',
2022-05-13 07:57:43 +02:00
style: TextStyle(color: Colors.white, fontSize: 20),
),
)
]),
);
2022-04-29 09:11:05 +02:00
}
}