Files
Auto-GPT/lib/views/task/task_list_tile.dart
hunteraraujo d7b6d1e49a Implement and Test Chat Input Field Widget
This commit introduces the ChatInputField widget, a custom text input field designed for use within the ChatView. The ChatInputField widget handles varying screen sizes and gracefully resizes itself according to the available width. It starts with a height of 50 and can expand up to 400 as the user types more lines of text.

In addition to the implementation, this commit also includes widget tests to ensure the ChatInputField behaves as expected.

- Add ChatInputField widget with dynamic resizing
- Include IconButton for sending messages
- Add widget tests for ChatInputField
- Handle edge cases and overflows
2023-08-24 11:55:05 -07:00

82 lines
2.5 KiB
Dart

import 'package:flutter/material.dart';
import 'package:auto_gpt_flutter_client/models/task.dart';
class TaskListTile extends StatefulWidget {
final Task task;
final VoidCallback onTap;
final VoidCallback onDelete;
const TaskListTile({
Key? key,
required this.task,
required this.onTap,
required this.onDelete,
}) : super(key: key);
@override
_TaskListTileState createState() => _TaskListTileState();
}
class _TaskListTileState extends State<TaskListTile> {
bool _isSelected = false;
@override
Widget build(BuildContext context) {
// Determine the width of the TaskView
double taskViewWidth = MediaQuery.of(context).size.width;
double tileWidth = taskViewWidth - 20;
if (tileWidth > 260) {
tileWidth = 260;
}
return GestureDetector(
onTap: () {
setState(() {
_isSelected = !_isSelected;
});
widget.onTap();
},
child: Material(
// Use a transparent color to avoid any unnecessary color overlay
color: Colors.transparent,
child: Padding(
// Provide a horizontal padding to ensure the tile does not touch the edges
padding: const EdgeInsets.symmetric(horizontal: 10.0),
child: Container(
// Width and height specifications for the tile
width: tileWidth,
height: 50,
decoration: BoxDecoration(
// Use conditional operator to determine background color based on selection
color: _isSelected ? Colors.grey[300] : Colors.white,
borderRadius: BorderRadius.circular(8.0),
),
child: Row(
children: [
// Space from the left edge of the tile
const SizedBox(width: 8),
// Message bubble icon indicating a task
const Icon(Icons.messenger_outline, color: Colors.black),
const SizedBox(width: 8),
// Task title
Expanded(
child: Text(
widget.task.title,
style: const TextStyle(color: Colors.black),
),
),
// If the task is selected, show a delete icon
if (_isSelected)
IconButton(
icon: const Icon(Icons.close, color: Colors.black),
onPressed: widget.onDelete,
),
],
),
),
),
),
);
}
}