初始化
This commit is contained in:
@@ -0,0 +1,90 @@
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:hgdj/tools_base/toast.dart';
|
||||
|
||||
import '../../../alert/mine/vip_level_dialog.dart';
|
||||
import '../../../config/config.dart';
|
||||
import '../../../hj_utils/api_service/ai_service.dart';
|
||||
import '../../../tools_base/global_store/store.dart';
|
||||
import '../../../tools_base/loading/loading_helper.dart';
|
||||
import '../ai_sub_type/ai_function_logic.dart';
|
||||
import '../models/ai_change_face_video_model.dart';
|
||||
import '../widgets/ai_mod_cell.dart';
|
||||
|
||||
/// ai绘画
|
||||
class AiPaintLogic extends AiFunctionBaseLogic {
|
||||
late final TextEditingController titleCtr = TextEditingController();
|
||||
final aspectRatios = ["1:1", "4:3", "3:4", "16:9", "9:16"];
|
||||
int selectIndex = 0; //比例选择
|
||||
bool isFold = false;
|
||||
int chooseItemIndex = 0; //图片选择
|
||||
|
||||
List<AiChangeFaceVideoMod> models = [];
|
||||
|
||||
AiPaintLogic(super.modList);
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
models = modList?.aiTextToImgMod ?? [];
|
||||
}
|
||||
|
||||
@override
|
||||
void onClose() {
|
||||
titleCtr.dispose();
|
||||
super.onClose();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> submit() async {
|
||||
if ((globalStore.wallet?.amount ?? 0) <
|
||||
(int.tryParse(Config.aiDrawPrice) ?? 0)) {
|
||||
showVipLevelDialog(
|
||||
"当前金币不足",
|
||||
buttonTitle: '我知道了',
|
||||
desc: '充值金币 即可继续生成',
|
||||
vipEvent: () => Get.back(),
|
||||
);
|
||||
return;
|
||||
}
|
||||
if (titleCtr.text.isEmpty) {
|
||||
showToast('请输入绘画描述~');
|
||||
return;
|
||||
}
|
||||
if (models.isEmpty) {
|
||||
showToast('暂无模版,请退出重试');
|
||||
return;
|
||||
}
|
||||
|
||||
LoadingHelper.showLoading();
|
||||
final result = await AIService.generateTextToImage(
|
||||
aspectRatios[selectIndex],
|
||||
models[chooseItemIndex].styleType ?? 0,
|
||||
titleCtr.text,
|
||||
shareStatus: shareToAiSquare,
|
||||
shareTitle: titleCtr.text,
|
||||
);
|
||||
LoadingHelper.dismissLoading();
|
||||
if (result) {
|
||||
showToast("提交成功~");
|
||||
selectIndex = 0;
|
||||
chooseItemIndex = 0;
|
||||
isFold = false;
|
||||
titleCtr.text = '';
|
||||
update();
|
||||
} else {
|
||||
showToast("提交失败");
|
||||
}
|
||||
}
|
||||
|
||||
Widget instanceChild(int index) {
|
||||
return AIModCell(
|
||||
mod: models[index],
|
||||
isSelected: chooseItemIndex == index,
|
||||
onTap: () {
|
||||
chooseItemIndex = index;
|
||||
update();
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,300 @@
|
||||
import 'dart:math';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:hgdj/assets_tool/app_colors.dart';
|
||||
import 'package:hgdj/assets_tool/images.dart';
|
||||
import 'package:hgdj/config/config.dart';
|
||||
import 'package:hgdj/hj_utils/screen.dart';
|
||||
|
||||
import '../../../tools_base/widget/net_image_widget.dart';
|
||||
import '../models/ai_mod_list_model.dart';
|
||||
import '../widgets/ai_draw_text_field.dart';
|
||||
import 'ai_paint_logic.dart';
|
||||
|
||||
//ai绘画页面
|
||||
class AiPaintPage extends StatelessWidget {
|
||||
final AiModList? aiModList;
|
||||
|
||||
const AiPaintPage({super.key, this.aiModList});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
color: Color(0xff030F18),
|
||||
child: GetBuilder<AiPaintLogic>(
|
||||
init: AiPaintLogic(aiModList),
|
||||
builder: (logic) => Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16.0),
|
||||
child: Column(
|
||||
children: [
|
||||
Expanded(
|
||||
child: SingleChildScrollView(
|
||||
keyboardDismissBehavior:
|
||||
ScrollViewKeyboardDismissBehavior.onDrag,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
12.sizeBoxH,
|
||||
Row(
|
||||
children: [
|
||||
Text(
|
||||
"形象描述(必填)",
|
||||
style: TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
10.sizeBoxH,
|
||||
Container(
|
||||
margin: EdgeInsets.symmetric(horizontal: 2),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white.withValues(alpha: .05),
|
||||
borderRadius: BorderRadius.all(Radius.circular(5)),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.white.withValues(alpha: .05),
|
||||
blurRadius: 1, //阴影模糊程度
|
||||
spreadRadius: 1.0, //阴影扩散程度
|
||||
)
|
||||
],
|
||||
),
|
||||
child: AIDrawTextField(
|
||||
controller: logic.titleCtr,
|
||||
hintText: "示例:“女,大学生,身高165cm,体重50kg,穿着JK制服.”",
|
||||
maxLength: 100,
|
||||
height: 112,
|
||||
),
|
||||
),
|
||||
14.sizeBoxH,
|
||||
Text(
|
||||
"选择长宽比例",
|
||||
style: TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
20.sizeBoxH,
|
||||
SizedBox(
|
||||
height: 28,
|
||||
child: SingleChildScrollView(
|
||||
child: Row(
|
||||
children: List.generate(
|
||||
logic.aspectRatios.length,
|
||||
(index) => Padding(
|
||||
padding: EdgeInsets.only(right: 12),
|
||||
child: InkWell(
|
||||
enableFeedback: false,
|
||||
onTap: () {
|
||||
logic.selectIndex = index;
|
||||
logic.update();
|
||||
},
|
||||
child: Container(
|
||||
padding:
|
||||
EdgeInsets.symmetric(horizontal: 8),
|
||||
alignment: Alignment.center,
|
||||
decoration: BoxDecoration(
|
||||
gradient: LinearGradient(
|
||||
colors: logic.selectIndex == index
|
||||
? [
|
||||
AppColors.actionRed,
|
||||
AppColors.actionRed
|
||||
]
|
||||
: [
|
||||
Colors.white
|
||||
.withValues(alpha: .05),
|
||||
Colors.white
|
||||
.withValues(alpha: .05),
|
||||
]),
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
color: logic.selectIndex == index
|
||||
? null
|
||||
: Color(0xFF7C7C7C),
|
||||
),
|
||||
height: 28,
|
||||
child: Text(
|
||||
logic.aspectRatios[index],
|
||||
style: TextStyle(
|
||||
color: logic.selectIndex == index
|
||||
? Colors.white
|
||||
: Colors.white
|
||||
.withValues(alpha: .5),
|
||||
fontSize: logic.selectIndex == index
|
||||
? 14
|
||||
: 12,
|
||||
fontWeight: FontWeight.w400,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
18.sizeBoxH,
|
||||
0.5.line,
|
||||
18.sizeBoxH,
|
||||
Container(
|
||||
padding: EdgeInsets.only(bottom: logic.isFold ? 0 : 10),
|
||||
margin: EdgeInsets.symmetric(horizontal: 1),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white.withValues(alpha: 0.05),
|
||||
borderRadius: BorderRadius.all(Radius.circular(5)),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.white.withValues(alpha: .05),
|
||||
blurRadius: 1, //阴影模糊程度
|
||||
spreadRadius: 1.0, //阴影扩散程度
|
||||
)
|
||||
],
|
||||
),
|
||||
child: _getStyleView(logic),
|
||||
),
|
||||
18.sizeBoxH,
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Text(
|
||||
"处理一张照片的费用是 ",
|
||||
style: TextStyle(
|
||||
color: Color(0xff999999),
|
||||
fontSize: 12,
|
||||
),
|
||||
),
|
||||
Text(
|
||||
'${(int.tryParse(Config.aiDrawPrice) ?? 0)}金币',
|
||||
style: TextStyle(
|
||||
color: AppColors.actionRed,
|
||||
fontSize: 12,
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
InkWell(
|
||||
enableFeedback: false,
|
||||
onTap: () => logic.submit(),
|
||||
child: Container(
|
||||
height: 44,
|
||||
margin: EdgeInsets.symmetric(vertical: 12),
|
||||
alignment: Alignment.center,
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.actionRed,
|
||||
borderRadius: BorderRadius.circular(3),
|
||||
),
|
||||
child: Text(
|
||||
"立即提交",
|
||||
style: TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _getStyleView(AiPaintLogic logic) {
|
||||
return logic.isFold
|
||||
? InkWell(
|
||||
enableFeedback: false,
|
||||
onTap: () {
|
||||
logic.isFold = !logic.isFold;
|
||||
logic.update();
|
||||
},
|
||||
child: Padding(
|
||||
padding:
|
||||
const EdgeInsets.symmetric(horizontal: 10.0, vertical: 10),
|
||||
child: Row(
|
||||
children: [
|
||||
_buildStyleTitle(),
|
||||
Spacer(),
|
||||
NetworkImageLoader(
|
||||
imageUrl: logic.models.length > 1
|
||||
? logic.models[logic.chooseItemIndex].cover ?? ""
|
||||
: '',
|
||||
width: 32,
|
||||
height: 32,
|
||||
),
|
||||
10.sizeBoxW,
|
||||
Transform.rotate(
|
||||
angle: pi,
|
||||
child: Image.asset('ai_draw_narrow.png'.aiPath, width: 10),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
)
|
||||
: Column(
|
||||
children: [
|
||||
InkWell(
|
||||
enableFeedback: false,
|
||||
onTap: () {
|
||||
logic.isFold = !logic.isFold;
|
||||
logic.update();
|
||||
},
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 10.0, vertical: 10),
|
||||
child: Row(
|
||||
children: [
|
||||
_buildStyleTitle(),
|
||||
Spacer(),
|
||||
Image.asset('ai_draw_narrow.png'.aiPath, width: 10),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
GridView.builder(
|
||||
physics: NeverScrollableScrollPhysics(),
|
||||
shrinkWrap: true,
|
||||
padding: EdgeInsets.symmetric(horizontal: 10),
|
||||
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
|
||||
crossAxisCount: 3,
|
||||
mainAxisSpacing: 10,
|
||||
crossAxisSpacing: 10,
|
||||
childAspectRatio: 105 / 131,
|
||||
),
|
||||
itemCount: logic.models.length,
|
||||
itemBuilder: (context, index) {
|
||||
return logic.instanceChild(index);
|
||||
},
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
_buildStyleTitle() {
|
||||
return Row(
|
||||
children: [
|
||||
Image.asset(
|
||||
'ai_draw_style.png'.aiPath,
|
||||
width: 15,
|
||||
color: Colors.white,
|
||||
),
|
||||
5.sizeBoxW,
|
||||
Text(
|
||||
"风格",
|
||||
style: TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user