//这是点击后的水平列表视图页面,然后需要将类别转到自己的页面。单击一个类别后,它会显示所有类别的所有页面,然后再登陆到主屏幕。我该如何阻止这种情况的发生。
import 'package:flutter/material.dart';
class HorizontalList extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Container(
height: 100.0,
child: ListView(
scrollDirection: Axis.horizontal,
children: <Widget>[
// containers for categories
Category(
image_location: 'lib/images/supreme_airmax_white.jpg',
image_caption: 'shoes',
),
Category(
image_location: 'lib/images/cats/offwhite_belt_blackandyellow_accessories.jpg',
image_caption: 'accessories',
),
],
),
);
}
}
class Category extends StatelessWidget {
final String image_location;
final String image_caption;
Category({this.image_location, this.image_caption});
@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.all(2.0),
child: InkWell(
onTap: (){
//pages for categories
Category();Navigator.of(context).pushNamed('/screen5');
Category();Navigator.of(context).pushNamed('/screen6');
},
为了使它起作用。该页面必须命名为image_caption。在定义路由的主文件中。页面名称应声明为“ / shoes” :(上下文)=> ShoesPage(); 。在onTap方法中,Navigator.of(context).pushNamed(“ /” + image_caption);然后可以工作。