| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568 |
- import 'package:dotted_border/dotted_border.dart';
- import 'package:flutter/material.dart';
- import 'package:flutter_screenutil/flutter_screenutil.dart';
- import 'package:get/get.dart';
- import 'package:keyboard/base/base_page.dart';
- import 'package:keyboard/module/character_custom/character_custom_controller.dart';
- import 'package:keyboard/resource/string.gen.dart';
- import 'package:keyboard/utils/toast_util.dart';
- import '../../resource/assets.gen.dart';
- import '../../utils/styles.dart';
- import '../../widget/auto_scroll_list_view.dart';
- class CharacterCustomPage extends BasePage<CharacterCustomController> {
- const CharacterCustomPage({super.key});
- static Future<void > start({StepType? step}) async {
- return Get.to(() => CharacterCustomPage());
- }
- @override
- bool immersive() {
- return true;
- }
- @override
- bool statusBarDarkFont() {
- return false;
- }
- @override
- Widget buildBody(BuildContext context) {
- return PopScope(
- canPop: false,
- onPopInvokedWithResult: (didPop, result) {
- if (didPop) {
- return;
- }
- controller.clickBack();
- },
- child: Obx(() {
- if (controller.currentStep.value == StepType.home) {
- return _buildCustomHomePage();
- } else {
- return _buildStepsPage();
- }
- }),
- );
- }
- // 定制首页
- Widget _buildCustomHomePage() {
- return Stack(
- children: [
- Assets.images.bgCharacterCustomHuman.image(
- width: double.infinity,
- fit: BoxFit.fill,
- ),
- SafeArea(
- child: Row(
- crossAxisAlignment: CrossAxisAlignment.center,
- mainAxisAlignment: MainAxisAlignment.spaceBetween,
- children: [
- Padding(
- padding: EdgeInsets.only(left: 16.w),
- child: GestureDetector(
- onTap: () {
- controller.clickBack();
- },
- child: Assets.images.iconCharacterCustomClose.image(
- width: 24.w,
- height: 24.w,
- ),
- ),
- ),
- GestureDetector(
- onTap: () {
- controller.clickHistory();
- },
- child: Container(
- width: 76.r,
- height: 32.h,
- decoration: ShapeDecoration(
- gradient: LinearGradient(
- colors: [
- const Color(0xFF702E96),
- const Color(0XFF400264),
- ],
- begin: Alignment.centerLeft,
- end: Alignment.centerRight,
- ),
- shape: RoundedRectangleBorder(
- borderRadius: BorderRadius.only(
- topLeft: Radius.circular(16.r),
- bottomLeft: Radius.circular(16.r),
- ),
- ),
- ),
- child: Center(
- child: Text(
- StringName.characterCustomHistory,
- style: TextStyle(
- color: Colors.white,
- fontSize: 14.sp,
- fontWeight: FontWeight.w400,
- ),
- ),
- ),
- ),
- ),
- ],
- ),
- ),
- Positioned(
- bottom: 50.h,
- left: 0,
- right: 0,
- child: GestureDetector(
- onTap: () {
- controller.clickNextButton(StepType.hobbies);
- },
- child: Center(
- child: Assets.images.iconCharacterCustomButton.image(
- width: 234.w,
- fit: BoxFit.contain,
- ),
- ),
- ),
- ),
- ],
- );
- }
- Widget _buildStepsPage() {
- return Stack(
- children: [
- Assets.images.bgCharacterCustomSteps.image(
- width: double.infinity,
- fit: BoxFit.fill,
- ),
- SafeArea(
- child: Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- Padding(
- padding: EdgeInsets.only(left: 16.w, bottom: 48.h),
- child: GestureDetector(
- onTap: () {
- controller.clickBack();
- },
- child: Assets.images.iconCharacterCustomClose.image(
- width: 24.w,
- height: 24.w,
- ),
- ),
- ),
- Expanded(
- child: SingleChildScrollView(
- child: Column(
- mainAxisAlignment: MainAxisAlignment.center,
- crossAxisAlignment: CrossAxisAlignment.center,
- children: [
- controller.currentStep.value == StepType.hobbies
- ? Assets.images.iconCharacterCustomStepOneTitle.image(
- fit: BoxFit.cover,
- width: 209.w,
- )
- : controller.currentStep.value == StepType.characters
- ? Assets.images.iconCharacterCustomStepTwoTitle.image(
- fit: BoxFit.cover,
- width: 168.w,
- )
- : Assets.images.iconCharacterCustomStepThreeTitle
- .image(fit: BoxFit.cover, width: 207.w),
- Container(
- margin: EdgeInsets.only(
- left: 16.w,
- right: 16.w,
- top: 24.h,
- ),
- width: double.infinity,
- decoration: ShapeDecoration(
- color: Colors.white,
- shape: RoundedRectangleBorder(
- borderRadius: BorderRadius.circular(20.r),
- ),
- shadows: [
- BoxShadow(
- color: Color(0x66D788FF),
- blurRadius: 10.r,
- offset: Offset(0, 0),
- spreadRadius: 0,
- ),
- ],
- ),
- child: Column(
- children: [
- Container(
- padding: EdgeInsets.symmetric(horizontal: 26.w),
- decoration: BoxDecoration(
- image: DecorationImage(
- image:
- Assets.images.bgCharacterCustomStepsDesc
- .provider(),
- fit: BoxFit.fill,
- ),
- ),
- child: Text(
- StringName.characterCustomStepsDesc,
- style: TextStyle(
- color: const Color(0xFFAD88EB),
- fontSize: 12.sp,
- fontWeight: FontWeight.w400,
- ),
- ),
- ),
- SizedBox(height: 24.h),
- Row(
- mainAxisAlignment: MainAxisAlignment.center,
- crossAxisAlignment: CrossAxisAlignment.center,
- children: [
- Text(
- '第${controller.currentStep.value.value}步',
- style: TextStyle(
- color: const Color(0xFF755AAB),
- fontSize: 12.sp,
- fontWeight: FontWeight.w500,
- ),
- ),
- Text(
- " | ",
- style: TextStyle(
- color: const Color(0xFF755AAB),
- fontSize: 12.sp,
- fontWeight: FontWeight.w500,
- ),
- ),
- Opacity(
- opacity: 0.60,
- child: Text(
- '共3步',
- style: TextStyle(
- color: const Color(0xFF755BAB),
- fontSize: 12.sp,
- fontWeight: FontWeight.w500,
- ),
- ),
- ),
- ],
- ),
- if (controller.currentStep.value ==
- StepType.hobbies)
- _buildHobbiesPage(),
- if (controller.currentStep.value ==
- StepType.characters)
- _buildCharacterPage(),
- if (controller.currentStep.value ==
- StepType.inputName)
- _buildInputNamePage(),
- ],
- ),
- ),
- ],
- ),
- ),
- ),
- ],
- ),
- ),
- ],
- );
- }
- Widget _buildSelectionPage({
- required String title,
- required String subtitle,
- required List<dynamic> items,
- required RxList<dynamic> selectedLabels,
- required Function(dynamic) onSelected,
- required bool isCustomEnabled,
- required VoidCallback onCustomClick,
- required VoidCallback nextClick,
- required bool isShowEmoji,
- }) {
- return Obx(() {
- int rowCount = 3; // 3 行
- int columnCount = (items.length / rowCount).ceil(); // 计算列数
- return Column(
- children: [
- Padding(
- padding: EdgeInsets.only(top: 15.h),
- child: Text(
- title,
- style: TextStyle(
- color: const Color(0xFF755BAB),
- fontSize: 18.sp,
- fontWeight: FontWeight.w500,
- ),
- ),
- ),
- Text(
- subtitle,
- style: TextStyle(
- color: const Color(0xFF755BAB).withOpacity(0.6),
- fontSize: 12.sp,
- fontWeight: FontWeight.w500,
- ),
- ),
- Container(
- margin: EdgeInsets.only(top: 32.h, left: 21.w, right: 21.w),
- height: 180.h,
- child: AutoScrollListView(
- itemCount: columnCount, // 列数
- scrollDirection: Axis.horizontal,
- itemBuilder: (context, columnIndex) {
- // 3 个 item
- int startIndex = columnIndex * rowCount;
- List<dynamic> columnItems =
- items.skip(startIndex).take(rowCount).toList();
- return Column(
- mainAxisSize: MainAxisSize.min,
- children:
- columnItems.map((item) {
- final emoji = item.emoji ?? "";
- final name = item.name ?? "";
- return Padding(
- padding: EdgeInsets.symmetric(
- vertical: 4.h,
- horizontal: 4.w,
- ),
- child: Obx(() {
- bool isSelected = selectedLabels.any(
- (selected) => selected.name == item.name,
- );
- return ChoiceChip(
- label: Text(
- isShowEmoji ? "$emoji$name" : name,
- style: TextStyle(
- color:
- isSelected
- ? Colors.white
- : const Color(0xFF755BAB),
- fontSize: 14.sp,
- fontWeight: FontWeight.w400,
- ),
- ),
- showCheckmark: false,
- selected: isSelected,
- selectedColor: const Color(0xFFB782FF),
- backgroundColor: Colors.white,
- shape: RoundedRectangleBorder(
- side: BorderSide(
- width: 1.w,
- color: const Color(0x4C755BAB),
- ),
- borderRadius: BorderRadius.circular(31.r),
- ),
- onSelected: (selected) {
- onSelected(item);
- },
- );
- }),
- );
- }).toList(),
- );
- },
- ),
- ),
- Visibility(
- visible: isCustomEnabled,
- replacement: SizedBox(width: 115.w, height: 36.h),
- child: GestureDetector(
- onTap: onCustomClick,
- child: Container(
- margin: EdgeInsets.only(top: 3.h),
- child: DottedBorder(
- color: const Color(0xFFC9C2DB),
- strokeWidth: 1.0.w,
- borderType: BorderType.RRect,
- radius: Radius.circular(20.r),
- child: Container(
- width: 115.w,
- height: 33.h,
- alignment: Alignment.center,
- child: Row(
- mainAxisAlignment: MainAxisAlignment.center,
- children: [
- Assets.images.iconCharacterCustomPlus.image(
- width: 18.w,
- height: 18.w,
- ),
- Text(
- StringName.characterCustomCustomizable,
- style: TextStyle(
- color: const Color(0xFFC9C2DB),
- fontSize: 14.sp,
- fontWeight: FontWeight.w500,
- ),
- ),
- ],
- ),
- ),
- ),
- ),
- ),
- ),
- Container(
- margin: EdgeInsets.only(top: 107.h, bottom: 32.h),
- child: _buildNextButton(
- isEnable: selectedLabels.isNotEmpty,
- onTap: nextClick,
- ),
- ),
- ],
- );
- });
- }
- Widget _buildNextButton({required VoidCallback onTap, required isEnable}) {
- return GestureDetector(
- onTap: () {
- onTap();
- },
- child: Container(
- width: 220.w,
- height: 48.h,
- decoration:
- isEnable
- ? Styles.getActivateButtonDecoration(31.r)
- : Styles.getInactiveButtonDecoration(31.r),
- child: Center(
- child: Text(
- '下一步',
- style: TextStyle(
- color: Colors.white,
- fontSize: 16.sp,
- fontWeight: FontWeight.w500,
- ),
- ),
- ),
- ),
- );
- }
- // 选择爱好页面
- Widget _buildHobbiesPage() {
- return _buildSelectionPage(
- title: StringName.characterCustomHobbiesTitle,
- subtitle:
- "(最多选择${controller.currentCharacterCustomConfig?.maxHobbyNum ?? 3}个)",
- items: controller.hobbiesLabelsList,
- selectedLabels: controller.hobbiesSelectLabels,
- isShowEmoji: true,
- onSelected: (name) {
- controller.selectHobby(name);
- },
- isCustomEnabled:
- controller.currentCharacterCustomConfig?.customHobby == true,
- onCustomClick: () {
- controller.clickHobbiesCustom();
- },
- nextClick: () {
- controller.clickHobbiesNext();
- },
- );
- }
- // 选择性格页面
- Widget _buildCharacterPage() {
- return _buildSelectionPage(
- title: StringName.characterCustomcharacterTitle,
- subtitle:
- "(最多选择${controller.currentCharacterCustomConfig?.maxCharacterNum ?? 3}个)",
- items: controller.characterLabelsList,
- selectedLabels: controller.characterSelectLabels,
- isShowEmoji: true,
- onSelected: (character) {
- controller.selectCharacter(character);
- },
- isCustomEnabled:
- controller.currentCharacterCustomConfig?.customCharacter == true,
- onCustomClick: () {
- controller.clickCharacterCustom();
- },
- nextClick: () {
- controller.clickCharacterNext();
- },
- );
- }
- // 输入名字页面
- Widget _buildInputNamePage() {
- return Obx(() {
- return Column(
- children: [
- Padding(
- padding: EdgeInsets.only(top: 15.h),
- child: Text(
- StringName.characterCustomNameTitle,
- style: TextStyle(
- color: const Color(0xFF755BAB),
- fontSize: 18.sp,
- fontWeight: FontWeight.w500,
- ),
- ),
- ),
- Text(
- "人设名称(最多5个字)",
- style: TextStyle(
- color: Color(0xFF755BAB).withValues(alpha: 0.6),
- fontSize: 12.sp,
- fontWeight: FontWeight.w500,
- ),
- ),
- Container(
- margin: EdgeInsets.only(top: 32.h, left: 21.w, right: 21.w),
- alignment: Alignment.center,
- child: Container(
- height: 48.h,
- alignment: Alignment.center,
- decoration: ShapeDecoration(
- color: const Color(0xFFF5F4F9),
- shape: RoundedRectangleBorder(
- borderRadius: BorderRadius.circular(31.r),
- ),
- ),
- child: TextField(
- // maxLength: maxLength,
- maxLines: 1,
- // expands: true,
- textAlign: TextAlign.center,
- textAlignVertical: TextAlignVertical.center,
- onChanged: (value) {
- controller.currentNameValue.value = value;
- },
- decoration: InputDecoration(
- isDense: true,
- counterText: "",
- hintText: StringName.characterCustomNameHint,
- hintStyle: TextStyle(color: Colors.black.withAlpha(66)),
- border: OutlineInputBorder(
- borderRadius: BorderRadius.circular(31.r),
- borderSide: BorderSide.none, // 移除边框线
- ),
- filled: true,
- fillColor: const Color(0xFFF5F4F9),
- ),
- ),
- ),
- ),
- Container(
- margin: EdgeInsets.only(top: 44.h, bottom: 32.h),
- child: _buildNextButton(
- isEnable: controller.currentNameValue.trim().isNotEmpty,
- onTap: () {
- controller.clickInputNameNext();
- },
- ),
- ),
- ],
- );
- });
- }
- }
|