尝试使用 InkWell 函数(onHover)放大我的图片(用 ClipPath 剪辑),但是当我将鼠标悬停在图片上时没有任何反应。
InkWell(
onTap: () {},
onHover: (isHovering) {
if (isHovering) {
setState(() {
sizeBool = !sizeBool;
});
}
},
child: ClipPath(
child: AnimatedContainer(
duration: Duration(seconds: 1),
width: MediaQuery.of(context).size.width,
height: sizeBool ? 450 : 150,
child: Image.network(
'image.url',
fit: BoxFit.cover,
),
),
clipper: CustomClipPath(),
),
)
],
)
],
),
),
),
);
}
}
Run Code Online (Sandbox Code Playgroud)
小智 21
定义onTap()为onHover(). 它将起作用:
InkWell(
onTap: (){},
onHover: (val) {
setState(() {isHover = val;
});
},
),
Run Code Online (Sandbox Code Playgroud)
试试这个:dartpad 链接
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
/// This Widget is the main application widget.
class MyApp extends StatelessWidget {
static const String _title = 'Flutter Code Sample';
@override
Widget build(BuildContext context) {
return MaterialApp(
title: _title,
home: Scaffold(
appBar: AppBar(title: const Text(_title)),
body: Center(
child: MyStatefulWidget(),
),
),
);
}
}
class MyStatefulWidget extends StatefulWidget {
MyStatefulWidget({Key key}) : super(key: key);
@override
_MyStatefulWidgetState createState() => _MyStatefulWidgetState();
}
class _MyStatefulWidgetState extends State<MyStatefulWidget> {
double sideLength = 50;
Widget build(BuildContext context) {
return AnimatedContainer(
height: sideLength,
width: sideLength,
duration: Duration(seconds: 2),
curve: Curves.easeIn,
child: Material(
color: Colors.yellow,
child: InkWell(
onTap:(){},
onHover: (value) {
print(value);
setState(() {
sideLength = value?150 :50;
});
},
),
),
);
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
19236 次 |
| 最近记录: |