Created
February 16, 2025 12:16
-
-
Save Lxxyx/a99053ba236c2eed0ef7f44429656dd2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
void main() => runApp(const MyApp()); | |
class MyApp extends StatelessWidget { | |
const MyApp({super.key}); | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
title: 'Chat List', | |
debugShowCheckedModeBanner: false, | |
theme: ThemeData( | |
colorSchemeSeed: Colors.blue, | |
), | |
home: const ChatListPage(), | |
); | |
} | |
} | |
class ChatListPage extends StatelessWidget { | |
const ChatListPage({super.key}); | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar( | |
title: const Text('Chat List'), | |
), | |
body: ListView.builder( | |
itemCount: 10, | |
itemBuilder: (context, index) { | |
return ChatCard( | |
name: 'User $index', | |
description: 'This is a chat with User $index', | |
onPressed: () { | |
print('Chat with User $index'); | |
}, | |
); | |
}, | |
), | |
); | |
} | |
} | |
class ChatCard extends StatelessWidget { | |
final String name; | |
final String description; | |
final VoidCallback onPressed; | |
const ChatCard({ | |
super.key, | |
required this.name, | |
required this.description, | |
required this.onPressed, | |
}); | |
@override | |
Widget build(BuildContext context) { | |
return Card( | |
child: InkWell( | |
onTap: onPressed, | |
child: Padding( | |
padding: const EdgeInsets.all(16.0), | |
child: Row( | |
children: [ | |
const CircleAvatar( | |
radius: 24, | |
backgroundImage: NetworkImage( | |
'https://via.placeholder.com/50', | |
), | |
), | |
const SizedBox(width: 16), | |
Expanded( | |
child: Column( | |
crossAxisAlignment: CrossAxisAlignment.start, | |
children: [ | |
Text( | |
name, | |
style: Theme.of(context).textTheme.bodyLarge, | |
), | |
Text( | |
description, | |
style: Theme.of(context).textTheme.bodySmall, | |
), | |
], | |
), | |
), | |
ElevatedButton( | |
onPressed: onPressed, | |
child: const Text('Chat'), | |
), | |
], | |
), | |
), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment