Compare commits

...

3 Commits

Author SHA1 Message Date
d3113a5e64 UI调整,签名 2024-06-18 00:05:22 +08:00
ee6b25f9b6 Merge remote-tracking branch 'origin/main'
# Conflicts:
#	lib/main.dart
#	lib/tools/HomePage.dart
2024-06-15 14:45:15 +08:00
8db843fd55 聊天界面 2024-06-15 14:38:50 +08:00
12 changed files with 207 additions and 140 deletions

BIN
android/app/ChatApp.jks Normal file

Binary file not shown.

View File

@ -28,6 +28,16 @@ android {
compileSdk = flutter.compileSdkVersion
ndkVersion = flutter.ndkVersion
signingConfigs {
//
signConfig {
storeFile file("ChatApp.jks")
storePassword '123456'
keyAlias 'ChatApp'
keyPassword '123456'
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
@ -47,8 +57,14 @@ android {
buildTypes {
release {
// TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --release` works.
signingConfig = signingConfigs.debug
signingConfig signingConfigs.signConfig //gradlew assembleRelease
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
//
minifyEnabled false //
shrinkResources false //
}
debug {
signingConfig signingConfigs.signConfig
}
}
}

View File

@ -1,8 +1,11 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<uses-permission android:name="android.permission.INTERNET" />
<application
android:label="Chat"
android:name="${applicationName}"
android:icon="@mipmap/ic_launcher">
android:icon="@mipmap/ic_logo">
<activity
android:name=".MainActivity"
android:exported="true"

Binary file not shown.

After

Width:  |  Height:  |  Size: 86 KiB

View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="Test">#D8D8D8</color>
</resources>

BIN
assets/images/avatar1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 278 KiB

BIN
assets/images/avatar2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 286 KiB

View File

@ -39,6 +39,7 @@ class _ChatAppState extends State<ChatApp> {
void initState() {
// TODO: implement initState
super.initState();
}
@override

View File

@ -25,9 +25,7 @@ class HomeModel {
var nowTime = DateTime.now(); //
var nTime = nowTime.millisecondsSinceEpoch; //()13
RequestCenter.instance.request(NetworkConfig.chat, {
"messages": [
{"role": "user", "content": message}
],
"messages": [{"role": "user", "content": message}],
"mode": "chat",
"character": character
}, (BaseEntity dataEntity) {

View File

@ -1,10 +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';
import 'Message.dart';
class Homepage extends StatefulWidget {
const Homepage({super.key});
@ -15,146 +15,223 @@ class Homepage extends StatefulWidget {
class _HomepageState extends State<Homepage> {
late StreamSubscription subscription;
final HomeModel viewModel = HomeModel();
final TextEditingController _controller1 = TextEditingController();
final HomeModel viewModel = HomeModel();
final TextEditingController _chatController = TextEditingController();
final ScrollController _scrollController = ScrollController();
String text = "";
String data = '';
List<Message> list = [];
Future<void> chat() async {
viewModel.chat(text,'Assistant');
EasyLoading.show(status: 'loading...');
viewModel.chat(text, 'Assistant');
}
void _textFieldChanged(String str) {
text = str;
}
@override
void initState() {
// TODO: implement initState
super.initState();
//
_controller1.addListener(() {
print(_controller1.text);
_chatController.addListener(() {
print(_chatController.text);
});
subscription = viewModel.streamController.stream.listen((newData) {
String code = newData['code'];
if (code.isNotEmpty) {
if (code == "chat") {
if (code == "chat") {
//
data = newData['data'];
setState(() {
});
data = newData['data'];
list.add(Message(data, false));
setState(() {});
Future.delayed(Duration(milliseconds: 500), () {
_scrollController.jumpTo(_scrollController.position.maxScrollExtent);
});
//EasyLoading.showToast(data);
print("data" + data.toString());
}
EasyLoading.dismiss();
} else {
EasyLoading.dismiss();
}
});
}
void _textFieldChanged1(String str) {
text = str;
}
@override
void dispose() {
// TODO: implement dispose
_chatController.dispose();
subscription.cancel();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text("聊天"),
),
backgroundColor: Colors.white,
appBar: AppBar(
title: Text(
"王梦阳",
style: TextStyle(fontSize: 18),
),
backgroundColor: Colors.white,
centerTitle: true,
),
body: Container(
child: Column(
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),
//
width: double.infinity,
height: 1,
color: Color(0xFFDFDFDF),
),
Expanded(
child: Container(
alignment: Alignment.topCenter,
child: ListView.builder(
// reverse: true,
controller: _scrollController,
itemCount: list.length,
itemBuilder: (Context, index) {
return _item(index);
}),
)),
Card(
elevation: 5,
color: Colors.white,
margin: EdgeInsets.only(left: 16, right: 16, bottom: 30),
child: Row(
children: [
//
Expanded(
child: Container(
margin: EdgeInsets.only(left: 16),
child: TextField(
controller: _chatController,
onChanged: _textFieldChanged,
decoration: InputDecoration(
border: InputBorder.none, //
enabledBorder: InputBorder.none, //
focusedBorder: InputBorder.none, //
),
),
),
),
GestureDetector(
onTap: () {
chat();
list.add(Message(text, true));
_chatController.clear();
Future.delayed(Duration(milliseconds: 200), () {
_scrollController.jumpTo(_scrollController.position.maxScrollExtent);
});
setState(() {});
},
child: Container(
width: 70,
height: 50,
alignment: Alignment.center,
decoration:
BoxDecoration(color: Color(0xFF006CFF), borderRadius: BorderRadius.all(Radius.circular(8.0))),
child: Text(
"发送",
style: TextStyle(color: Colors.white),
),
),
)
],
),
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,
_item(index) {
return Padding(
padding: EdgeInsets.symmetric(vertical: 8.0),
child: !list[index].isMe
? Row(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
width: 45,
height: 45,
margin: EdgeInsets.only(left: 16, top: 4),
child: ClipRRect(
borderRadius: BorderRadius.circular(10),
child: Image(
fit: BoxFit.cover,
image: AssetImage('assets/images/avatar2.png'),
),
),
),
ConstrainedBox(
constraints: BoxConstraints(
maxWidth: MediaQuery.of(context).size.width - 150, //
),
child: Container(
margin: EdgeInsets.symmetric(horizontal: 16.0, vertical: 4.0),
padding: EdgeInsets.all(12.0),
decoration: BoxDecoration(
color: Color(0xFFECECEC),
borderRadius: BorderRadius.circular(16.0),
),
child: Text(
list[index].text,
style: TextStyle(
fontSize: 16,
color: Colors.black,
),
),
),
),
],
)
: Row(
mainAxisAlignment: MainAxisAlignment.end,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
ConstrainedBox(
constraints: BoxConstraints(
maxWidth: MediaQuery.of(context).size.width - 150, //
),
child: Container(
margin: EdgeInsets.symmetric(horizontal: 16.0, vertical: 4.0),
padding: EdgeInsets.all(12.0),
decoration: BoxDecoration(
color: Color(0xFF006CFF),
borderRadius: BorderRadius.circular(16.0),
),
child: Text(
list[index].text,
style: TextStyle(
fontSize: 16,
color: Colors.white,
),
),
),
),
Container(
width: 45,
height: 45,
margin: EdgeInsets.only(right: 16, top: 4),
child: ClipRRect(
borderRadius: BorderRadius.circular(10),
child: Image(
fit: BoxFit.cover,
image: AssetImage('assets/images/avatar1.png'),
),
),
),
],
),
),
),
),
);
}
}

6
lib/tools/Message.dart Normal file
View File

@ -0,0 +1,6 @@
class Message{
final String text;
final bool isMe;
Message(this.text, this.isMe);
}

View File

@ -42,53 +42,15 @@ dev_dependencies:
flutter_test:
sdk: flutter
# The "flutter_lints" package below contains a set of recommended lints to
# encourage good coding practices. The lint set provided by the package is
# activated in the `analysis_options.yaml` file located at the root of your
# 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
# The following section is specific to Flutter packages.
flutter:
# The following line ensures that the Material Icons font is
# included with your application, so that you can use the icons in
# the material Icons class.
uses-material-design: true
assets:
- assets/
- assets/images/
# To add assets to your application, add an assets section, like this:
# assets:
# - images/a_dot_burr.jpeg
# - images/a_dot_ham.jpeg
# An image asset can refer to one or more resolution-specific "variants", see
# https://flutter.dev/assets-and-images/#resolution-aware
# For details regarding adding assets from package dependencies, see
# https://flutter.dev/assets-and-images/#from-packages
# To add custom fonts to your application, add a fonts section here,
# in this "flutter" section. Each entry in this list should have a
# "family" key with the font family name, and a "fonts" key with a
# list giving the asset and other descriptors for the font. For
# example:
# fonts:
# - family: Schyler
# fonts:
# - asset: fonts/Schyler-Regular.ttf
# - asset: fonts/Schyler-Italic.ttf
# style: italic
# - family: Trajan Pro
# fonts:
# - asset: fonts/TrajanPro.ttf
# - asset: fonts/TrajanPro_Bold.ttf
# weight: 700
#
# For details regarding fonts from package dependencies,
# see https://flutter.dev/custom-fonts/#from-packages