Created
March 21, 2025 11:24
-
-
Save Lxxyx/a2dfe19830406c9bbbef65bf5c3e621b 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 Demo', | |
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, // replace with your chat list length | |
itemBuilder: (context, index) { | |
return ChatListItem( | |
name: 'Person $index', | |
introduction: 'This is a brief introduction of person $index', | |
linkText: 'View Profile', | |
); | |
}, | |
), | |
); | |
} | |
} | |
class ChatListItem extends StatelessWidget { | |
final String name; | |
final String introduction; | |
final String linkText; | |
const ChatListItem({ | |
super.key, | |
required this.name, | |
required this.introduction, | |
required this.linkText, | |
}); | |
@override | |
Widget build(BuildContext context) { | |
return Card( | |
child: Padding( | |
padding: const EdgeInsets.all(16.0), | |
child: Row( | |
children: [ | |
Expanded( | |
flex: 2, | |
child: Column( | |
crossAxisAlignment: CrossAxisAlignment.start, | |
children: [ | |
Text( | |
name, | |
style: Theme.of(context).textTheme.titleMedium, | |
), | |
Text( | |
introduction, | |
style: Theme.of(context).textTheme.bodySmall, | |
), | |
], | |
), | |
), | |
Expanded( | |
child: ElevatedButton( | |
onPressed: () { | |
// handle link button press | |
}, | |
child: Text(linkText), | |
), | |
), | |
], | |
), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment