update greeting
This commit is contained in:
@@ -1,4 +1,7 @@
|
||||
import 'package:ai_chat_assistant/models/chat_message.dart';
|
||||
import 'package:basic_intl/intl.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import '../enums/message_status.dart';
|
||||
import '../widgets/chat_box.dart';
|
||||
import '../widgets/gradient_background.dart';
|
||||
import '../services/message_service.dart';
|
||||
@@ -63,6 +66,14 @@ class _FullScreenState extends State<FullScreen> {
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
_scrollToBottom();
|
||||
});
|
||||
final messageService = context.read<MessageService>();
|
||||
List<ChatMessage> fullScreenMessages = List.from(handler.messages);
|
||||
if (fullScreenMessages.isEmpty) {
|
||||
String text = Intl.getCurrentLocale().startsWith('zh')
|
||||
? "您好,我是众众,请问有什么可以帮您?"
|
||||
: "Hi, I'm Zhongzhong, may I help you ? ";
|
||||
messageService.addMessage(text, false, MessageStatus.normal);
|
||||
}
|
||||
return ChatBox(
|
||||
scrollController: _scrollController,
|
||||
messages: handler.messages,
|
||||
|
||||
@@ -17,10 +17,18 @@ class PartScreen extends StatefulWidget {
|
||||
|
||||
class _PartScreenState extends State<PartScreen> {
|
||||
final ScrollController _scrollController = ScrollController();
|
||||
bool _isInitialized = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
final messageService = Provider.of<MessageService>(context, listen: false);
|
||||
messageService.initializeEmpty();
|
||||
setState(() {
|
||||
_isInitialized = true;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -54,6 +62,9 @@ class _PartScreenState extends State<PartScreen> {
|
||||
backgroundColor: Colors.transparent,
|
||||
body: LayoutBuilder(
|
||||
builder: (context, constraints) {
|
||||
if (!_isInitialized) {
|
||||
return const SizedBox.shrink();
|
||||
}
|
||||
final double minHeight = constraints.maxHeight * 0.18;
|
||||
final double maxHeight = constraints.maxHeight * 0.4;
|
||||
final double chatWidth = constraints.maxWidth * 0.94;
|
||||
@@ -74,9 +85,13 @@ class _PartScreenState extends State<PartScreen> {
|
||||
child: GestureDetector(
|
||||
behavior: HitTestBehavior.translucent,
|
||||
onTap: () {
|
||||
Provider.of<MessageService>(context, listen: false)
|
||||
.abortReply();
|
||||
final messageService = context.read<MessageService>();
|
||||
if (widget.onHide != null) widget.onHide!();
|
||||
setState(() {
|
||||
_isInitialized = true;
|
||||
});
|
||||
messageService.abortReply();
|
||||
messageService.initializeEmpty();
|
||||
},
|
||||
child: Container(
|
||||
color: Colors.transparent,
|
||||
|
||||
@@ -34,16 +34,7 @@ class MessageService extends ChangeNotifier {
|
||||
TextClassificationService();
|
||||
final VehicleCommandService _vehicleCommandService = VehicleCommandService();
|
||||
|
||||
final List<ChatMessage> _messages = [
|
||||
ChatMessage(
|
||||
id: Uuid().v1(),
|
||||
text: Intl.getCurrentLocale().startsWith('zh')
|
||||
? "您好,我是众众,请问有什么可以帮您?"
|
||||
: "Hi, I'm Zhongzhong, may I help you ? ",
|
||||
isUser: false,
|
||||
timestamp: DateTime.now(),
|
||||
status: MessageStatus.normal)
|
||||
];
|
||||
final List<ChatMessage> _messages = [];
|
||||
|
||||
List<ChatMessage> get messages => List.unmodifiable(_messages);
|
||||
|
||||
@@ -62,6 +53,11 @@ class MessageService extends ChangeNotifier {
|
||||
|
||||
bool _isReplyAborted = true;
|
||||
|
||||
void initializeEmpty() {
|
||||
_messages.clear();
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Future<void> startVoiceInput() async {
|
||||
if (await Permission.microphone.status == PermissionStatus.denied) {
|
||||
PermissionStatus status = await Permission.microphone.request();
|
||||
|
||||
Reference in New Issue
Block a user