我曾经遇到过同样的问题,通过移除手势检测器并使用Inkwell onTap解决了它。
将这个改成:
GestureDetector(
onTap: () {
Navigator.of(context, rootNavigator: true).push(
MaterialPageRoute(
builder: (context) => ChangeNotifierProvider(
create: (BuildContext context) {
ProductViewModel();
},
child: ProductDetails(
product: _shownProduct,
),
),
),
);
},
child: InkWell(
child: Hero(
tag: _shownProduct.productID,
child: CachedNetworkImage(
fadeInDuration: Duration(milliseconds: 1),
imageUrl: _shownProduct.images[0],
imageBuilder: (context, imageProvider) => Container(
height: MediaQuery.of(context).size.flipped.height / 3.2,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(5),
image: DecorationImage(
image: imageProvider,
fit: BoxFit.cover,
),
),
),
placeholder: (context, url) => CircularProgressIndicator(
strokeWidth: 0.5,
),
errorWidget: (context, url, error) => Icon(Icons.error),
),
),
),
转译为:
InkWell(
onTap: () {
Navigator.of(context).push(
MaterialPageRoute(
builder: (context) => ProductDetails(
product: _shownProduct,
),
),
);
},
child: Hero(
tag: _shownProduct.productID,
child: CachedNetworkImage(
fadeInDuration: Duration(milliseconds: 1),
imageUrl: _shownProduct.images[0],
imageBuilder: (context, imageProvider) => Container(
height: MediaQuery.of(context).size.flipped.height / 3.2,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(5),
image: DecorationImage(
image: imageProvider,
fit: BoxFit.cover,
),
),
),
placeholder: (context, url) => CircularProgressIndicator(
strokeWidth: 0.5,
),
errorWidget: (context, url, error) => Icon(Icons.error),
),
),
),
它解决了我的问题。