Created
January 8, 2025 10:27
-
-
Save Lxxyx/97663b22e9dffee632282f26f5f2d736 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 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, // assuming you have 10 chat items | |
itemBuilder: (context, index) { | |
return ChatItem( | |
name: 'Person $index', | |
introduction: 'This is a brief introduction about person $index', | |
onPressed: () { | |
print('Button $index pressed'); | |
}, | |
); | |
}, | |
), | |
); | |
} | |
} | |
class ChatItem extends StatelessWidget { | |
final String name; | |
final String introduction; | |
final VoidCallback onPressed; | |
const ChatItem({ | |
super.key, | |
required this.name, | |
required this.introduction, | |
required this.onPressed, | |
}); | |
@override | |
Widget build(BuildContext context) { | |
return Card( | |
child: Padding( | |
padding: const EdgeInsets.all(16.0), | |
child: Column( | |
crossAxisAlignment: CrossAxisAlignment.start, | |
children: [ | |
Text( | |
name, | |
style: Theme.of(context).textTheme.titleMedium, | |
), | |
Text( | |
introduction, | |
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