Skip to content

Instantly share code, notes, and snippets.

@Lxxyx
Created February 16, 2025 12:16
Show Gist options
  • Save Lxxyx/2418a0085a886d88cc8841bfa251f921 to your computer and use it in GitHub Desktop.
Save Lxxyx/2418a0085a886d88cc8841bfa251f921 to your computer and use it in GitHub Desktop.
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: 'Person $index',
description: 'This is a description of person $index',
onTap: () {
// Handle tap on the chat card
},
);
},
),
);
}
}
class ChatCard extends StatelessWidget {
final String name;
final String description;
final VoidCallback onTap;
const ChatCard({
super.key,
required this.name,
required this.description,
required this.onTap,
});
@override
Widget build(BuildContext context) {
return Card(
child: InkWell(
onTap: onTap,
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Row(
children: [
CircleAvatar(
radius: 24,
backgroundImage: NetworkImage('https://via.placeholder.com/50'),
),
const SizedBox(width: 16),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
name,
style: Theme.of(context).textTheme.titleMedium,
),
Text(
description,
style: Theme.of(context).textTheme.bodySmall,
),
],
),
Spacer(),
ElevatedButton(
onPressed: onTap,
child: const Text('Chat'),
),
],
),
),
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment