Created
January 8, 2025 09:45
-
-
Save Lxxyx/7d64254b84e69e50d1a93a3c17af1fc9 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: 'Flutter Demo', | |
debugShowCheckedModeBanner: false, | |
theme: ThemeData( | |
colorSchemeSeed: Colors.blue, | |
), | |
home: const MyHomePage(title: 'Flutter Demo Home Page'), | |
); | |
} | |
} | |
class MyHomePage extends StatefulWidget { | |
final String title; | |
const MyHomePage({ | |
super.key, | |
required this.title, | |
}); | |
@override | |
State<MyHomePage> createState() => _MyHomePageState(); | |
} | |
class _MyHomePageState extends State<MyHomePage> { | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar( | |
title: Text(widget.title), | |
), | |
body: ChatList(), | |
); | |
} | |
} | |
class ChatList extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return ListView.builder( | |
itemCount: 10, | |
itemBuilder: (context, index) { | |
return ChatCard( | |
name: 'Person $index', | |
description: 'This is a chat description for person $index', | |
onPressed: () { | |
print('Pressed chat card $index'); | |
}, | |
); | |
}, | |
); | |
} | |
} | |
class ChatCard extends StatelessWidget { | |
final String name; | |
final String description; | |
final VoidCallback onPressed; | |
const ChatCard({ | |
Key? key, | |
required this.name, | |
required this.description, | |
required this.onPressed, | |
}) : super(key: key); | |
@override | |
Widget build(BuildContext context) { | |
return Card( | |
child: InkWell( | |
onTap: onPressed, | |
child: Padding( | |
padding: const EdgeInsets.all(16.0), | |
child: Row( | |
children: [ | |
CircleAvatar( | |
child: Text(name.substring(0, 1)), | |
), | |
const SizedBox(width: 16), | |
Column( | |
crossAxisAlignment: CrossAxisAlignment.start, | |
children: [ | |
Text( | |
name, | |
style: TextStyle(fontSize: 16), | |
), | |
Text( | |
description, | |
style: TextStyle(fontSize: 14, color: Colors.grey), | |
), | |
], | |
), | |
Spacer(), | |
ElevatedButton( | |
onPressed: onPressed, | |
child: Text('Link'), | |
), | |
], | |
), | |
), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment