Skip to content

Instantly share code, notes, and snippets.

@Lxxyx
Created January 8, 2025 09:43
Show Gist options
  • Save Lxxyx/52b0b98718e8fa7b3a4715071def8ead to your computer and use it in GitHub Desktop.
Save Lxxyx/52b0b98718e8fa7b3a4715071def8ead 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: 'Chat List Demo',
debugShowCheckedModeBanner: false,
theme: ThemeData(
colorSchemeSeed: Colors.blue,
),
home: const MyHomePage(title: 'Chat List Demo'),
);
}
}
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: ListView.builder(
itemCount: 10, // number of chat items
itemBuilder: (context, index) {
return ChatItem(
name: 'Person $index',
introduction: 'This is person $index\'s introduction',
link: 'https://example.com/$index',
);
},
),
);
}
}
class ChatItem extends StatelessWidget {
final String name;
final String introduction;
final String link;
const ChatItem({
super.key,
required this.name,
required this.introduction,
required this.link,
});
@override
Widget build(BuildContext context) {
return Card(
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
name,
style: Theme.of(context).textTheme.titleMedium,
),
Text(
introduction,
style: Theme.of(context).textTheme.bodySmall,
),
],
),
Spacer(),
OutlinedButton(
onPressed: () {
// navigate to the link
print('Navigating to $link');
},
child: Text('Link'),
),
],
),
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment