如果选择了Page2,则在点击Page1 / Page3时 GestureDetector
工作正常 . 同样适用于Page3并点击Page2 / Page4 . 另外Page4并点击Page3工作正常,但是一旦选择了Page1,第2页上的点击将完全不起作用 . 我的错误在哪里或者这只是一个错误?
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home:MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatelessWidget {
MyHomePage({this.title});
final String title;
_createBox(String title, Color color) {
return Center(
child: GestureDetector(
onTap: () => print("Tapped on $title."),
child: Container(
width: 200,
height: 200,
color: color,
child: Center(
child: Text(title),
),
),
),
);
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(title),
),
body: Center(
child: Container(
width: 300,
height: 300,
color: Colors.yellow,
child: PageView(
controller: PageController(viewportFraction: 0.7),
children: <Widget>[
_createBox("Box 1", Colors.green),
_createBox("Box 2", Colors.blue),
_createBox("Box 3", Colors.green),
_createBox("Box 4", Colors.blue),
_createBox("Box 5", Colors.green),
],
),
),
),
);
}
}