Issue
class OwnCard extends StatelessWidget {
const OwnCard({
Key? key,
}) : super(key: key);
@override
Widget build(BuildContext context) {
return Card(
child: Column(
children: [
AspectRatio(
aspectRatio: 18 / 11,
child: Image.asset('assets/diamond.png'),
),
Padding(
padding: EdgeInsets.fromLTRB(16, 12, 16, 8),
child: Column(
children: [
Text('Title'),
SizedBox(
height: 12,
),
Text('Secondary Text')
],
),
)
],
),
);
Solution
I prefer this way
class OwnCard extends StatelessWidget {
final String imagePath;
final String title;
final String secondaryText;
const OwnCard(
{Key? key,
required this.imagePath,
required this.title,
required this.secondaryText})
: super(key: key);
@override
Widget build(BuildContext context) {
return Card(
child: Column(
children: [
AspectRatio(
aspectRatio: 18 / 11,
child: Image.asset(imagePath),
),
Padding(
padding: const EdgeInsets.fromLTRB(16, 12, 16, 8),
child: Column(
children: [
Text(title),
const SizedBox(
height: 12,
),
Text(secondaryText)
],
),
)
],
),
);
}
}
Answered By – Yeasin Sheikh
Answer Checked By – Timothy Miller (FlutterFixes Admin)