dreampad/lib/app/modules/welcome/controllers/welcome_controller.dart
2023-11-28 10:45:09 +08:00

84 lines
2.3 KiB
Dart

// ignore_for_file: unnecessary_overrides
import 'package:dreampad/app/routes/app_pages.dart';
import 'package:dreampad/app/shared/shared.dart';
import 'package:flustars_flutter3/flustars_flutter3.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:scroll_date_picker/scroll_date_picker.dart';
class WelcomeController extends GetxController {
final step = 0.obs;
final clickable = false.obs;
final pullStatus = 'down'.obs;
final birthday = ''.obs;
final selectedDate = DateTime.now().obs;
final selectedGender = 2.obs;
final focusNode = FocusNode();
final TextEditingController textController = TextEditingController();
ScrollViewDetailOptions dateScrollViewDetailOptions = ScrollViewDetailOptions(
selectedTextStyle: TextStyle(
fontSize: 18.sp,
fontWeight: FontWeight.w500,
color: Colors.white,
),
textStyle: TextStyle(
fontSize: 18.sp,
fontWeight: FontWeight.w500,
color: const Color(0xFF95C3E1),
),
);
@override
void onInit() {
super.onInit();
textController.addListener(verify);
textController.text = '天行';
birthday.value = '2013-12-03';
selectedDate.value = DateTime(2013, 12, 3);
clickable.value = true;
}
@override
void onReady() {
super.onReady();
}
@override
void onClose() {
textController.removeListener(verify);
textController.dispose();
focusNode.dispose();
super.onClose();
}
Future changeGende(int gender) async {
if (gender == 1) {
textController.text = '琉璃';
birthday.value = '2013-07-03';
selectedDate.value = DateTime(2013, 7, 19);
} else {
textController.text = '天行';
birthday.value = '2013-12-03';
selectedDate.value = DateTime(2013, 12, 3);
}
verify();
}
void verify() {
final String name = textController.text;
bool clickabled = true;
if (name.isEmpty || name.length < 2) {
clickabled = false;
}
clickable.value = clickabled && birthday.value.isNotEmpty;
}
Future confirm() async {
SpUtil.putString(Constant.account, textController.text);
SpUtil.putInt(Constant.gender, selectedGender.value);
SpUtil.putInt(Constant.age, AgeByBirthUtils.getAge(selectedDate.value));
await Get.offAllNamed(Routes.SELECT);
}
}