Skip to content

Instantly share code, notes, and snippets.

@Lxxyx
Created August 29, 2024 23:05
Show Gist options
  • Save Lxxyx/d6a16a717b3cdc021fbcf88f96167a4b to your computer and use it in GitHub Desktop.
Save Lxxyx/d6a16a717b3cdc021fbcf88f96167a4b 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: 'Flutter Demo',
debugShowCheckedModeBanner: false,
theme: ThemeData(
colorSchemeSeed: Colors.blue,
),
home: const MyHomePage(title: 'Chat List'),
);
}
}
class MyHomePage extends StatelessWidget {
final String title;
const MyHomePage({
super.key,
required this.title,
});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(title),
),
body: ListView.builder(
itemCount: 10,
itemBuilder: (context, index) {
return ChatCard(
name: 'Person ${index + 1}',
description: 'This is a description for person ${index + 1}',
onPressed: () {
// Handle link button press
},
);
},
),
);
}
}
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: Padding(
padding: const EdgeInsets.all(16.0),
child: Row(
children: [
// You can add a profile picture or avatar here
const CircleAvatar(
backgroundColor: Colors.grey,
radius: 24,
),
const SizedBox(width: 16),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
name,
style: Theme.of(context).textTheme.titleMedium,
),
Text(
description,
style: Theme.of(context).textTheme.bodySmall,
),
],
),
),
ElevatedButton(
onPressed: onPressed,
child: const Text('Link'),
),
],
),
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment