dart - Flutter InkResponse splash migrates to the center when containedInkWell is set true - Stack Overflow

Here is a simple flutter code:Widget build(BuildContext context) {return Scaffold(body: Center(child: S

Here is a simple flutter code:

  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: SizedBox(
          width: 600,
          height: 400,
          child: Material(
            color: Colors.amber,
            child: InkResponse(
              containedInkWell: true,
              splashColor: Colors.blue.shade500,
              radius: 40,
              onTap: () {},
            ),
          ),
        ),
      ),
    );

The output is

As per the containedInkWell docs

This flag also controls whether the splash migrates to the center of the InkResponse or not. If containedInkWell is true, the splash remains centered around the tap location. If it is false, the splash migrates to the center of the InkResponse as it grows.

So, the blue splash must grow and not migrate to the center as the the above code. However, the splash always migrates to the center whether containedInkWell is set true or false

Here is a simple flutter code:

  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: SizedBox(
          width: 600,
          height: 400,
          child: Material(
            color: Colors.amber,
            child: InkResponse(
              containedInkWell: true,
              splashColor: Colors.blue.shade500,
              radius: 40,
              onTap: () {},
            ),
          ),
        ),
      ),
    );

The output is

As per the containedInkWell docs

This flag also controls whether the splash migrates to the center of the InkResponse or not. If containedInkWell is true, the splash remains centered around the tap location. If it is false, the splash migrates to the center of the InkResponse as it grows.

So, the blue splash must grow and not migrate to the center as the the above code. However, the splash always migrates to the center whether containedInkWell is set true or false

Share Improve this question asked Nov 16, 2024 at 4:54 AnonymousAnonymous 3672 silver badges13 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

I explored this widget's functionality and experimented with its properties. I believe I have found a solution that aligns with what you're looking for. I hope this meets your requirements

 class NoRadiusInkSplashFactory extends InteractiveInkFeatureFactory {
  @override
  InteractiveInkFeature create({
    required MaterialInkController controller,
    required RenderBox referenceBox,
    required Offset position,
    required Color color,
    required TextDirection textDirection,
    bool containedInkWell = false,
    RectCallback? rectCallback,
    BorderRadius? borderRadius,
    ShapeBorder? customBorder,
    double? radius,
    VoidCallback? onRemoved,
  }) {
   return InkSplash(
  controller: controller,
  referenceBox: referenceBox,
  position: position,
  color: color,
  containedInkWell: true, // chnage this to false
  rectCallback: rectCallback,
  borderRadius: borderRadius,
  customBorder: customBorder,
  radius: 40,
  onRemoved: onRemoved,
  textDirection: textDirection,
);
  }
}

class SplashScreen extends StatelessWidget {
  const SplashScreen({super.key});

  @override
   Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: SizedBox(
        width: 600,
      height: 400,
      child: Material(
        color: Colors.amber,
        child: InkWell(
          splashFactory: NoRadiusInkSplashFactory(),
          splashColor: Colors.blue.shade500,
          onTap: () {},
        ),
      ),
    ),
  ),
);
}
}

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745665109a4639074.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信