dreampad/lib/app/modules/welcome/controllers/welcome_controller.dart

82 lines
2.2 KiB
Dart
Raw Normal View History

2023-11-28 10:44:58 +08:00
// ignore_for_file: unnecessary_overrides
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 {
2023-11-29 20:37:45 +08:00
final step = 1.obs;
2023-11-28 10:44:58 +08:00
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));
}
}