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 'package:flutter/material.dart';
|
||||||
|
import '../enums/message_status.dart';
|
||||||
import '../widgets/chat_box.dart';
|
import '../widgets/chat_box.dart';
|
||||||
import '../widgets/gradient_background.dart';
|
import '../widgets/gradient_background.dart';
|
||||||
import '../services/message_service.dart';
|
import '../services/message_service.dart';
|
||||||
@@ -63,6 +66,14 @@ class _FullScreenState extends State<FullScreen> {
|
|||||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||||
_scrollToBottom();
|
_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(
|
return ChatBox(
|
||||||
scrollController: _scrollController,
|
scrollController: _scrollController,
|
||||||
messages: handler.messages,
|
messages: handler.messages,
|
||||||
|
|||||||
@@ -17,10 +17,18 @@ class PartScreen extends StatefulWidget {
|
|||||||
|
|
||||||
class _PartScreenState extends State<PartScreen> {
|
class _PartScreenState extends State<PartScreen> {
|
||||||
final ScrollController _scrollController = ScrollController();
|
final ScrollController _scrollController = ScrollController();
|
||||||
|
bool _isInitialized = false;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||||
|
final messageService = Provider.of<MessageService>(context, listen: false);
|
||||||
|
messageService.initializeEmpty();
|
||||||
|
setState(() {
|
||||||
|
_isInitialized = true;
|
||||||
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -54,6 +62,9 @@ class _PartScreenState extends State<PartScreen> {
|
|||||||
backgroundColor: Colors.transparent,
|
backgroundColor: Colors.transparent,
|
||||||
body: LayoutBuilder(
|
body: LayoutBuilder(
|
||||||
builder: (context, constraints) {
|
builder: (context, constraints) {
|
||||||
|
if (!_isInitialized) {
|
||||||
|
return const SizedBox.shrink();
|
||||||
|
}
|
||||||
final double minHeight = constraints.maxHeight * 0.18;
|
final double minHeight = constraints.maxHeight * 0.18;
|
||||||
final double maxHeight = constraints.maxHeight * 0.4;
|
final double maxHeight = constraints.maxHeight * 0.4;
|
||||||
final double chatWidth = constraints.maxWidth * 0.94;
|
final double chatWidth = constraints.maxWidth * 0.94;
|
||||||
@@ -74,9 +85,13 @@ class _PartScreenState extends State<PartScreen> {
|
|||||||
child: GestureDetector(
|
child: GestureDetector(
|
||||||
behavior: HitTestBehavior.translucent,
|
behavior: HitTestBehavior.translucent,
|
||||||
onTap: () {
|
onTap: () {
|
||||||
Provider.of<MessageService>(context, listen: false)
|
final messageService = context.read<MessageService>();
|
||||||
.abortReply();
|
|
||||||
if (widget.onHide != null) widget.onHide!();
|
if (widget.onHide != null) widget.onHide!();
|
||||||
|
setState(() {
|
||||||
|
_isInitialized = true;
|
||||||
|
});
|
||||||
|
messageService.abortReply();
|
||||||
|
messageService.initializeEmpty();
|
||||||
},
|
},
|
||||||
child: Container(
|
child: Container(
|
||||||
color: Colors.transparent,
|
color: Colors.transparent,
|
||||||
|
|||||||
@@ -34,16 +34,7 @@ class MessageService extends ChangeNotifier {
|
|||||||
TextClassificationService();
|
TextClassificationService();
|
||||||
final VehicleCommandService _vehicleCommandService = VehicleCommandService();
|
final VehicleCommandService _vehicleCommandService = VehicleCommandService();
|
||||||
|
|
||||||
final List<ChatMessage> _messages = [
|
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)
|
|
||||||
];
|
|
||||||
|
|
||||||
List<ChatMessage> get messages => List.unmodifiable(_messages);
|
List<ChatMessage> get messages => List.unmodifiable(_messages);
|
||||||
|
|
||||||
@@ -62,6 +53,11 @@ class MessageService extends ChangeNotifier {
|
|||||||
|
|
||||||
bool _isReplyAborted = true;
|
bool _isReplyAborted = true;
|
||||||
|
|
||||||
|
void initializeEmpty() {
|
||||||
|
_messages.clear();
|
||||||
|
notifyListeners();
|
||||||
|
}
|
||||||
|
|
||||||
Future<void> startVoiceInput() async {
|
Future<void> startVoiceInput() async {
|
||||||
if (await Permission.microphone.status == PermissionStatus.denied) {
|
if (await Permission.microphone.status == PermissionStatus.denied) {
|
||||||
PermissionStatus status = await Permission.microphone.request();
|
PermissionStatus status = await Permission.microphone.request();
|
||||||
|
|||||||
Reference in New Issue
Block a user