Closed Mduardar27 closed 1 month ago
Código
Base ( sem estilização e correção de erros extras):
`import 'package:flutter/material.dart';
void main() { runApp(ChatApp()); }
class ChatApp extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( title: 'Chat App', theme: ThemeData( primarySwatch: Colors.blue, ), home: ConversationListScreen(), ); } }
class Conversation { final String name; final String lastMessage; final DateTime timestamp;
Conversation({required this.name, required this.lastMessage, required this.timestamp}); }
class ConversationListScreen extends StatefulWidget { @override _ConversationListScreenState createState() => _ConversationListScreenState(); }
class _ConversationListScreenState extends State
List
@override void initState() { super.initState(); _filteredConversations = _conversations; _searchController.addListener(_filterConversations); }
void _filterConversations() { final query = _searchController.text.toLowerCase(); setState(() { _filteredConversations = _conversations.where((conversation) { return conversation.name.toLowerCase().contains(query); }).toList(); }); }
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Conversas'),
),
body: Column(
children:
class ChatScreen extends StatelessWidget { final Conversation conversation;
ChatScreen({required this.conversation});
@override
Widget build(BuildContext context) {
final TextEditingController _messageController = TextEditingController();
final List
void _sendMessage() {
if (_messageController.text.isNotEmpty) {
_messages.add(_messageController.text);
_messageController.clear();
}
}
return Scaffold(
appBar: AppBar(
title: Text(conversation.name),
),
body: Column(
children: <Widget>[
Expanded(
child: ListView.builder(
itemCount: _messages.length,
itemBuilder: (context, index) {
return ListTile(
title: Text(_messages[index]),
);
},
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: Row(
children: <Widget>[
Expanded(
child: TextField(
controller: _messageController,
decoration: InputDecoration(
hintText: 'Enviar mensagem',
),
),
),
IconButton(
icon: Icon(Icons.send),
onPressed: _sendMessage,
),
],
),
),
],
),
);
} } `
_AFAZERES:__