如何删除材质PageView组件中的splash?

时间:2018-05-29 03:45:42

标签: flutter

如何移除material PageView component中的水花? 我尝试将ThemeData的accentColorsplashColor设置为Colors.transparent,但这会导致整个应用程序出现透明的黑色闪烁。

我试图创建一个NoSplashContainer,就像这个solution一样,但是它仍然存在于孩子们的内心。

import 'package:flutter/material.dart';

class NoSplashContainer extends StatelessWidget {
  final Widget child;
  NoSplashContainer(this.child) : assert(child != null);
  @override
  Widget build(BuildContext context) {
    return (new Container(
        child: new Theme(
            data: Theme
                .of(context)
                .copyWith(splashFactory: const NoSplashFactory()),
            child: child)));
  }
}

class NoSplashFactory extends InteractiveInkFeatureFactory {
  const NoSplashFactory();

  @override
  InteractiveInkFeature create({
    @required MaterialInkController controller,
    @required RenderBox referenceBox,
    @required Offset position,
    @required Color color,
    bool containedInkWell: false,
    RectCallback rectCallback,
    BorderRadius borderRadius,
    double radius,
    VoidCallback onRemoved,
  }) {
    return new NoSplash(
      controller: controller,
      referenceBox: referenceBox,
    );
  }
}

class NoSplash extends InteractiveInkFeature {
  NoSplash({
    @required MaterialInkController controller,
    @required RenderBox referenceBox,
  })  : assert(controller != null),
        assert(referenceBox != null),
        super(
          controller: controller,
          referenceBox: referenceBox,
        );

  @override
  void paintFeature(Canvas canvas, Matrix4 transform) {}
}

我这样使用NoSplashContainer ..

new NoSplashContainer(new PageView(
   children: ...,
)));

但是PageView中仍然存在闪现。

1 个答案:

答案 0 :(得分:0)

有一个名为ThemeWidget会将主题应用于后代小部件。因此,您可以使用Theme自定义应用的任何部分,而无需修改整个应用的主题。像这样:

new Theme(
      data: Theme.of(context).copyWith(
        splashColor: Colors.transparent
      ), 
      child:....
    );