294 lines
8.8 KiB
Dart
294 lines
8.8 KiB
Dart
import 'dart:convert';
|
|
import 'dart:io';
|
|
|
|
import 'package:cathaypay_mobile/Register/camera_card_id.dart';
|
|
import 'package:cathaypay_mobile/Register/register.dart';
|
|
import 'package:cathaypay_mobile/Register/register_data.dart';
|
|
import 'package:cathaypay_mobile/Register/register_picture.dart';
|
|
import 'package:cathaypay_mobile/utils/utils.dart';
|
|
import 'package:device_info_plus/device_info_plus.dart';
|
|
import 'package:easy_localization/easy_localization.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:google_fonts/google_fonts.dart';
|
|
import 'package:path_provider/path_provider.dart';
|
|
import 'package:signature/signature.dart';
|
|
|
|
import '../api/api.dart';
|
|
import '../utils/color_custom.dart';
|
|
|
|
class RegisterSignaturePage extends StatefulWidget {
|
|
const RegisterSignaturePage({Key? key}) : super(key: key);
|
|
|
|
@override
|
|
State<RegisterSignaturePage> createState() => _RegisterSignaturePageState();
|
|
}
|
|
|
|
class _RegisterSignaturePageState extends State<RegisterSignaturePage> {
|
|
GlobalKey _containerKey = GlobalKey();
|
|
List<Offset> _points = <Offset>[];
|
|
final _pointsList = <Offset>[];
|
|
SignatureController? _controller;
|
|
DeviceInfoPlugin? deviceInfo;
|
|
bool loading = false;
|
|
String signaturePath = "";
|
|
|
|
@override
|
|
void initState() {
|
|
deviceInfo = DeviceInfoPlugin();
|
|
_controller = SignatureController(
|
|
strokeCap: StrokeCap.round,
|
|
strokeJoin: StrokeJoin.round,
|
|
penStrokeWidth: 5,
|
|
penColor: Colors.black,
|
|
exportBackgroundColor: Colors.white,
|
|
);
|
|
super.initState();
|
|
}
|
|
|
|
register() async {
|
|
setState(() {
|
|
loading = true;
|
|
});
|
|
var deviceId = "";
|
|
if (Platform.isAndroid) {
|
|
await deviceInfo?.androidInfo.then((value) => {deviceId = value.id});
|
|
} else if (Platform.isIOS) {
|
|
await deviceInfo?.iosInfo.then((value) => {deviceId = value.name});
|
|
}
|
|
var param = jsonEncode(<dynamic, dynamic>{
|
|
"Username": username.text.trim(),
|
|
"Email": email.text,
|
|
"FullName": name.text,
|
|
"PhoneNumber": phone.text,
|
|
"Password": password.text,
|
|
"ConfirmPassword": passwordConfirm.text,
|
|
"MobileDeviceId": deviceId,
|
|
"PersonalCardId": idCardEditText.text,
|
|
"MaxCardID": phone.text,
|
|
"UserType": "P",
|
|
"CustomerTypeId": "P01",
|
|
"GenderCode": "",
|
|
"MaritalStatusCode": "",
|
|
"TitleCode": prefix,
|
|
});
|
|
Api.postGetMessage(context, Api.register, param).then((value) =>
|
|
{
|
|
if (value != null)
|
|
{registerEkyc()}
|
|
else
|
|
{
|
|
setState(() {
|
|
loading = false;
|
|
}),
|
|
}
|
|
});
|
|
}
|
|
|
|
registerEkyc() async {
|
|
var deviceId = "";
|
|
if (Platform.isAndroid) {
|
|
await deviceInfo?.androidInfo.then((value) => {deviceId = value.id});
|
|
} else if (Platform.isIOS) {
|
|
await deviceInfo?.iosInfo.then((value) => {deviceId = value.name});
|
|
}
|
|
var param = jsonEncode(<dynamic, dynamic>{
|
|
"id_card": idCardEditText.text,
|
|
"code_back_card": idCardBackEditText.text,
|
|
"prefix_name": prefix,
|
|
"first_name": name.text,
|
|
"last_name": "",
|
|
"phone": phone.text,
|
|
"email": email.text,
|
|
"image_front_url": idCardFrontPath,
|
|
"image_back_url": idCardBackPath,
|
|
"is_pass": false,
|
|
"current_address": addressNow.text,
|
|
"occupation": occ,
|
|
"additional_occupation": jobOther.text,
|
|
"name_of_workplace": addressJob.text,
|
|
"max_card_no": phone.text,
|
|
"nationality": nationality.text,
|
|
"address_according_id_card": addressCard.text,
|
|
"work_address": addressJob2.text,
|
|
"image_person_with_card_url": imageEkycPath,
|
|
"signature_url": signaturePath,
|
|
"user_name": username.text,
|
|
"purpose": target,
|
|
});
|
|
Api.post(context, Api.ekyc, param).then((value) =>
|
|
{
|
|
if (value != null)
|
|
{
|
|
setState(() {
|
|
loading = false;
|
|
}),
|
|
Utils.showAlertDialogCallback(context, "กรุณาเช็ค e-mail เพื่อยืนยัน และรอการตรวจสอบข้อมูลยืนยันตัวตนภายใน 48 ชั่วโมง\nPlease check your email to confirm and wait for verification of your identity within 48 hours", (value) {
|
|
Navigator.pushNamed(context, '/');
|
|
})
|
|
}
|
|
else
|
|
{
|
|
setState(() {
|
|
loading = false;
|
|
}),
|
|
}
|
|
});
|
|
}
|
|
|
|
postImagePath(File image) {
|
|
Api.imageUploadPath(Api.uploadImage, image).then((value) =>
|
|
{
|
|
if (value != null) {imagePathJson(value)}
|
|
});
|
|
}
|
|
|
|
imagePathJson(value) {
|
|
value.forEach((v) {
|
|
signaturePath = v["file_name"];
|
|
});
|
|
register();
|
|
}
|
|
|
|
signatureCapture() {
|
|
_controller?.toPngBytes().then((value) => {writeFile(value)});
|
|
}
|
|
|
|
writeFile(imageInUnit8List) async {
|
|
final tempDir = await getTemporaryDirectory();
|
|
File file = await File('${tempDir.path}/imageSignature.png').create();
|
|
file.writeAsBytesSync(imageInUnit8List);
|
|
postImagePath(file);
|
|
}
|
|
|
|
Widget build(BuildContext context) {
|
|
return Stack(
|
|
children: [
|
|
Scaffold(
|
|
// extendBodyBehindAppBar: true,
|
|
|
|
appBar: AppBar(
|
|
backgroundColor: Colors.transparent,
|
|
actions: [
|
|
IconButton(
|
|
onPressed: () {
|
|
Navigator.of(context).pop();
|
|
},
|
|
icon: const Icon(
|
|
Icons.clear,
|
|
color: Colors.grey,
|
|
),
|
|
),
|
|
],
|
|
centerTitle: true,
|
|
elevation: 0,
|
|
title: Text(
|
|
"Verify your identity".tr(),
|
|
textAlign: TextAlign.center,
|
|
style: GoogleFonts.kanit(
|
|
color: Colors.black,
|
|
fontSize: 20,
|
|
),
|
|
),
|
|
),
|
|
body: SafeArea(
|
|
child: Column(mainAxisSize: MainAxisSize.max, children: [
|
|
register_step(index: 4),
|
|
Padding(
|
|
padding: const EdgeInsets.all(20.0),
|
|
child: Text(
|
|
"Sign your name".tr(),
|
|
textAlign: TextAlign.center,
|
|
style: GoogleFonts.kanit(
|
|
color: Color(0xff65676b),
|
|
fontSize: 16,
|
|
),
|
|
),
|
|
),
|
|
Expanded(
|
|
child: Stack(
|
|
children: [
|
|
Signature(
|
|
controller: _controller!,
|
|
backgroundColor: Colors.white,
|
|
),
|
|
Container(
|
|
alignment: Alignment.topRight,
|
|
margin: EdgeInsets.all(10),
|
|
child: InkWell(
|
|
onTap: () {
|
|
_controller!.clear();
|
|
},
|
|
child: Image.asset(
|
|
"images/register/rubber.png",
|
|
width: 50,
|
|
height: 50,
|
|
),
|
|
),
|
|
)
|
|
],
|
|
)),
|
|
Container(
|
|
child: InkWell(
|
|
onTap: () async {
|
|
signatureCapture();
|
|
},
|
|
child: SizedBox(
|
|
width: double.infinity,
|
|
child: Card(
|
|
shape: RoundedRectangleBorder(
|
|
borderRadius: BorderRadius.circular(40),
|
|
),
|
|
child: Container(
|
|
padding: EdgeInsets.all(10),
|
|
child: Text(
|
|
"Next".tr(),
|
|
textAlign: TextAlign.center,
|
|
style: GoogleFonts.kanit(
|
|
color: ColorCustom.greyBorder,
|
|
fontSize: 20,
|
|
fontWeight: FontWeight.w500,
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
)
|
|
]),
|
|
),
|
|
),
|
|
loading
|
|
? Center(
|
|
child: CircularProgressIndicator(),
|
|
)
|
|
: Container()
|
|
],
|
|
);
|
|
}
|
|
}
|
|
|
|
class DrawingPainter extends CustomPainter {
|
|
List<Offset> points;
|
|
|
|
DrawingPainter({required this.points});
|
|
|
|
@override
|
|
void paint(Canvas canvas, Size size) {
|
|
Paint paint = Paint()
|
|
..color = Colors.black
|
|
..strokeCap = StrokeCap.round
|
|
..strokeWidth = 5.0;
|
|
|
|
for (int i = 0; i < points.length - 1; i++) {
|
|
if (points[i] != null && points[i + 1] != null) {
|
|
canvas.drawLine(points[i], points[i + 1], paint);
|
|
}
|
|
}
|
|
}
|
|
|
|
@override
|
|
bool shouldRepaint(DrawingPainter oldDelegate) {
|
|
return oldDelegate.points != points;
|
|
}
|
|
}
|