129 lines
3.6 KiB
Dart
129 lines
3.6 KiB
Dart
import 'package:flutter/material.dart';
|
|
|
|
class ChatInput extends StatefulWidget {
|
|
final Function(String) onSend;
|
|
final bool isConnected;
|
|
final bool isLoading;
|
|
|
|
const ChatInput({
|
|
super.key,
|
|
required this.onSend,
|
|
this.isConnected = true,
|
|
this.isLoading = false,
|
|
});
|
|
|
|
@override
|
|
State<ChatInput> createState() => _ChatInputState();
|
|
}
|
|
|
|
class _ChatInputState extends State<ChatInput> {
|
|
final _controller = TextEditingController();
|
|
final _focusNode = FocusNode();
|
|
|
|
bool get _canSend =>
|
|
widget.isConnected &&
|
|
!widget.isLoading &&
|
|
_controller.text.trim().isNotEmpty;
|
|
|
|
void _send() {
|
|
if (!_canSend) return;
|
|
|
|
final text = _controller.text.trim();
|
|
_controller.clear();
|
|
widget.onSend(text);
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
_controller.dispose();
|
|
_focusNode.dispose();
|
|
super.dispose();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Container(
|
|
padding: EdgeInsets.only(
|
|
left: 12,
|
|
right: 12,
|
|
top: 8,
|
|
bottom: MediaQuery.of(context).padding.bottom + 8,
|
|
),
|
|
decoration: BoxDecoration(
|
|
color: const Color(0xFF1A1A1A),
|
|
border: Border(
|
|
top: BorderSide(color: Colors.grey.shade800),
|
|
),
|
|
),
|
|
child: Row(
|
|
crossAxisAlignment: CrossAxisAlignment.end,
|
|
children: [
|
|
// Input field
|
|
Expanded(
|
|
child: Container(
|
|
constraints: const BoxConstraints(maxHeight: 120),
|
|
decoration: BoxDecoration(
|
|
color: const Color(0xFF2D2D2D),
|
|
borderRadius: BorderRadius.circular(24),
|
|
border: Border.all(
|
|
color: widget.isConnected
|
|
? Colors.grey.shade700
|
|
: Colors.red.shade700,
|
|
),
|
|
),
|
|
child: TextField(
|
|
controller: _controller,
|
|
focusNode: _focusNode,
|
|
maxLines: null,
|
|
textInputAction: TextInputAction.newline,
|
|
onChanged: (_) => setState(() {}),
|
|
style: const TextStyle(
|
|
color: Colors.white,
|
|
fontSize: 15,
|
|
),
|
|
decoration: InputDecoration(
|
|
hintText: widget.isConnected
|
|
? 'Message Claude...'
|
|
: 'Disconnected',
|
|
hintStyle: TextStyle(
|
|
color: Colors.grey.shade500,
|
|
),
|
|
contentPadding: const EdgeInsets.symmetric(
|
|
horizontal: 16,
|
|
vertical: 12,
|
|
),
|
|
border: InputBorder.none,
|
|
),
|
|
),
|
|
),
|
|
),
|
|
const SizedBox(width: 8),
|
|
// Send button
|
|
Container(
|
|
decoration: BoxDecoration(
|
|
color: _canSend ? Colors.orange.shade700 : Colors.grey.shade800,
|
|
shape: BoxShape.circle,
|
|
),
|
|
child: IconButton(
|
|
onPressed: _canSend ? _send : null,
|
|
icon: widget.isLoading
|
|
? SizedBox(
|
|
width: 20,
|
|
height: 20,
|
|
child: CircularProgressIndicator(
|
|
strokeWidth: 2,
|
|
color: Colors.grey.shade400,
|
|
),
|
|
)
|
|
: Icon(
|
|
Icons.send,
|
|
color: _canSend ? Colors.white : Colors.grey.shade600,
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|