Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter InkWell Hover Function

Tags:

flutter

Trying to enlarge my picture(clipped with ClipPath) using InkWell function(onHover) but when i hover picture nothing happens.

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(),
                        ),
                      )
                    ],
                  )
                ],
              ),
            ),
          ),
        );
      }
    }
like image 289
Emir Kutlugün Avatar asked Jul 09 '26 02:07

Emir Kutlugün


2 Answers

Define onTap() with onHover(). It will work:

InkWell(
onTap: (){},
onHover: (val) {
setState(() {isHover = val;
      });
  },
),
like image 146
Muhammad Ullah Avatar answered Jul 11 '26 15:07

Muhammad Ullah


Try this: dartpad link

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;
            });
          },
        ),
      ),
    );
  }
}
like image 44
M.B Avatar answered Jul 11 '26 17:07

M.B