//这是一个水平列表视图页面,点击后需要类别转到自己的页面。当点击一个类别时,它会显示所有类别的所有页面,然后在主屏幕上着陆。我怎样才能阻止这种事的发生。
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');
},
以便使其工作。页面必须命名为imageoption。在定义路由的主文件中。页面名称应声明为"/shoes":(Context(=>ShoesPage((。在onTap方法Navigator.of(context(.pushNamed("/"+image_ception(中;然后就可以工作了。