UI调整,签名

This commit is contained in:
18631081161 2024-06-18 00:05:22 +08:00
parent ee6b25f9b6
commit d3113a5e64
9 changed files with 107 additions and 94 deletions

BIN
android/app/ChatApp.jks Normal file

Binary file not shown.

View File

@ -28,6 +28,16 @@ android {
compileSdk = flutter.compileSdkVersion compileSdk = flutter.compileSdkVersion
ndkVersion = flutter.ndkVersion ndkVersion = flutter.ndkVersion
signingConfigs {
//
signConfig {
storeFile file("ChatApp.jks")
storePassword '123456'
keyAlias 'ChatApp'
keyPassword '123456'
}
}
compileOptions { compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8 sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8 targetCompatibility = JavaVersion.VERSION_1_8
@ -47,8 +57,14 @@ android {
buildTypes { buildTypes {
release { release {
// TODO: Add your own signing config for the release build. // TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --release` works. signingConfig signingConfigs.signConfig //gradlew assembleRelease
signingConfig = signingConfigs.debug 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"> <manifest xmlns:android="http://schemas.android.com/apk/res/android">
<uses-permission android:name="android.permission.INTERNET" />
<application <application
android:label="Chat" android:label="Chat"
android:name="${applicationName}" android:name="${applicationName}"
android:icon="@mipmap/ic_launcher"> android:icon="@mipmap/ic_logo">
<activity <activity
android:name=".MainActivity" android:name=".MainActivity"
android:exported="true" android:exported="true"

Binary file not shown.

After

Width:  |  Height:  |  Size: 86 KiB

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

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

View File

@ -1,11 +1,9 @@
import 'dart:async'; import 'dart:async';
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 'HomeModel.dart'; import 'HomeModel.dart';
import 'Message.dart'; import 'Message.dart';
class Homepage extends StatefulWidget { class Homepage extends StatefulWidget {
@ -17,54 +15,60 @@ class Homepage extends StatefulWidget {
class _HomepageState extends State<Homepage> { class _HomepageState extends State<Homepage> {
late StreamSubscription subscription; late StreamSubscription subscription;
final HomeModel viewModel = HomeModel(); final HomeModel viewModel = HomeModel();
final TextEditingController _controller1 = TextEditingController(); final TextEditingController _chatController = TextEditingController();
final ScrollController _scrollController = ScrollController();
String text = ""; String text = "";
String data = ''; String data = '';
List<Message> list = [];
Future<void> chat() async { Future<void> chat() async {
viewModel.chat(text,'Assistant'); EasyLoading.show(status: 'loading...');
viewModel.chat(text, 'Assistant');
} }
void _textFieldChanged(String str) {
text = str;
}
@override @override
void initState() { void initState() {
// TODO: implement initState // TODO: implement initState
super.initState(); super.initState();
// //
_controller1.addListener(() { _chatController.addListener(() {
print(_controller1.text); print(_chatController.text);
}); });
subscription = viewModel.streamController.stream.listen((newData) { subscription = viewModel.streamController.stream.listen((newData) {
String code = newData['code']; String code = newData['code'];
if (code.isNotEmpty) { if (code.isNotEmpty) {
if (code == "chat") { if (code == "chat") {
// //
data = newData['data']; data = newData['data'];
list.add(Message(data, false));
setState(() { setState(() {});
Future.delayed(Duration(milliseconds: 500), () {
}); _scrollController.jumpTo(_scrollController.position.maxScrollExtent);
});
//EasyLoading.showToast(data); //EasyLoading.showToast(data);
print("data" + data.toString()); print("data" + data.toString());
} }
EasyLoading.dismiss();
} else { } else {
EasyLoading.dismiss(); EasyLoading.dismiss();
} }
}); });
} }
void _textFieldChanged1(String str) {
text = str;
}
@override @override
void dispose() { void dispose() {
// TODO: implement dispose // TODO: implement dispose
_chatController.dispose();
subscription.cancel(); subscription.cancel();
super.dispose(); super.dispose();
} }
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return Scaffold(
@ -90,6 +94,7 @@ class _HomepageState extends State<Homepage> {
alignment: Alignment.topCenter, alignment: Alignment.topCenter,
child: ListView.builder( child: ListView.builder(
// reverse: true, // reverse: true,
controller: _scrollController,
itemCount: list.length, itemCount: list.length,
itemBuilder: (Context, index) { itemBuilder: (Context, index) {
return _item(index); return _item(index);
@ -107,6 +112,7 @@ class _HomepageState extends State<Homepage> {
margin: EdgeInsets.only(left: 16), margin: EdgeInsets.only(left: 16),
child: TextField( child: TextField(
controller: _chatController, controller: _chatController,
onChanged: _textFieldChanged,
decoration: InputDecoration( decoration: InputDecoration(
border: InputBorder.none, // border: InputBorder.none, //
enabledBorder: InputBorder.none, // enabledBorder: InputBorder.none, //
@ -117,16 +123,20 @@ class _HomepageState extends State<Homepage> {
), ),
GestureDetector( GestureDetector(
onTap: () { onTap: () {
list.add(Message(chatText, true)); chat();
list.add(Message(text, true));
_chatController.clear(); _chatController.clear();
Future.delayed(Duration(milliseconds: 200), () {
_scrollController.jumpTo(_scrollController.position.maxScrollExtent);
});
setState(() {}); setState(() {});
}, },
child: Container( child: Container(
width: 70, width: 70,
height: 50, height: 50,
alignment: Alignment.center, alignment: Alignment.center,
decoration: BoxDecoration( decoration:
color: Color(0xFF006CFF), borderRadius: BorderRadius.all(Radius.circular(8.0))), BoxDecoration(color: Color(0xFF006CFF), borderRadius: BorderRadius.all(Radius.circular(8.0))),
child: Text( child: Text(
"发送", "发送",
style: TextStyle(color: Colors.white), style: TextStyle(color: Colors.white),
@ -148,25 +158,37 @@ class _HomepageState extends State<Homepage> {
child: !list[index].isMe child: !list[index].isMe
? Row( ? Row(
mainAxisAlignment: MainAxisAlignment.start, mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
Container( Container(
width: 45, width: 45,
height: 45, height: 45,
color: Color(0xFFD8D8D8), margin: EdgeInsets.only(left: 16, top: 4),
margin: EdgeInsets.only(left: 16), child: ClipRRect(
), borderRadius: BorderRadius.circular(10),
Container( child: Image(
margin: EdgeInsets.symmetric(horizontal: 16.0, vertical: 4.0), fit: BoxFit.cover,
padding: EdgeInsets.all(12.0), image: AssetImage('assets/images/avatar2.png'),
decoration: BoxDecoration( ),
color: Color(0xFFECECEC),
borderRadius: BorderRadius.circular(16.0),
), ),
child: Text( ),
list[index].text, ConstrainedBox(
style: TextStyle( constraints: BoxConstraints(
fontSize: 16, maxWidth: MediaQuery.of(context).size.width - 150, //
color: Colors.black, ),
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,
),
), ),
), ),
), ),
@ -174,27 +196,39 @@ class _HomepageState extends State<Homepage> {
) )
: Row( : Row(
mainAxisAlignment: MainAxisAlignment.end, mainAxisAlignment: MainAxisAlignment.end,
crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
Container( ConstrainedBox(
margin: EdgeInsets.symmetric(horizontal: 16.0, vertical: 4.0), constraints: BoxConstraints(
padding: EdgeInsets.all(12.0), maxWidth: MediaQuery.of(context).size.width - 150, //
decoration: BoxDecoration(
color: Color(0xFF006CFF),
borderRadius: BorderRadius.circular(16.0),
), ),
child: Text( child: Container(
list[index].text, margin: EdgeInsets.symmetric(horizontal: 16.0, vertical: 4.0),
style: TextStyle( padding: EdgeInsets.all(12.0),
fontSize: 16, decoration: BoxDecoration(
color: Colors.white, color: Color(0xFF006CFF),
borderRadius: BorderRadius.circular(16.0),
),
child: Text(
list[index].text,
style: TextStyle(
fontSize: 16,
color: Colors.white,
),
), ),
), ),
), ),
Container( Container(
width: 45, width: 45,
height: 45, height: 45,
color: Color(0xFFD8D8D8), margin: EdgeInsets.only(right: 16, top: 4),
margin: EdgeInsets.only(right: 16), child: ClipRRect(
borderRadius: BorderRadius.circular(10),
child: Image(
fit: BoxFit.cover,
image: AssetImage('assets/images/avatar1.png'),
),
),
), ),
], ],
), ),

View File

@ -42,53 +42,15 @@ dev_dependencies:
flutter_test: flutter_test:
sdk: flutter 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 flutter_lints: ^3.0.0
build_runner: ^2.4.11 build_runner: ^2.4.11
json_serializable: ^6.8.0 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: 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 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