From 5d6707b78e844218f12f75e40d7d3679b002640a Mon Sep 17 00:00:00 2001 From: liyuqian Date: Fri, 24 Aug 2018 13:53:54 -0700 Subject: [PATCH] Expose clipBehavior to more buttons (#20538) This allows developers to control the clipBehavior of those buttons. --- packages/flutter/lib/src/material/flat_button.dart | 13 +++++++++++-- .../lib/src/material/floating_action_button.dart | 11 +++++++++-- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/packages/flutter/lib/src/material/flat_button.dart b/packages/flutter/lib/src/material/flat_button.dart index a816abd923..5c58f5a05b 100644 --- a/packages/flutter/lib/src/material/flat_button.dart +++ b/packages/flutter/lib/src/material/flat_button.dart @@ -38,6 +38,8 @@ import 'theme_data.dart'; /// Flat buttons have a minimum size of 88.0 by 36.0 which can be overidden /// with [ButtonTheme]. /// +/// The [clipBehavior] argument must not be null. +/// /// See also: /// /// * [RaisedButton], a filled button whose material elevates when pressed. @@ -63,9 +65,10 @@ class FlatButton extends StatelessWidget { this.colorBrightness, this.padding, this.shape, + this.clipBehavior = Clip.none, this.materialTapTargetSize, @required this.child, - }) : super(key: key); + }) : assert(clipBehavior != null), super(key: key); /// Create a text button from a pair of widgets that serve as the button's /// [icon] and [label]. @@ -73,7 +76,7 @@ class FlatButton extends StatelessWidget { /// The icon and label are arranged in a row and padded by 12 logical pixels /// at the start, and 16 at the end, with an 8 pixel gap in between. /// - /// The [icon] and [label] arguments must not be null. + /// The [icon], [label], and [clipBehavior] arguments must not be null. FlatButton.icon({ Key key, @required this.onPressed, @@ -87,11 +90,13 @@ class FlatButton extends StatelessWidget { this.splashColor, this.colorBrightness, this.shape, + this.clipBehavior = Clip.none, this.materialTapTargetSize, @required Widget icon, @required Widget label, }) : assert(icon != null), assert(label != null), + assert(clipBehavior != null), padding = const EdgeInsetsDirectional.only(start: 12.0, end: 16.0), child = new Row( mainAxisSize: MainAxisSize.min, @@ -221,6 +226,9 @@ class FlatButton extends StatelessWidget { /// shape as well. final ShapeBorder shape; + /// {@macro flutter.widgets.Clip} + final Clip clipBehavior; + Brightness _getBrightness(ThemeData theme) { return colorBrightness ?? theme.brightness; } @@ -306,6 +314,7 @@ class FlatButton extends StatelessWidget { padding: padding ?? buttonTheme.padding, constraints: buttonTheme.constraints, shape: shape ?? buttonTheme.shape, + clipBehavior: clipBehavior, child: child, ); } diff --git a/packages/flutter/lib/src/material/floating_action_button.dart b/packages/flutter/lib/src/material/floating_action_button.dart index 9c492eeaa9..5a43297cd2 100644 --- a/packages/flutter/lib/src/material/floating_action_button.dart +++ b/packages/flutter/lib/src/material/floating_action_button.dart @@ -57,7 +57,7 @@ class _DefaultHeroTag { class FloatingActionButton extends StatefulWidget { /// Creates a circular floating action button. /// - /// The [elevation], [highlightElevation], [mini], and [shape] + /// The [elevation], [highlightElevation], [mini], [shape], and [clipBehavior] /// arguments must not be null. const FloatingActionButton({ Key key, @@ -71,6 +71,7 @@ class FloatingActionButton extends StatefulWidget { @required this.onPressed, this.mini = false, this.shape = const CircleBorder(), + this.clipBehavior = Clip.none, this.materialTapTargetSize, this.isExtended = false, }) : assert(elevation != null), @@ -84,7 +85,7 @@ class FloatingActionButton extends StatefulWidget { /// Creates a wider [StadiumBorder] shaped floating action button with both /// an [icon] and a [label]. /// - /// The [label], [icon], [elevation], [highlightElevation] + /// The [label], [icon], [elevation], [highlightElevation], [clipBehavior] /// and [shape] arguments must not be null. FloatingActionButton.extended({ Key key, @@ -98,12 +99,14 @@ class FloatingActionButton extends StatefulWidget { this.shape = const StadiumBorder(), this.isExtended = true, this.materialTapTargetSize, + this.clipBehavior = Clip.none, @required Widget icon, @required Widget label, }) : assert(elevation != null), assert(highlightElevation != null), assert(shape != null), assert(isExtended != null), + assert(clipBehavior != null), _sizeConstraints = _kExtendedSizeConstraints, mini = false, child = new _ChildOverflowBox( @@ -193,6 +196,9 @@ class FloatingActionButton extends StatefulWidget { /// shape as well. final ShapeBorder shape; + /// {@macro flutter.widgets.Clip} + final Clip clipBehavior; + /// True if this is an "extended" floating action button. /// /// Typically [extended] buttons have a [StadiumBorder] [shape] @@ -265,6 +271,7 @@ class _FloatingActionButtonState extends State { letterSpacing: 1.2, ), shape: widget.shape, + clipBehavior: widget.clipBehavior, child: result, );