InkWell有的叫溅墨结果,有的叫水波纹结果。行使场景是给一些无点击变乱的部件添加点击变乱时行使(也支持长按、双击等变乱),同时你也可以去修改它的颜色和外形。
- InkWell(
- borderRadius: BorderRadius.circular(8.0), // 圆角
- splashColor: Colors.transparent, // 溅墨色(波纹色)
- highlightColor: Colors.transparent, // 点击时的配景致(高亮色)
- onTap: () {},// 点击变乱
- child: Container(),
- );
不外偶然你会发明并不是包一层InkWell就必然会有溅墨结果。首要缘故起因是溅墨结果是在一个配景结果,并不是包围的远景结果。以是InkWell中的child一旦有配置配景图或配景致,那么就会遮住这个溅墨结果。假如你必要这个溅墨结果,有两种方法实现。
(1)包一层 Material,将配景致配置在 Material中的color里。
- Material(
- color: Colors.white,
- child: InkWell(),
- )
(2)行使Stack机关,将InkWell安排在上层。这种合用于给图片添加点击结果,好比Banner图的点击。
- Stack(
- children: [
- Positioned.fill(
- child: Image(),
- ),
- Positioned.fill(
- child: Material(
- color: Colors.transparent,
- child: InkWell(
- splashColor: Color(0X40FFFFFF),
- highlightColor: Colors.transparent,
- onTap: () {},
- ),
- ),
- )
- ],
- )
8.保持页面状态
好比点击导航栏往返切换页面,默认环境下会丢失原页面状态,也就是每次切换城市从头初始化页面。这种环境办理要领就是PageView与BottomNavigationBar团结行使,同时子页面State中担任AutomaticKeepAliveClientMixin并重写wantKeepAlive为true。代码大抵如下:
- class _TestState extends State with AutomaticKeepAliveClientMixin{
-
- @override
- Widget build(BuildContext context) {
- super.build(context);
- return Container();
- }
-
- @override
- bool get wantKeepAlive => true;
- }
9.依靠版本题目 (编辑:湖南网)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|