100 lines
2.5 KiB
Dart
100 lines
2.5 KiB
Dart
import 'dart:async';
|
|
|
|
import 'package:circle_app/util/util.dart';
|
|
import 'package:flutter/cupertino.dart';
|
|
import 'package:flutter/foundation.dart';
|
|
import 'package:get/get.dart';
|
|
|
|
import '../../network/api.dart';
|
|
import '../../network/dio_manager.dart';
|
|
import '../account/logic.dart';
|
|
import '../login/login/logic.dart';
|
|
import 'state.dart';
|
|
|
|
class PhotoinfoLogic extends GetxController {
|
|
final PhotoinfoState state = PhotoinfoState();
|
|
|
|
TextEditingController photoController = TextEditingController();
|
|
// TextEditingController passwordController = TextEditingController();
|
|
TextEditingController newPhotoController = TextEditingController();
|
|
TextEditingController codeController = TextEditingController();
|
|
|
|
int countdownSeconds = 60;
|
|
bool isCountingDown = false;
|
|
Timer? timer ;
|
|
|
|
|
|
|
|
@override
|
|
void onClose() {
|
|
timer?.cancel();
|
|
super.onClose();
|
|
}
|
|
|
|
|
|
|
|
// @override
|
|
// void dispose() {
|
|
// timer?.cancel();
|
|
// super.dispose();
|
|
// }
|
|
|
|
|
|
|
|
bindingPhoto()async{
|
|
var data = await DioManager.instance.put(url: Api.bindingPhoto, params: {
|
|
"old_phone": photoController.text.toString(),
|
|
"new_phone": newPhotoController.text.toString(),
|
|
"code": codeController.text.toString(),
|
|
});
|
|
// var activity = Get.find<MinefragmentLogic>();
|
|
// activity.isVip
|
|
var bean = BaseResponse<dynamic>.fromJson(data, (jsonData) => jsonData,);
|
|
showOKToast(bean.msg);
|
|
if(bean.isSuccess()){
|
|
final accountLogic = Get.find<AccountLogic>();
|
|
accountLogic.photo = newPhotoController.text.toString();
|
|
accountLogic.update();
|
|
Get.back();
|
|
|
|
}
|
|
}
|
|
|
|
|
|
void startCountdown() {
|
|
isCountingDown = true;
|
|
countdownSeconds = 60;
|
|
|
|
timer = Timer.periodic(Duration(seconds: 1), (timer) {
|
|
if (countdownSeconds > 0) {
|
|
countdownSeconds--;
|
|
update();
|
|
print(countdownSeconds.toString());
|
|
} else {
|
|
isCountingDown = false;
|
|
timer?.cancel();
|
|
}
|
|
});
|
|
}
|
|
|
|
Future<void> getCode() async {
|
|
if(!GetUtils.isPhoneNumber(newPhotoController.text)){
|
|
showOKToast("新手机号输入有误");
|
|
return;
|
|
}
|
|
var data = await DioManager.instance.post(url: Api.sendCode, params: {"phone": newPhotoController.text});
|
|
var bean = BaseResponse<Data>.fromJson(data, (data) => Data.fromJson(data));
|
|
showOKToast(bean.msg);
|
|
if(kDebugMode){
|
|
if(bean.code==200){
|
|
codeController.text = bean.data!.code.toString();
|
|
startCountdown();
|
|
update();
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
}
|