Commit 5fcf9f32 authored by 关振斌's avatar 关振斌

update

parent 2f7c6604
...@@ -25,17 +25,24 @@ class NewsAPI { ...@@ -25,17 +25,24 @@ class NewsAPI {
return response['data']; return response['data'];
} }
static Future<int> aiAnswerWithStream(Map<String, String> params) async {
var response =
await HttpUtil().post('/openAi/aiAnswerWithStream', data: params);
return response['status'];
}
// /api/openAi/aiAnswerWithStream
static Future<String> doPay(Map<String, String> params) async { static Future<String> doPay(Map<String, String> params) async {
var response = await HttpUtil().post('/pay/doPay', data: params); var response = await HttpUtil().post('/pay/doPay', data: params);
return response['data']; return response['data'];
} }
// /api/pay/doPay // /api/pay/doPay
static Future<String> sendMessageByDetailId( static Future<int> sendMessageByDetailId(
dynamic params, String detailId) async { dynamic params, String detailId) async {
var response = var response =
await HttpUtil().post('/openAi/aiAnswer/${detailId}', data: params); await HttpUtil().post('/openAi/aiAnswer/${detailId}', data: params);
return response['data']; return response['status'];
} }
static Future<List<GoodEntity>> getGoodsList() async { static Future<List<GoodEntity>> getGoodsList() async {
......
// baidu yapi // baidu yapi
// const SERVER_API_URL = 'https://yapi.baidu.com/mock/41008'; // const SERVER_API_URL = 'https://yapi.baidu.com/mock/41008';
// const SERVER_API_URL = 'https://yapi.ducafecat.tech/mock/11'; // const SERVER_API_URL = 'http://192.168.110.127:8083/api';
// const SERVER_API_URL = 'http://101.34.153.228:8083/api';//线上 const SERVER_API_URL = 'http://101.34.153.228:8083/api';//线上
// http://192.168.110.127:8083/api/doc.html
// http://192.168.110.66:8083/api/doc.html // http://192.168.110.66:8083/api/doc.html
const SERVER_API_URL = 'http://192.168.110.66:8083/api'; // const SERVER_API_URL = 'http://192.168.110.66:8083/api';
// http://192.168.110.25:8083/ // http://192.168.110.25:8083/
// const SERVER_API_URL = 'http://192.168.2.178:8083/api'; // const SERVER_API_URL = 'http://192.168.2.178:8083/api';
// const SERVER_API_URL = 'http://192.168.110.57:8083/api'; // const SERVER_API_URL = 'http://192.168.110.57:8083/api';
......
...@@ -13,7 +13,7 @@ AppBar transparentAppBar({ ...@@ -13,7 +13,7 @@ AppBar transparentAppBar({
// elevation: 2, // elevation: 2,
title: title, title: title,
leading: leading ?? null, leading: leading ?? null,
// actions: actions, actions: actions,
); );
} }
......
...@@ -5,6 +5,7 @@ import 'dart:math'; ...@@ -5,6 +5,7 @@ import 'dart:math';
import 'package:animated_text_kit/animated_text_kit.dart'; import 'package:animated_text_kit/animated_text_kit.dart';
import 'package:flutter/gestures.dart'; import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_markdown/flutter_markdown.dart';
import 'package:flutter_parsed_text/flutter_parsed_text.dart'; import 'package:flutter_parsed_text/flutter_parsed_text.dart';
import 'package:gradient_borders/input_borders/gradient_outline_input_border.dart'; import 'package:gradient_borders/input_borders/gradient_outline_input_border.dart';
import 'package:intl/intl.dart' as intl; import 'package:intl/intl.dart' as intl;
......
...@@ -60,6 +60,24 @@ class _InputToolbarState extends State<InputToolbar> ...@@ -60,6 +60,24 @@ class _InputToolbarState extends State<InputToolbar>
super.dispose(); super.dispose();
} }
// AnimatedTextKit(
// onFinished: () => {},
// totalRepeatCount: 1,
// animatedTexts: identical(message.status, Status.sending)
// ? [
// TypewriterAnimatedText('正在思考中......'),
// TypewriterAnimatedText('正在使劲思考中......'),
// TypewriterAnimatedText('正在拼命思考中......'),
// TypewriterAnimatedText('您的问题太有深度,请稍等......'),
// ]
// : [
// TypewriterAnimatedText(
// message.text,
// speed: const Duration(milliseconds: 100),
// )
// ],
// )
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Container( return Container(
...@@ -75,47 +93,62 @@ class _InputToolbarState extends State<InputToolbar> ...@@ -75,47 +93,62 @@ class _InputToolbarState extends State<InputToolbar>
Expanded( Expanded(
child: Directionality( child: Directionality(
textDirection: widget.inputOptions.inputTextDirection, textDirection: widget.inputOptions.inputTextDirection,
child: TextField( child: widget.inputOptions.inputDisabled
focusNode: focusNode, ? Center(
controller: textController, child: AnimatedTextKit(
enabled: !widget.inputOptions.inputDisabled, animatedTexts: [
textCapitalization: widget.inputOptions.textCapitalization, TypewriterAnimatedText('AI正在生成中......',
textInputAction: widget.inputOptions.textInputAction, textStyle: TextStyle(color: Colors.white)),
decoration: widget.inputOptions.inputDecoration ?? ],
defaultInputDecoration(_sendMessage), )
maxLength: widget.inputOptions.maxInputLength, // Text("请稍等", style: TextStyle(color: Colors.white)
minLines: 1,
maxLines: widget.inputOptions.sendOnEnter ,
? 1 )
: widget.inputOptions.inputMaxLines, : TextField(
cursorColor: widget.inputOptions.cursorStyle.color, focusNode: focusNode,
cursorWidth: widget.inputOptions.cursorStyle.width, controller: textController,
showCursor: !widget.inputOptions.cursorStyle.hide, enabled: !widget.inputOptions.inputDisabled,
style: widget.inputOptions.inputTextStyle, textCapitalization:
onSubmitted: (String value) { widget.inputOptions.textCapitalization,
if (widget.inputOptions.sendOnEnter) { textInputAction: widget.inputOptions.textInputAction,
_sendMessage(); decoration: widget.inputOptions.inputDecoration ??
} defaultInputDecoration(_sendMessage),
}, maxLength: widget.inputOptions.maxInputLength,
onChanged: (String value) async { minLines: 1,
setState(() {}); maxLines: 1,
if (widget.inputOptions.onTextChange != null) { // maxLines: widget.inputOptions.sendOnEnter
widget.inputOptions.onTextChange!(value); // ? 1
} // : widget.inputOptions.inputMaxLines,
WidgetsBinding.instance.addPostFrameCallback((_) async { cursorColor: widget.inputOptions.cursorStyle.color,
if (widget.inputOptions.onMention != null) { cursorWidth: widget.inputOptions.cursorStyle.width,
await _checkMentions(value); showCursor: !widget.inputOptions.cursorStyle.hide,
} style: widget.inputOptions.inputTextStyle,
}); onSubmitted: (String value) {
}, if (widget.inputOptions.sendOnEnter) {
autocorrect: widget.inputOptions.autocorrect, _sendMessage();
), }
},
onChanged: (String value) async {
setState(() {});
if (widget.inputOptions.onTextChange != null) {
widget.inputOptions.onTextChange!(value);
}
WidgetsBinding.instance.addPostFrameCallback((_) async {
if (widget.inputOptions.onMention != null) {
await _checkMentions(value);
}
});
},
autocorrect: widget.inputOptions.autocorrect,
),
), ),
), ),
if (widget.inputOptions.trailing != null && if (widget.inputOptions.trailing != null &&
widget.inputOptions.showTraillingBeforeSend) widget.inputOptions.showTraillingBeforeSend)
...widget.inputOptions.trailing!, ...widget.inputOptions.trailing!,
//发送按钮重写 //发送按钮重写
// inputDisabled
// if (widget.inputOptions.alwaysShowSend || // if (widget.inputOptions.alwaysShowSend ||
// textController.text.isNotEmpty) // textController.text.isNotEmpty)
// widget.inputOptions.sendButtonBuilder != null // widget.inputOptions.sendButtonBuilder != null
......
...@@ -54,23 +54,13 @@ class DefaultAvatar extends StatelessWidget { ...@@ -54,23 +54,13 @@ class DefaultAvatar extends StatelessWidget {
ClipOval( ClipOval(
child: Container( child: Container(
color: Colors.grey[200], color: Colors.grey[200],
child: getInitials().isNotEmpty child: Image(
? Center( image: fallbackImage ??
child: Text( const AssetImage(
getInitials(), 'assets/images/logo.png',
style: TextStyle( // package: 'dash_chat_2',
color: Colors.black,
fontSize: size * 0.35,
),
),
)
: Image(
image: fallbackImage ??
const AssetImage(
'assets/profile_placeholder.png',
package: 'dash_chat_2',
),
), ),
),
), ),
), ),
if (user.profileImage != null && user.profileImage!.isNotEmpty) if (user.profileImage != null && user.profileImage!.isNotEmpty)
......
...@@ -97,7 +97,7 @@ class DefaultMessageText extends StatelessWidget { ...@@ -97,7 +97,7 @@ class DefaultMessageText extends StatelessWidget {
Widget getPostMessageBuild(String text, List<ChatMessage> messageLength, Widget getPostMessageBuild(String text, List<ChatMessage> messageLength,
bool isOwnMessage, int index) { bool isOwnMessage, int index) {
var lastMessage = messageLength.first; // var lastMessage = messageLength.first;
// if(lastMessage.) { // if(lastMessage.) {
...@@ -107,23 +107,18 @@ class DefaultMessageText extends StatelessWidget { ...@@ -107,23 +107,18 @@ class DefaultMessageText extends StatelessWidget {
// if(a.is) // if(a.is)
// if() // if()
return index == 0 // Text(text);
? AnimatedTextKit( // return Container(
animatedTexts: [ // height: 200,
TypewriterAnimatedText( // child: Markdown(data: text, selectable: true),
text, // );
textStyle: const TextStyle(
// fontSize: 32.0, return RichText(
// fontWeight: FontWeight.bold, text: TextSpan(text: text, style: TextStyle(color: Colors.black)),
), // selectionRegistrar: SelectionContainer.maybeOf(context),
speed: const Duration(milliseconds: 100), selectionColor: const Color(0xAF6694e8),
) );
], // Markdown(data: text, selectable: true);
totalRepeatCount: 1,
// displayFullTextOnTap: true,
// stopPauseOnTap: true,
)
: Text(text);
} }
// {buildPostMessage = getPostMessageBuild} // {buildPostMessage = getPostMessageBuild}
......
import 'dart:async';
import 'package:chart/common/apis/apis.dart'; import 'package:chart/common/apis/apis.dart';
import 'package:chart/common/store/store.dart'; import 'package:chart/common/store/store.dart';
import 'package:chart/common/values/server.dart';
import 'package:chart/entity/user_entity.dart'; import 'package:chart/entity/user_entity.dart';
import 'package:chart/package/chat_dash/dash_chat_2.dart' as Chat; import 'package:chart/package/chat_dash/dash_chat_2.dart' as Chat;
import 'package:chart/package/chat_dash/dash_chat_2.dart';
import 'package:chart/pages/frame/product/controller.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart'; import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:flutter_vibrate/flutter_vibrate.dart'; import 'package:flutter_vibrate/flutter_vibrate.dart';
import 'package:get/get.dart'; import 'package:get/get.dart';
import 'package:share_plus/share_plus.dart';
import 'package:uuid/uuid.dart'; import 'package:uuid/uuid.dart';
import 'package:flutter_chat_types/flutter_chat_types.dart' as types; import 'package:flutter_chat_types/flutter_chat_types.dart' as types;
import 'index.dart'; import 'index.dart';
import 'package:eventsource/eventsource.dart';
import 'dart:convert';
import 'package:flutter/services.dart';
// EventSource eventSource = EventSource(Uri.parse('http://example.com/events'));
//
class ChatNewController extends GetxController { class ChatNewController extends GetxController {
ChatNewController(); ChatNewController();
...@@ -16,6 +30,8 @@ class ChatNewController extends GetxController { ...@@ -16,6 +30,8 @@ class ChatNewController extends GetxController {
final state = ChatPageState(); final state = ChatPageState();
late StreamSubscription<Event> eventSource;
/// 成员变量 /// 成员变量
/// 事件 /// 事件
...@@ -42,6 +58,7 @@ class ChatNewController extends GetxController { ...@@ -42,6 +58,7 @@ class ChatNewController extends GetxController {
/// 事件 /// 事件
void sendMessage(Chat.ChatMessage message) async { void sendMessage(Chat.ChatMessage message) async {
print("${message.text}321321321");
Vibrate.feedback(FeedbackType.impact); Vibrate.feedback(FeedbackType.impact);
// if (state.messageList.isNotEmpty) { // if (state.messageList.isNotEmpty) {
// // data = !_messages.every((element) => element.status != Status.sending); // // data = !_messages.every((element) => element.status != Status.sending);
...@@ -78,32 +95,41 @@ class ChatNewController extends GetxController { ...@@ -78,32 +95,41 @@ class ChatNewController extends GetxController {
_addMessage(textMessage); _addMessage(textMessage);
// _addMessage(loadingMessage); // _addMessage(loadingMessage);
EasyLoading.show(status: "正在思考中...");
// ("正在思考中..."); // ("正在思考中...");
try { try {
// print("1321312321${UserStore.to.profile.id}"); // print("1321312321${UserStore.to.profile.id}");
if (UserStore.to.profile.id != '') { if (UserStore.to.profile.id != '') {
String? result = await NewsAPI.sendMessage( state.isLoading = true;
{"question": message.text, "id": "${UserStore.to.profile.id}"}); int? result =
await NewsAPI.aiAnswerWithStream({"question": message.text});
// _cancelLoading(); // _cancelLoading();
final receiveMessage = Chat.ChatMessage(
user: receiveUser, if (result == 200) {
createdAt: DateTime.now(), EasyLoading.dismiss();
// id: const Uuid().v4(), Vibrate.feedback(FeedbackType.success);
text: "$result", UserAPI.getUserInfo().then((value) async {
); await UserStore.to.saveProfile(IntegralEntity(
_addMessage(receiveMessage); id: UserStore.to.profile.id,
EasyLoading.dismiss(); username: UserStore.to.profile.username,
Vibrate.feedback(FeedbackType.success); token: UserStore.to.profile.token,
UserAPI.getUserInfo().then((value) async { expireTime: value.expireTime,
await UserStore.to.saveProfile(IntegralEntity( integral: value.integral));
id: UserStore.to.profile.id, });
username: UserStore.to.profile.username,
token: UserStore.to.profile.token, final receiveMessage = Chat.ChatMessage(
expireTime: value.expireTime, user: receiveUser,
integral: value.integral)); createdAt: DateTime.now(),
}); // id: const Uuid().v4(),
text: " ",
);
_addMessage(receiveMessage);
// index.value = state.messageList.length;
} else {
EasyLoading.showError("网络异常");
EasyLoading.dismiss();
state.isLoading = false;
}
} else { } else {
final receiveErrorMessage = Chat.ChatMessage( final receiveErrorMessage = Chat.ChatMessage(
user: receiveUser, user: receiveUser,
...@@ -111,13 +137,14 @@ class ChatNewController extends GetxController { ...@@ -111,13 +137,14 @@ class ChatNewController extends GetxController {
// id: const Uuid().v4(), // id: const Uuid().v4(),
text: "你还未登录,请登录后再体验更多功能。", text: "你还未登录,请登录后再体验更多功能。",
); );
state.isLoading = false;
_addMessage(receiveErrorMessage); _addMessage(receiveErrorMessage);
EasyLoading.dismiss(); EasyLoading.dismiss();
Vibrate.feedback(FeedbackType.error); Vibrate.feedback(FeedbackType.error);
} }
} catch (e) { } catch (e) {
print("eeeeeeee$e"); // print("eeeeeeee$e");
state.isLoading = false;
// _cancelLoading(); // _cancelLoading();
final receiveErrorMessage = Chat.ChatMessage( final receiveErrorMessage = Chat.ChatMessage(
user: receiveUser, user: receiveUser,
...@@ -172,15 +199,104 @@ class ChatNewController extends GetxController { ...@@ -172,15 +199,104 @@ class ChatNewController extends GetxController {
// print("${state.newsList.length}"); // print("${state.newsList.length}");
} }
initEventSource() async {
final eventSourceUrl = await EventSource.connect(
"$SERVER_API_URL/openAi/connect/${UserStore.to.profile.id}")
as EventSource;
eventSource = eventSourceUrl.listen(
(Event event) {
// print("New event:");
// print(" event: ${event.event}");
// print(" data: ${event.data}");
// final a = json['event.data'];
if (event.data == "[DONE]") {
state.isLoading = false;
// eventSource.cancel();
return;
}
Map<String, dynamic> jsonMap = jsonDecode("${event.data}");
// if()
if (jsonMap['askType'] == 1) {
_updateMessage("${jsonMap['content']}" as String);
} else {
// print("${jsonMap['content']}}");
print("${jsonMap['content']}");
ProductController.to.state.inderText =
ProductController.to.state.inderText + jsonMap['content'];
// state.genText
}
// list.setRange(1, 4, [9, 9, 9]);
// final receiveMessage = Chat.ChatMessage(
// user: receiveUser,
// createdAt: DateTime.now(),
// // id: const Uuid().v4(),
// text: "${event.data}",
// );
// _addMessage(receiveMessage);
},
);
// eventSource.onOpen.listen();
// eventSource
}
_updateMessage(String text) {
// state.messageList[0].text = state.messageList[0].text + text;
// state.messageList.forEach((element) {
// print(element.text);
// });
if (state.messageList.length == 0) {
return;
}
state.messageList.setRange(0, 1, [
ChatMessage(
user: receiveUser,
createdAt: DateTime.now(),
text: state.messageList.value[0].text + text
// user: receiveUser,
// createdAt: DateTime.now(),
// // id: const Uuid().v4(),
// text: "",
)
]);
// state.messageList.value = [...state.messageList.value];list.setRange(1, 4, [9, 9, 9]);
// state.messageList.value[0].text = state.messageList.value[0].text + text;
}
share() async {
final text =
state.messageList.reversed.map((element) => element.text).join('\n\n');
print(text);
// state.messageQueenItemQueen.map((element) => element.text).join("");
if (text.isNotEmpty) {
await Share.share(
text,
// sharePositionOrigin: box!.localToGlobal(Offset.zero) & box.size,
);
}
}
tabMessage(message) {
Clipboard.setData(ClipboardData(text: message?.text));
Get.snackbar("复制成功", "", colorText: Colors.white);
}
/// 生命周期 /// 生命周期
@override @override
void onInit() { void onInit() async {
print("initttinitttinitttinitttinitttinitttinittt"); // connect("http://example.org/events");
// http://192.168.110.127:8083/api/openAi/connect
await initEventSource();
super.onInit(); super.onInit();
ever(Get.parameters['question'].obs, (value) { // ever(Get.parameters['question'].obs, (value) {
print("messageListmessageListmessageListmessageList$value"); // print("messageListmessageListmessageListmessageList$value");
}); // });
} }
///dispose 释放内存 ///dispose 释放内存
......
...@@ -13,5 +13,10 @@ class ChatPageState { ...@@ -13,5 +13,10 @@ class ChatPageState {
final _page = "AI写作大师".obs; final _page = "AI写作大师".obs;
set page(value) => this._page.value = value; set page(value) => this._page.value = value;
get page => this._page.value; get page => this._page.value;
RxBool _isLoading = false.obs;
set isLoading(value) => _isLoading.value = value;
get isLoading => _isLoading.value;
// RxList<NewsItem> newsList = <NewsItem>[].obs; // RxList<NewsItem> newsList = <NewsItem>[].obs;
} }
...@@ -33,6 +33,23 @@ class ChatNewPage extends GetView<ChatNewController> { ...@@ -33,6 +33,23 @@ class ChatNewPage extends GetView<ChatNewController> {
// final c = Get.put(ChatNewController()); // final c = Get.put(ChatNewController());
return Obx(() => Scaffold( return Obx(() => Scaffold(
appBar: transparentAppBar( appBar: transparentAppBar(
actions: [
IconButton(
tooltip: '返回上一页',
icon: const Icon(
Icons.share,
color: AppColors.primaryElementText,
),
onPressed: () {
controller.share();
// Get.offAll(ApplicationPage());
// await Get.off(ApplicationPage());
// Get.toNamed(AppRoutes.Application);
// Navigator.of(context).pop();
//_nextPage(-1);
},
)
],
title: RichText( title: RichText(
text: TextSpan(children: [ text: TextSpan(children: [
TextSpan( TextSpan(
...@@ -74,7 +91,10 @@ class ChatNewPage extends GetView<ChatNewController> { ...@@ -74,7 +91,10 @@ class ChatNewPage extends GetView<ChatNewController> {
fit: BoxFit.cover), fit: BoxFit.cover),
), ),
child: Chat.DashChat( child: Chat.DashChat(
inputOptions: const Chat.InputOptions( inputOptions: Chat.InputOptions(
inputDisabled: controller.state.isLoading,
// controller.state.isLoading,
// alwaysShowSend: true, // alwaysShowSend: true,
// sendButtonBuilder: (send) => const Text("data"), // sendButtonBuilder: (send) => const Text("data"),
// showTraillingBeforeSend: true, // showTraillingBeforeSend: true,
...@@ -151,8 +171,9 @@ class ChatNewPage extends GetView<ChatNewController> { ...@@ -151,8 +171,9 @@ class ChatNewPage extends GetView<ChatNewController> {
// child: Text("footer")), // child: Text("footer")),
// ), // ),
messageOptions: Chat.MessageOptions( messageOptions: Chat.MessageOptions(
// containerColor: Colors.black, onPressMessage: controller.tabMessage,
), // containerColor: Colors.black,
),
), ),
// Column(children: [ // Column(children: [
......
...@@ -159,7 +159,7 @@ class PayItemWidget extends GetView<PayListController> { ...@@ -159,7 +159,7 @@ class PayItemWidget extends GetView<PayListController> {
children: [ children: [
Icon(Icons.check, color: color), Icon(Icons.check, color: color),
Text("月卡会员", Text("月卡(30天)会员",
style: TextStyle( style: TextStyle(
color: color, fontSize: 16)) color: color, fontSize: 16))
], ],
...@@ -193,7 +193,7 @@ class PayItemWidget extends GetView<PayListController> { ...@@ -193,7 +193,7 @@ class PayItemWidget extends GetView<PayListController> {
children: [ children: [
Icon(Icons.check, color: color), Icon(Icons.check, color: color),
Text("周卡会员", Text("周卡7(天)会员",
style: TextStyle( style: TextStyle(
color: color, fontSize: 16)) color: color, fontSize: 16))
], ],
...@@ -275,7 +275,7 @@ class PayItemWidget extends GetView<PayListController> { ...@@ -275,7 +275,7 @@ class PayItemWidget extends GetView<PayListController> {
color: Colors.white), color: Colors.white),
), ),
Text( Text(
"${item == 0 ? '30次提问卡' : item == 1 ? '月卡' : '周卡'}", "${item == 0 ? '30次提问卡' : item == 1 ? '月卡(30天)' : '周卡(7天)'}",
maxLines: 2, maxLines: 2,
overflow: TextOverflow.clip, overflow: TextOverflow.clip,
style: TextStyle( style: TextStyle(
......
import 'dart:convert';
import 'package:chart/common/apis/apis.dart'; import 'package:chart/common/apis/apis.dart';
import 'package:chart/common/store/user.dart'; import 'package:chart/common/store/user.dart';
import 'package:chart/common/values/values.dart';
import 'package:chart/entity/user_entity.dart';
import 'package:eventsource/eventsource.dart';
// import 'package:flutter/cupertino.dart'; // import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart'; import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:get/get_connect/http/src/utils/utils.dart'; import 'package:get/get_connect/http/src/utils/utils.dart';
import 'package:share_plus/share_plus.dart'; import 'package:share_plus/share_plus.dart';
...@@ -10,12 +16,13 @@ import 'package:get/get.dart'; ...@@ -10,12 +16,13 @@ import 'package:get/get.dart';
import 'index.dart'; import 'index.dart';
class ProductController extends GetxController { class ProductController extends GetxController {
ProductController(); static ProductController get to => Get.put(ProductController());
// ProductController();
/// 响应式成员变量 /// 响应式成员变量
final state = ProductState(); final state = ProductState();
late EventSource eventSourceConnect;
late final List<String> initDataList; late final List<String> initDataList;
TextEditingController controller1 = TextEditingController(); TextEditingController controller1 = TextEditingController();
...@@ -42,12 +49,12 @@ class ProductController extends GetxController { ...@@ -42,12 +49,12 @@ class ProductController extends GetxController {
// universalLink: "https://com.eallcn.wasp/"); // universalLink: "https://com.eallcn.wasp/");
} }
/// 生命周期
///在 widget 内存中分配后立即调用。 ///在 widget 内存中分配后立即调用。
///你可以用它来为控制器初始化 initialize 一些东西。 ///你可以用它来为控制器初始化 initialize 一些东西。
///
///
@override @override
void onInit() { void onInit() async {
_initFluwx(); _initFluwx();
super.onInit(); super.onInit();
initDataList = ["321321", '321321']; initDataList = ["321321", '321321'];
...@@ -57,19 +64,26 @@ class ProductController extends GetxController { ...@@ -57,19 +64,26 @@ class ProductController extends GetxController {
} }
share() async { share() async {
final a = if (state.inderText?.isNotEmpty) {
state.messageQueenItemQueen.map((element) => element.text).join(""); await Share.share(
await Share.share( state.inderText,
a, // sharePositionOrigin: box!.localToGlobal(Offset.zero) & box.size,
// sharePositionOrigin: box!.localToGlobal(Offset.zero) & box.size, );
); }
} }
clearState() { clearState() {
state.genText = ''; state.genText = '';
state.inderText = '';
state.messageQueenItemQueen.clear(); state.messageQueenItemQueen.clear();
} }
handleCopy() {
Clipboard.setData(ClipboardData(text: state.inderText));
Get.snackbar("复制成功", "", colorText: Colors.white);
}
void handleGenText() async { void handleGenText() async {
final params = Get.parameters; final params = Get.parameters;
...@@ -105,7 +119,7 @@ class ProductController extends GetxController { ...@@ -105,7 +119,7 @@ class ProductController extends GetxController {
// json.encode(map); // json.encode(map);
if (UserStore.to.isLogin) { if (UserStore.to.isLogin) {
String result = await NewsAPI.sendMessageByDetailId([ int result = await NewsAPI.sendMessageByDetailId([
{ {
"label": params['firstLabel'], "label": params['firstLabel'],
"value": controller1.text, "value": controller1.text,
...@@ -120,13 +134,27 @@ class ProductController extends GetxController { ...@@ -120,13 +134,27 @@ class ProductController extends GetxController {
} }
], params['detailId']!); ], params['detailId']!);
if (result == 200) {
EasyLoading.dismiss();
UserAPI.getUserInfo().then((value) async {
await UserStore.to.saveProfile(IntegralEntity(
id: UserStore.to.profile.id,
username: UserStore.to.profile.username,
token: UserStore.to.profile.token,
expireTime: value.expireTime,
integral: value.integral));
});
} else {
EasyLoading.dismiss();
}
// state.genText = result; // state.genText = result;
state.messageQueenItemQueen.add(MessageQueenItem( // state.messageQueenItemQueen.add(MessageQueenItem(
text: result.replaceAll('\n\n', ''), // text: result.replaceAll('\n\n', ''),
isFinish: false, // isFinish: false,
isWhiteIng: true)); // isWhiteIng: true));
state.isWhite = true; // state.isWhite = true;
state.loading = false; // state.loading = false;
} else { } else {
EasyLoading.showError("你还未登录,请登录后再使用"); EasyLoading.showError("你还未登录,请登录后再使用");
state.isWhite = false; state.isWhite = false;
...@@ -158,8 +186,9 @@ class ProductController extends GetxController { ...@@ -158,8 +186,9 @@ class ProductController extends GetxController {
} }
showModal() { showModal() {
print("awaitawaitawaitawaitawaitawaitawait"); // print("awaitawaitawaitawaitawaitawaitawait");
state.inderText = '';
// Share.share('Text I wish to share'); // Share.share('Text I wish to share');
Get.bottomSheet( Get.bottomSheet(
FormWidget(), FormWidget(),
...@@ -238,7 +267,6 @@ class ProductController extends GetxController { ...@@ -238,7 +267,6 @@ class ProductController extends GetxController {
///dispose 释放内存 ///dispose 释放内存
@override @override
void dispose() { void dispose() {
print("disposing");
super.dispose(); super.dispose();
// dispose 释放对象 // dispose 释放对象
} }
......
...@@ -24,6 +24,10 @@ class ProductState { ...@@ -24,6 +24,10 @@ class ProductState {
set isWhite(value) => _isWhite.value = value; set isWhite(value) => _isWhite.value = value;
get isWhite => _isWhite.value; get isWhite => _isWhite.value;
final _inderText = "".obs;
set inderText(value) => _inderText.value = value;
get inderText => _inderText.value;
RxList<MessageQueenItem> messageQueenItemQueen = <MessageQueenItem>[].obs; RxList<MessageQueenItem> messageQueenItemQueen = <MessageQueenItem>[].obs;
} }
......
This diff is collapsed.
...@@ -267,6 +267,13 @@ packages: ...@@ -267,6 +267,13 @@ packages:
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "2.0.5" version: "2.0.5"
eventsource:
dependency: "direct main"
description:
name: eventsource
url: "https://pub.dartlang.org"
source: hosted
version: "0.4.0"
extended_phone_number_input: extended_phone_number_input:
dependency: "direct main" dependency: "direct main"
description: description:
...@@ -721,6 +728,13 @@ packages: ...@@ -721,6 +728,13 @@ packages:
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "2.0.1" version: "2.0.1"
logging:
dependency: transitive
description:
name: logging
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.1"
markdown: markdown:
dependency: transitive dependency: transitive
description: description:
...@@ -1118,6 +1132,13 @@ packages: ...@@ -1118,6 +1132,13 @@ packages:
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.1.1" version: "1.1.1"
sync:
dependency: transitive
description:
name: sync
url: "https://pub.dartlang.org"
source: hosted
version: "0.3.0"
synchronized: synchronized:
dependency: transitive dependency: transitive
description: description:
......
...@@ -114,6 +114,7 @@ dependencies: ...@@ -114,6 +114,7 @@ dependencies:
alipay_kit: 5.0.0 alipay_kit: 5.0.0
alipay_kit_ios: 5.0.0 alipay_kit_ios: 5.0.0
pointycastle: ^3.1.1 pointycastle: ^3.1.1
eventsource: ^0.4.0
# package:bubble/bubble.dart # package:bubble/bubble.dart
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment