Created
July 2, 2025 07:12
-
-
Save Lxxyx/b75232063a283b84b33471539c41cab6 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: 'Music Item Card', | |
debugShowCheckedModeBanner: false, | |
theme: ThemeData( | |
colorSchemeSeed: Colors.blue, | |
), | |
home: const MyHomePage(title: 'Music Item Card'), | |
); | |
} | |
} | |
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, | |
itemBuilder: (context, index) { | |
return MusicItemCard( | |
title: 'Music Item $index', | |
artist: 'Artist $index', | |
duration: '3:45', | |
onPressed: () { | |
// Add your onPressed logic here | |
print('Music item $index pressed'); | |
}, | |
); | |
}, | |
), | |
); | |
} | |
} | |
class MusicItemCard extends StatelessWidget { | |
final String title; | |
final String artist; | |
final String duration; | |
final VoidCallback onPressed; | |
const MusicItemCard({ | |
super.key, | |
required this.title, | |
required this.artist, | |
required this.duration, | |
required this.onPressed, | |
}); | |
@override | |
Widget build(BuildContext context) { | |
return Card( | |
child: InkWell( | |
onTap: onPressed, | |
child: Padding( | |
padding: const EdgeInsets.all(16.0), | |
child: Row( | |
children: [ | |
Icon(Icons.music_note), | |
const SizedBox(width: 16), | |
Column( | |
crossAxisAlignment: CrossAxisAlignment.start, | |
children: [ | |
Text( | |
title, | |
style: Theme.of(context).textTheme.titleMedium, | |
), | |
Text( | |
artist, | |
style: Theme.of(context).textTheme.bodySmall, | |
), | |
], | |
), | |
const Spacer(), | |
Text( | |
duration, | |
style: Theme.of(context).textTheme.bodySmall, | |
), | |
], | |
), | |
), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment