1 | // Copyright 2014 The Flutter Authors. All rights reserved. |
2 | // Use of this source code is governed by a BSD-style license that can be |
3 | // found in the LICENSE file. |
4 | |
5 | /// @docImport 'button_style.dart'; |
6 | /// @docImport 'elevated_button.dart'; |
7 | /// @docImport 'theme.dart'; |
8 | library; |
9 | |
10 | import 'package:flutter/rendering.dart'; |
11 | import 'package:flutter/widgets.dart'; |
12 | |
13 | import 'ink_well.dart'; |
14 | import 'material.dart'; |
15 | |
16 | class _NoSplashFactory extends InteractiveInkFeatureFactory { |
17 | const _NoSplashFactory(); |
18 | |
19 | @override |
20 | InteractiveInkFeature create({ |
21 | required MaterialInkController controller, |
22 | required RenderBox referenceBox, |
23 | required Offset position, |
24 | required Color color, |
25 | required TextDirection textDirection, |
26 | bool containedInkWell = false, |
27 | RectCallback? rectCallback, |
28 | BorderRadius? borderRadius, |
29 | ShapeBorder? customBorder, |
30 | double? radius, |
31 | VoidCallback? onRemoved, |
32 | }) { |
33 | return NoSplash( |
34 | controller: controller, |
35 | referenceBox: referenceBox, |
36 | color: color, |
37 | onRemoved: onRemoved, |
38 | ); |
39 | } |
40 | } |
41 | |
42 | /// An [InteractiveInkFeature] that doesn't paint a splash. |
43 | /// |
44 | /// Use [NoSplash.splashFactory] to defeat the default ink splash drawn by |
45 | /// an [InkWell] or [ButtonStyle]. For example, to create an [ElevatedButton] |
46 | /// that does not draw the default "ripple" ink splash when it's tapped: |
47 | /// |
48 | /// ```dart |
49 | /// ElevatedButton( |
50 | /// style: ElevatedButton.styleFrom( |
51 | /// splashFactory: NoSplash.splashFactory, |
52 | /// ), |
53 | /// onPressed: () { }, |
54 | /// child: const Text('No Splash'), |
55 | /// ) |
56 | /// ``` |
57 | class NoSplash extends InteractiveInkFeature { |
58 | /// Create an [InteractiveInkFeature] that doesn't paint a splash. |
59 | NoSplash({ |
60 | required super.controller, |
61 | required super.referenceBox, |
62 | required super.color, |
63 | super.onRemoved, |
64 | }); |
65 | |
66 | /// Used to specify this type of ink splash for an [InkWell], [InkResponse] |
67 | /// material [Theme], or [ButtonStyle]. |
68 | static const InteractiveInkFeatureFactory splashFactory = _NoSplashFactory(); |
69 | |
70 | @override |
71 | void paintFeature(Canvas canvas, Matrix4 transform) {} |
72 | |
73 | @override |
74 | void confirm() { |
75 | super.confirm(); |
76 | dispose(); |
77 | } |
78 | |
79 | @override |
80 | void cancel() { |
81 | super.cancel(); |
82 | dispose(); |
83 | } |
84 | } |
85 | |