Skip to content

Instantly share code, notes, and snippets.

@Lxxyx
Created January 7, 2025 11:09
Show Gist options
  • Save Lxxyx/25705f65f07333b9a669a01143aa47eb to your computer and use it in GitHub Desktop.
Save Lxxyx/25705f65f07333b9a669a01143aa47eb 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: 'User $index',
description: 'This is a brief introduction of user $index',
link: 'https://www.example.com/user/$index',
);
},
),
);
}
}
class ChatCard extends StatelessWidget {
final String name;
final String description;
final String link;
const ChatCard({
super.key,
required this.name,
required this.description,
required this.link,
});
@override
Widget build(BuildContext context) {
return Card(
child: InkWell(
onTap: () {
// Handle tap on card
},
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Row(
children: [
CircleAvatar(
radius: 24,
child: Text(name[0]),
),
const SizedBox(width: 16),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
name,
style: Theme.of(context).textTheme.titleMedium,
),
Text(description),
],
),
),
SizedBox(
width: 64,
child: ElevatedButton(
onPressed: () {
// Handle link button press
},
child: Text('Link'),
),
),
],
),
),
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment