Как я могу напечатать строку ListTile
с onTap
,
В этом случае "image_caption" - это строка.
import 'package:flutter/material.dart';
class HorizontalList extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Container(
height: 85.0,
child: ListView(
scrollDirection: Axis.horizontal,
children: <Widget>[
Catagory(
image_location: 'Images/Icons/smartphone.png',
image_caption: 'Electronics',
),
Catagory(
image_location: 'Images/Icons/car.png',
image_caption: 'Vehicles',
),
Catagory(
image_location: 'Images/Icons/car.png',
image_caption: 'Vehicles',
),
Catagory(
image_location: 'Images/Icons/car.png',
image_caption: 'Vehicles',
),
Catagory(
image_location: 'Images/Icons/car.png',
image_caption: 'Vehicles',
),
],
),
);
}
}
class Catagory extends StatelessWidget {
final String image_location;
final String image_caption;
Catagory({this.image_location, this.image_caption});
@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.all(0.0),
child: GestureDetector(
onTap: () {
print("image_caption"); //Print tapped image_caption
},
child: Container(
width: 101.0,
color: Color(0xFF051622),
child: ListTile(
title: CircleAvatar(
//Circle with gold border
radius: 32.0,
backgroundColor: Color(0xFFDEB992),
child: CircleAvatar(
//Circle which containes the icon
radius: 29.0,
backgroundColor: Colors.white,
child: Image.asset(image_location),
),
),
subtitle: Container(
alignment: Alignment.topCenter,
height: 15.0,
child: Text(
image_caption,
style: TextStyle(
color: Colors.white,
),
),
),
),
),
),
);
}
}