Compare commits
2 Commits
4a812d1a16
...
f52dcdf657
| Author | SHA1 | Date | |
|---|---|---|---|
| f52dcdf657 | |||
| 97c6d06a8f |
24
lib/beans/EpgCategoryListBean.dart
Normal file
24
lib/beans/EpgCategoryListBean.dart
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
|
||||
part 'EpgCategoryListBean.g.dart';
|
||||
|
||||
@JsonSerializable(explicitToJson: true)
|
||||
class EpgCategoryListBean {
|
||||
|
||||
String? CategoryName;
|
||||
String? CategoryType;
|
||||
bool? HasMore;
|
||||
int? RowNum;
|
||||
bool? IsQuickStartPopUp;
|
||||
|
||||
|
||||
EpgCategoryListBean(this.CategoryName, this.CategoryType, this.HasMore,
|
||||
this.RowNum, this.IsQuickStartPopUp, );
|
||||
|
||||
factory EpgCategoryListBean.fromJson(Map<String, dynamic> json) => _$EpgCategoryListBeanFromJson(json);
|
||||
|
||||
Map<String, dynamic> toJson() => _$EpgCategoryListBeanToJson(this);
|
||||
|
||||
}
|
||||
26
lib/beans/EpgCategoryListBean.g.dart
Normal file
26
lib/beans/EpgCategoryListBean.g.dart
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'EpgCategoryListBean.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// JsonSerializableGenerator
|
||||
// **************************************************************************
|
||||
|
||||
EpgCategoryListBean _$EpgCategoryListBeanFromJson(Map<String, dynamic> json) =>
|
||||
EpgCategoryListBean(
|
||||
json['CategoryName'] as String?,
|
||||
json['CategoryType'] as String?,
|
||||
json['HasMore'] as bool?,
|
||||
(json['RowNum'] as num?)?.toInt(),
|
||||
json['IsQuickStartPopUp'] as bool?,
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$EpgCategoryListBeanToJson(
|
||||
EpgCategoryListBean instance) =>
|
||||
<String, dynamic>{
|
||||
'CategoryName': instance.CategoryName,
|
||||
'CategoryType': instance.CategoryType,
|
||||
'HasMore': instance.HasMore,
|
||||
'RowNum': instance.RowNum,
|
||||
'IsQuickStartPopUp': instance.IsQuickStartPopUp,
|
||||
};
|
||||
20
lib/beans/HallEpgListBean.dart
Normal file
20
lib/beans/HallEpgListBean.dart
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
import 'EpgCategoryListBean.dart';
|
||||
|
||||
part 'HallEpgListBean.g.dart';
|
||||
|
||||
@JsonSerializable(explicitToJson: true)
|
||||
class HallEpgListBean {
|
||||
|
||||
|
||||
List<EpgCategoryListBean>? EpgCategoryList;
|
||||
|
||||
HallEpgListBean(this.EpgCategoryList);
|
||||
|
||||
|
||||
factory HallEpgListBean.fromJson(Map<String, dynamic> json) => _$HallEpgListBeanFromJson(json);
|
||||
Map<String, dynamic> toJson() => _$HallEpgListBeanToJson(this);
|
||||
|
||||
}
|
||||
20
lib/beans/HallEpgListBean.g.dart
Normal file
20
lib/beans/HallEpgListBean.g.dart
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'HallEpgListBean.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// JsonSerializableGenerator
|
||||
// **************************************************************************
|
||||
|
||||
HallEpgListBean _$HallEpgListBeanFromJson(Map<String, dynamic> json) =>
|
||||
HallEpgListBean(
|
||||
(json['EpgCategoryList'] as List<dynamic>?)
|
||||
?.map((e) => EpgCategoryListBean.fromJson(e as Map<String, dynamic>))
|
||||
.toList(),
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$HallEpgListBeanToJson(HallEpgListBean instance) =>
|
||||
<String, dynamic>{
|
||||
'EpgCategoryList':
|
||||
instance.EpgCategoryList?.map((e) => e.toJson()).toList(),
|
||||
};
|
||||
|
|
@ -21,9 +21,7 @@ class Global {
|
|||
}
|
||||
|
||||
static Global _getInstance() {
|
||||
if (_instance == null) {
|
||||
_instance = new Global._internal();
|
||||
}
|
||||
_instance ??= Global._internal();
|
||||
return _instance!;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -13,11 +13,11 @@ Future<void> main() async {
|
|||
await runZonedGuarded(() async {
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
Global.initialize().then((e) {
|
||||
new Global();
|
||||
runApp(ChatApp());
|
||||
Global();
|
||||
runApp(const ChatApp());
|
||||
if (Platform.isAndroid) {
|
||||
// 以下两行 设置android状态栏为透明的沉浸。写在组件渲染之后,是为了在渲染后进行set赋值,覆盖状态栏,写在渲染之前MaterialApp组件会覆盖掉这个值。
|
||||
SystemUiOverlayStyle systemUiOverlayStyle = SystemUiOverlayStyle(statusBarColor: Colors.transparent);
|
||||
SystemUiOverlayStyle systemUiOverlayStyle = const SystemUiOverlayStyle(statusBarColor: Colors.transparent);
|
||||
SystemChrome.setSystemUIOverlayStyle(systemUiOverlayStyle);
|
||||
}
|
||||
});
|
||||
|
|
@ -35,26 +35,21 @@ class ChatApp extends StatefulWidget {
|
|||
|
||||
class _ChatAppState extends State<ChatApp> {
|
||||
|
||||
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
// TODO: implement initState
|
||||
super.initState();
|
||||
print("666666");
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return MaterialApp(
|
||||
title: 'AI聊天',
|
||||
home: Homepage(),
|
||||
|
||||
home: const Homepage(),
|
||||
//注册路由
|
||||
routes: <String, WidgetBuilder>{
|
||||
'/HomePage': (BuildContext context) => Homepage(),
|
||||
'/HomePage': (BuildContext context) => const Homepage(),
|
||||
},
|
||||
|
||||
debugShowMaterialGrid: false,
|
||||
//显示网格
|
||||
debugShowCheckedModeBanner: false,
|
||||
|
|
|
|||
|
|
@ -11,12 +11,11 @@ class BaseEntity {
|
|||
|
||||
// 数据解析
|
||||
factory BaseEntity.fromJson(json) {
|
||||
Map<String, dynamic> responseData = jsonDecode(json);
|
||||
int code = responseData["Code"];
|
||||
int result = responseData["Result"];
|
||||
String message = responseData["Message"]; //错误描述
|
||||
dynamic data = responseData["Data"];
|
||||
return BaseEntity(code: code, result: result, message: message, data: data);
|
||||
Map<String, dynamic> responseData = json;
|
||||
|
||||
|
||||
dynamic data = json["choices"][0]["message"]["content"];
|
||||
return BaseEntity(data: data);
|
||||
}
|
||||
|
||||
// 数据解析
|
||||
|
|
|
|||
|
|
@ -9,13 +9,13 @@ class NetworkConfig {
|
|||
static int SELECT_INDEX = 0;
|
||||
|
||||
static List BASE_URLS = [
|
||||
"http://127.0.0.1:7860/",
|
||||
"http://127.0.0.1:7860/",
|
||||
"http://127.0.0.1:7860/",
|
||||
"http://117.50.182.144:5000",
|
||||
"http://117.50.182.144:5000",
|
||||
"http://117.50.182.144:5000",
|
||||
];
|
||||
|
||||
static List BASE_URLS_AI = [
|
||||
"http://127.0.0.1:7860/",
|
||||
"http://117.50.182.144:5000",
|
||||
];
|
||||
|
||||
|
||||
|
|
@ -35,4 +35,6 @@ class NetworkConfig {
|
|||
static const String login = "login"; //登录
|
||||
|
||||
|
||||
static const String chat = "/v1/chat/completions"; //聊天
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -60,15 +60,7 @@ class RequestCenter {
|
|||
responseType: ResponseType.json));
|
||||
_dioLog!.interceptors.add(DioLogInterceptor());
|
||||
|
||||
// if (NetworkConfig.isAgent) {
|
||||
// (_dio.httpClientAdapter as DefaultHttpClientAdapter).onHttpClientCreate = (client) {
|
||||
// client.findProxy = (uri) {
|
||||
// return "PROXY 192.168.1.231:8888";
|
||||
// };
|
||||
// //抓Https包设置
|
||||
// client.badCertificateCallback = (X509Certificate cert, String host, int port) => true;
|
||||
// };
|
||||
// }
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -77,7 +69,6 @@ class RequestCenter {
|
|||
{RequestMethod? method}) async {
|
||||
Map<String, dynamic> headers = {
|
||||
"AppId": NetworkConfig.AppId,
|
||||
/*"BossId": NetworkConfig.BossId,*/
|
||||
"userId": NetworkConfig.userId,
|
||||
"Version": NetworkConfig.Version,
|
||||
"Language": NetworkConfig.Language
|
||||
|
|
@ -133,22 +124,12 @@ class RequestCenter {
|
|||
}
|
||||
|
||||
// 网络请求默认为post
|
||||
Future<BaseEntity?> request(path, Map<String, dynamic> parmeters, Function(BaseEntity dataEntity) success, Function(ErrorEntity errorEntity) error,
|
||||
Future<BaseEntity?> request(path, Object parmeters, Function(BaseEntity dataEntity) success, Function(ErrorEntity errorEntity) error,
|
||||
{RequestMethod? method}) async {
|
||||
Map<String, dynamic> headers = {
|
||||
"AppId": NetworkConfig.AppId,
|
||||
/*"BossId": NetworkConfig.BossId,*/
|
||||
"userId": NetworkConfig.userId,
|
||||
"Version": NetworkConfig.Version,
|
||||
"Language": NetworkConfig.Language
|
||||
};
|
||||
parmeters.addAll(headers);
|
||||
//签名加密
|
||||
Map<String, dynamic> parmetersSign = sign(parmeters);
|
||||
try {
|
||||
FormData formData = FormData.fromMap(parmetersSign);
|
||||
Response response = await _dio!.post(path, data: formData);
|
||||
if (response != null && response.statusCode == 200) {
|
||||
//FormData formData = FormData.fromMap(parmeters);
|
||||
Response response = await _dio!.post(path, data: parmeters);
|
||||
if (response.statusCode == 200) {
|
||||
BaseEntity entity = BaseEntity.fromJson(response.data);
|
||||
success(entity);
|
||||
return entity;
|
||||
|
|
|
|||
55
lib/tools/HomeModel.dart
Normal file
55
lib/tools/HomeModel.dart
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
import '../beans/HallEpgListBean.dart';
|
||||
import '../common/Global.dart';
|
||||
import '../network/BaseEntity.dart';
|
||||
import '../network/NetworkConfig.dart';
|
||||
import '../network/RequestCenter.dart';
|
||||
|
||||
class HomeModel {
|
||||
StreamController streamController = StreamController.broadcast();
|
||||
|
||||
HomeModel() {
|
||||
setup();
|
||||
}
|
||||
|
||||
void setup() {
|
||||
//初始化
|
||||
}
|
||||
|
||||
//首页大厅数据
|
||||
Future<void> chat(message, character) async {
|
||||
var nowTime = DateTime.now(); //获取当前时间
|
||||
var nTime = nowTime.millisecondsSinceEpoch; //单位是毫秒(千分之一秒),13位时间戳
|
||||
RequestCenter.instance.request(NetworkConfig.chat, {
|
||||
"messages": [
|
||||
{"role": "user", "content": message}
|
||||
],
|
||||
"mode": "chat",
|
||||
"character": character
|
||||
}, (BaseEntity dataEntity) {
|
||||
String json = dataEntity.data;
|
||||
|
||||
streamController.sink.add({
|
||||
'code': "chat", //有数据
|
||||
'data': json,
|
||||
});
|
||||
}, (ErrorEntity errorEntity) {
|
||||
streamController.sink.add({
|
||||
'code': "0", //无数据
|
||||
'data': errorEntity.message,
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// 获取原生的值
|
||||
invokeNativeMethod(String method, Map<String, Object> map) async {
|
||||
dynamic args;
|
||||
try {
|
||||
args = await Global.method.invokeMethod(method, map);
|
||||
} on PlatformException catch (e) {}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,4 +1,10 @@
|
|||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_easyloading/flutter_easyloading.dart';
|
||||
|
||||
import 'HomeModel.dart';
|
||||
|
||||
class Homepage extends StatefulWidget {
|
||||
const Homepage({super.key});
|
||||
|
|
@ -8,16 +14,147 @@ class Homepage extends StatefulWidget {
|
|||
}
|
||||
|
||||
class _HomepageState extends State<Homepage> {
|
||||
late StreamSubscription subscription;
|
||||
final HomeModel viewModel = HomeModel();
|
||||
final TextEditingController _controller1 = TextEditingController();
|
||||
String text = "";
|
||||
String data = '';
|
||||
Future<void> chat() async {
|
||||
viewModel.chat(text,'Assistant');
|
||||
}
|
||||
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
// TODO: implement initState
|
||||
super.initState();
|
||||
// 监听输入变化
|
||||
_controller1.addListener(() {
|
||||
print(_controller1.text);
|
||||
});
|
||||
|
||||
subscription = viewModel.streamController.stream.listen((newData) {
|
||||
String code = newData['code'];
|
||||
if (code.isNotEmpty) {
|
||||
if (code == "chat") {
|
||||
//有数据
|
||||
data = newData['data'];
|
||||
|
||||
setState(() {
|
||||
|
||||
});
|
||||
//EasyLoading.showToast(data);
|
||||
print("data" + data.toString());
|
||||
}
|
||||
} else {
|
||||
EasyLoading.dismiss();
|
||||
}
|
||||
});
|
||||
}
|
||||
void _textFieldChanged1(String str) {
|
||||
text = str;
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
// TODO: implement dispose
|
||||
subscription.cancel();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text("聊天"),
|
||||
title: const Text("聊天"),
|
||||
),
|
||||
body: Container(
|
||||
child: Text('你好'),
|
||||
child: Column(
|
||||
children: [
|
||||
Text(data),
|
||||
|
||||
Container(
|
||||
alignment: Alignment.center,
|
||||
margin: const EdgeInsets.only(top: 100),
|
||||
padding: EdgeInsets.only(left: 21),
|
||||
height: 48,
|
||||
width: MediaQuery.of(context).size.width - 60,
|
||||
decoration: new BoxDecoration(
|
||||
//设置四周圆角 角度
|
||||
borderRadius: const BorderRadius.all(Radius.circular(24.0)),
|
||||
border: Border.all(color: const Color(0xFFCACACA), width: 1),
|
||||
//设置四周边框
|
||||
),
|
||||
child: TextField(
|
||||
controller: _controller1,
|
||||
keyboardType: TextInputType.number,
|
||||
decoration: const InputDecoration.collapsed(hintText: '输入内容', hintStyle: TextStyle(fontSize: 16.0, color: Color(0xFF999999))),
|
||||
textAlign: TextAlign.left,
|
||||
//文本对齐方式
|
||||
//最大长度,设置此项会让TextField右下角有一个输入数量的统计字符串
|
||||
maxLines: 1,
|
||||
//最大行数
|
||||
style: const TextStyle(fontSize: 16.0, color: Color(0xFF999999)),
|
||||
//输入文本的样式
|
||||
onChanged: _textFieldChanged1,
|
||||
autofocus: false,
|
||||
inputFormatters: [
|
||||
LengthLimitingTextInputFormatter(255),
|
||||
//最大长度
|
||||
]),
|
||||
),
|
||||
Container(
|
||||
margin: const EdgeInsets.only(top: 17),
|
||||
height: 48,
|
||||
width: MediaQuery.of(context).size.width - 60,
|
||||
child: _LoginButton(),
|
||||
),
|
||||
|
||||
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
_LoginButton() {
|
||||
return Container(
|
||||
height: 35,
|
||||
alignment: Alignment.center,
|
||||
decoration: const BoxDecoration(
|
||||
//渐变
|
||||
gradient:
|
||||
LinearGradient(colors: [Color(0xFF52B5FF), Color(0xFF6591FB)], begin: Alignment.centerLeft, end: Alignment.centerRight),
|
||||
//设置四周圆角 角度
|
||||
borderRadius: BorderRadius.all(Radius.circular(24)),
|
||||
//设置四周边框
|
||||
),
|
||||
child: SizedBox(
|
||||
width: double.infinity,
|
||||
height: double.infinity,
|
||||
child: ElevatedButton(
|
||||
style: ButtonStyle(
|
||||
elevation: MaterialStateProperty.all(0), //阴影
|
||||
backgroundColor: MaterialStateProperty.all(Color(0x00ffffff)),
|
||||
shape: MaterialStateProperty.all(RoundedRectangleBorder(borderRadius: BorderRadius.circular(3.3))),
|
||||
//设置水波纹颜色
|
||||
overlayColor: MaterialStateProperty.all(Color(0x4fffffff)),
|
||||
),
|
||||
onPressed: () {
|
||||
chat();
|
||||
},
|
||||
child: Text(
|
||||
"调用",
|
||||
style: TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,6 +35,8 @@ dependencies:
|
|||
cupertino_icons: ^1.0.6
|
||||
flutter_easyloading: ^3.0.5
|
||||
crypto: ^3.0.3
|
||||
shared_preferences: ^2.0.7
|
||||
json_annotation: ^4.9.0
|
||||
|
||||
dev_dependencies:
|
||||
flutter_test:
|
||||
|
|
@ -46,6 +48,8 @@ dev_dependencies:
|
|||
# package. See that file for information about deactivating specific lint
|
||||
# rules and activating additional ones.
|
||||
flutter_lints: ^3.0.0
|
||||
build_runner: ^2.4.11
|
||||
json_serializable: ^6.8.0
|
||||
|
||||
# For information on the generic Dart part of this file, see the
|
||||
# following page: https://dart.dev/tools/pub/pubspec
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user