239 lines
5.6 KiB
Dart
239 lines
5.6 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:get/get.dart';
|
|
|
|
import '../models/occupation_model.dart';
|
|
|
|
class SelectController extends GetxController {
|
|
late int gender = 2;
|
|
late int count = 4;
|
|
late int page = 0;
|
|
late List<Occupation> occupations = [];
|
|
final confirm = false.obs;
|
|
final confirmTitle = '为你推荐的梦想职业是'.obs;
|
|
final selectOccupation = Rx<Occupation?>(null);
|
|
final selectOccupations = RxList<Rx<Occupation>>([]);
|
|
@override
|
|
void onInit() {
|
|
super.onInit();
|
|
gender = SpUtil.getInt(Constant.gender, defValue: 1)!;
|
|
if (gender == 1) {
|
|
initFemaleOccupation();
|
|
} else {
|
|
initMaleOccupation();
|
|
}
|
|
changeOccupation();
|
|
}
|
|
|
|
@override
|
|
void onReady() {
|
|
super.onReady();
|
|
}
|
|
|
|
@override
|
|
void onClose() {
|
|
super.onClose();
|
|
}
|
|
|
|
void initMaleOccupation() {
|
|
occupations.add(Occupation(
|
|
id: 1,
|
|
gender: 2,
|
|
name: '画家',
|
|
enName: 'artist',
|
|
vImage: 'btn_male_pic_artist',
|
|
hImage: 'pic_male_artist',
|
|
selected: true,
|
|
enable: true,
|
|
));
|
|
occupations.add(Occupation(
|
|
id: 2,
|
|
gender: 2,
|
|
name: '科学院士',
|
|
enName: 'academician',
|
|
vImage: 'btn_male_pic_academician',
|
|
hImage: 'pic_male_academician',
|
|
enable: true,
|
|
));
|
|
occupations.add(Occupation(
|
|
id: 3,
|
|
gender: 2,
|
|
name: '董事长',
|
|
enName: 'president',
|
|
vImage: 'btn_male_pic_president',
|
|
hImage: 'pic_male_president',
|
|
));
|
|
occupations.add(Occupation(
|
|
id: 4,
|
|
gender: 2,
|
|
name: '歌手',
|
|
enName: 'singer',
|
|
vImage: 'btn_male_pic_singer',
|
|
hImage: 'pic_male_singer',
|
|
selected: false,
|
|
));
|
|
occupations.add(Occupation(
|
|
id: 5,
|
|
gender: 2,
|
|
name: '运动员',
|
|
enName: 'athletes',
|
|
vImage: 'btn_male_pic_athletes',
|
|
hImage: 'pic_male_athletes',
|
|
selected: false,
|
|
));
|
|
|
|
occupations.add(Occupation(
|
|
id: 6,
|
|
gender: 2,
|
|
name: '军人',
|
|
enName: 'soldier',
|
|
vImage: 'btn_male_pic_soldier',
|
|
hImage: 'pic_male_soldier',
|
|
selected: false,
|
|
));
|
|
occupations.add(Occupation(
|
|
id: 7,
|
|
gender: 2,
|
|
name: '医生',
|
|
enName: 'doctor',
|
|
vImage: 'btn_male_pic_doctor',
|
|
hImage: 'pic_male_doctor',
|
|
selected: false,
|
|
));
|
|
occupations.add(Occupation(
|
|
id: 8,
|
|
gender: 2,
|
|
name: '饲养员',
|
|
enName: 'breeder',
|
|
vImage: 'btn_male_pic_breeder',
|
|
hImage: 'pic_male_breeder',
|
|
selected: false,
|
|
));
|
|
}
|
|
|
|
void initFemaleOccupation() {
|
|
occupations.add(Occupation(
|
|
id: 1,
|
|
gender: 1,
|
|
name: '画家',
|
|
enName: 'artist',
|
|
vImage: 'btn_female_pic_artist',
|
|
hImage: 'pic_female_artist',
|
|
selected: true,
|
|
enable: true,
|
|
));
|
|
occupations.add(Occupation(
|
|
id: 2,
|
|
gender: 1,
|
|
name: '科学院士',
|
|
enName: 'academician',
|
|
vImage: 'btn_female_pic_academician',
|
|
hImage: 'pic_female_academician',
|
|
enable: true,
|
|
));
|
|
occupations.add(Occupation(
|
|
id: 3,
|
|
gender: 1,
|
|
name: '董事长',
|
|
enName: 'president',
|
|
vImage: 'btn_female_pic_president',
|
|
hImage: 'pic_female_president',
|
|
));
|
|
occupations.add(Occupation(
|
|
id: 4,
|
|
gender: 1,
|
|
name: '歌手',
|
|
enName: 'singer',
|
|
vImage: 'btn_female_pic_singer',
|
|
hImage: 'pic_female_singer',
|
|
selected: false,
|
|
));
|
|
occupations.add(Occupation(
|
|
id: 5,
|
|
gender: 1,
|
|
name: '运动员',
|
|
enName: 'athletes',
|
|
vImage: 'btn_female_pic_athletes',
|
|
hImage: 'pic_female_athletes',
|
|
selected: false,
|
|
));
|
|
|
|
occupations.add(Occupation(
|
|
id: 6,
|
|
gender: 1,
|
|
name: '军人',
|
|
enName: 'soldier',
|
|
vImage: 'btn_female_pic_soldier',
|
|
hImage: 'pic_female_soldier',
|
|
selected: false,
|
|
));
|
|
occupations.add(Occupation(
|
|
id: 7,
|
|
gender: 1,
|
|
name: '医生',
|
|
enName: 'doctor',
|
|
vImage: 'btn_female_pic_doctor',
|
|
hImage: 'pic_female_doctor',
|
|
selected: false,
|
|
));
|
|
occupations.add(Occupation(
|
|
id: 8,
|
|
gender: 1,
|
|
name: '饲养员',
|
|
enName: 'breeder',
|
|
vImage: 'btn_female_pic_breeder',
|
|
hImage: 'pic_female_breeder',
|
|
selected: false,
|
|
));
|
|
}
|
|
|
|
Future change() async {
|
|
page++;
|
|
if (page * count >= occupations.length) {
|
|
page = 0;
|
|
}
|
|
changeOccupation();
|
|
}
|
|
|
|
void changeOccupation() {
|
|
var mOccupations = occupations
|
|
.where((t) => t.gender == gender)
|
|
.skip(page * count)
|
|
.take(count)
|
|
.toList();
|
|
selectOccupations.clear();
|
|
for (var occupation in mOccupations) {
|
|
selectOccupations.add(occupation.obs);
|
|
}
|
|
}
|
|
|
|
Future selectedOccupation(Occupation occupation) async {
|
|
selectOccupation.value = occupation;
|
|
for (var occupation in selectOccupations) {
|
|
occupation.update((val) {
|
|
val!.selected = false;
|
|
});
|
|
}
|
|
}
|
|
|
|
Future recommendOccupation(int id) async {
|
|
confirm.value = true;
|
|
var occupation = selectOccupations.firstWhere((t) => t.value.id == id);
|
|
selectOccupation.value = occupation.value;
|
|
for (var occupation in selectOccupations) {
|
|
occupation.update((val) {
|
|
val!.selected = false;
|
|
});
|
|
}
|
|
}
|
|
|
|
Future openDream() async {
|
|
SpUtil.putString(Constant.occupationName, selectOccupation.value!.name!);
|
|
SpUtil.putInt(Constant.occupationId, selectOccupation.value!.id!);
|
|
await Get.offAllNamed(Routes.HOME);
|
|
}
|
|
}
|