elevated_button.dart 23 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'dart:math' as math;
import 'dart:ui' show lerpDouble;

import 'package:flutter/foundation.dart';
import 'package:flutter/widgets.dart';

import 'button_style.dart';
import 'button_style_button.dart';
import 'color_scheme.dart';
import 'constants.dart';
15
import 'elevated_button_theme.dart';
16 17
import 'ink_ripple.dart';
import 'ink_well.dart';
18 19 20 21
import 'material_state.dart';
import 'theme.dart';
import 'theme_data.dart';

22
/// A Material Design "elevated button".
23
///
24
/// Use elevated buttons to add dimension to otherwise mostly flat
25
/// layouts, e.g. in long busy lists of content, or in wide
26
/// spaces. Avoid using elevated buttons on already-elevated content
27 28
/// such as dialogs or cards.
///
29
/// An elevated button is a label [child] displayed on a [Material]
30 31
/// widget whose [Material.elevation] increases when the button is
/// pressed. The label's [Text] and [Icon] widgets are displayed in
32
/// [style]'s [ButtonStyle.foregroundColor] and the button's filled
33 34
/// background is the [ButtonStyle.backgroundColor].
///
35
/// The elevated button's default style is defined by
36
/// [defaultStyleOf]. The style of this elevated button can be
37
/// overridden with its [style] parameter. The style of all elevated
38
/// buttons in a subtree can be overridden with the
39
/// [ElevatedButtonTheme], and the style of all of the elevated
40
/// buttons in an app can be overridden with the [Theme]'s
41
/// [ThemeData.elevatedButtonTheme] property.
42 43
///
/// The static [styleFrom] method is a convenient way to create a
44
/// elevated button [ButtonStyle] from simple values.
45 46 47 48
///
/// If [onPressed] and [onLongPress] callbacks are null, then the
/// button will be disabled.
///
49
/// {@tool dartpad}
50 51
/// This sample produces an enabled and a disabled ElevatedButton.
///
52
/// ** See code in examples/api/lib/material/elevated_button/elevated_button.0.dart **
53 54
/// {@end-tool}
///
55 56
/// See also:
///
57 58 59 60
///  * [FilledButton], a filled button that doesn't elevate when pressed.
///  * [FilledButton.tonal], a filled button variant that uses a secondary fill color.
///  * [OutlinedButton], a button with an outlined border and no fill color.
///  * [TextButton], a button with no outline or fill color.
61
///  * <https://material.io/design/components/buttons.html>
62
///  * <https://m3.material.io/components/buttons>
63 64
class ElevatedButton extends ButtonStyleButton {
  /// Create an ElevatedButton.
65 66
  ///
  /// The [autofocus] and [clipBehavior] arguments must not be null.
67
  const ElevatedButton({
68 69 70 71 72 73 74 75 76
    super.key,
    required super.onPressed,
    super.onLongPress,
    super.onHover,
    super.onFocusChange,
    super.style,
    super.focusNode,
    super.autofocus = false,
    super.clipBehavior = Clip.none,
77
    super.statesController,
78 79
    required super.child,
  });
80

81
  /// Create an elevated button from a pair of widgets that serve as the button's
82 83 84 85 86 87
  /// [icon] and [label].
  ///
  /// 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.
88
  factory ElevatedButton.icon({
89 90 91
    Key? key,
    required VoidCallback? onPressed,
    VoidCallback? onLongPress,
92 93
    ValueChanged<bool>? onHover,
    ValueChanged<bool>? onFocusChange,
94 95 96 97
    ButtonStyle? style,
    FocusNode? focusNode,
    bool? autofocus,
    Clip? clipBehavior,
98
    MaterialStatesController? statesController,
99 100
    required Widget icon,
    required Widget label,
101
  }) = _ElevatedButtonWithIcon;
102

103
  /// A static convenience method that constructs an elevated button
104 105
  /// [ButtonStyle] given simple values.
  ///
106 107 108 109 110 111
  /// The [foregroundColor] and [disabledForegroundColor] colors are used
  /// to create a [MaterialStateProperty] [ButtonStyle.foregroundColor], and
  /// a derived [ButtonStyle.overlayColor].
  ///
  /// The [backgroundColor] and [disabledBackgroundColor] colors are
  /// used to create a [MaterialStateProperty] [ButtonStyle.backgroundColor].
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
  ///
  /// The button's elevations are defined relative to the [elevation]
  /// parameter. The disabled elevation is the same as the parameter
  /// value, [elevation] + 2 is used when the button is hovered
  /// or focused, and elevation + 6 is used when the button is pressed.
  ///
  /// Similarly, the [enabledMouseCursor] and [disabledMouseCursor]
  /// parameters are used to construct [ButtonStyle].mouseCursor.
  ///
  /// All of the other parameters are either used directly or used to
  /// create a [MaterialStateProperty] with a single value for all
  /// states.
  ///
  /// All parameters default to null, by default this method returns
  /// a [ButtonStyle] that doesn't override anything.
  ///
  /// For example, to override the default text and icon colors for a
129
  /// [ElevatedButton], as well as its overlay color, with all of the
130 131 132 133
  /// standard opacity adjustments for the pressed, focused, and
  /// hovered states, one could write:
  ///
  /// ```dart
134
  /// ElevatedButton(
135
  ///   style: ElevatedButton.styleFrom(foregroundColor: Colors.green),
136 137 138 139 140
  ///   onPressed: () {
  ///     // ...
  ///   },
  ///   child: const Text('Jump'),
  /// ),
141 142 143 144 145 146 147
  /// ```
  ///
  /// And to change the fill color:
  ///
  /// ```dart
  /// ElevatedButton(
  ///   style: ElevatedButton.styleFrom(backgroundColor: Colors.green),
148 149 150 151 152
  ///   onPressed: () {
  ///     // ...
  ///   },
  ///   child: const Text('Meow'),
  /// ),
153
  /// ```
154
  ///
155
  static ButtonStyle styleFrom({
156 157 158 159
    Color? foregroundColor,
    Color? backgroundColor,
    Color? disabledForegroundColor,
    Color? disabledBackgroundColor,
160
    Color? shadowColor,
161
    Color? surfaceTintColor,
162 163 164 165
    double? elevation,
    TextStyle? textStyle,
    EdgeInsetsGeometry? padding,
    Size? minimumSize,
166
    Size? fixedSize,
167
    Size? maximumSize,
168 169 170 171 172 173 174 175
    BorderSide? side,
    OutlinedBorder? shape,
    MouseCursor? enabledMouseCursor,
    MouseCursor? disabledMouseCursor,
    VisualDensity? visualDensity,
    MaterialTapTargetSize? tapTargetSize,
    Duration? animationDuration,
    bool? enableFeedback,
176
    AlignmentGeometry? alignment,
177
    InteractiveInkFeatureFactory? splashFactory,
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192
    @Deprecated(
      'Use backgroundColor instead. '
      'This feature was deprecated after v3.1.0.'
    )
    Color? primary,
    @Deprecated(
      'Use foregroundColor instead. '
      'This feature was deprecated after v3.1.0.'
    )
    Color? onPrimary,
    @Deprecated(
      'Use disabledForegroundColor and disabledBackgroundColor instead. '
      'This feature was deprecated after v3.1.0.'
    )
    Color? onSurface,
193
  }) {
194 195 196
    final Color? background = backgroundColor ?? primary;
    final Color? disabledBackground = disabledBackgroundColor ?? onSurface?.withOpacity(0.12);
    final MaterialStateProperty<Color?>? backgroundColorProp = (background == null && disabledBackground == null)
197
      ? null
198 199 200 201
      : _ElevatedButtonDefaultColor(background, disabledBackground);
    final Color? foreground = foregroundColor ?? onPrimary;
    final Color? disabledForeground = disabledForegroundColor ?? onSurface?.withOpacity(0.38);
    final MaterialStateProperty<Color?>? foregroundColorProp = (foreground == null && disabledForeground == null)
202
      ? null
203 204
      : _ElevatedButtonDefaultColor(foreground, disabledForeground);
    final MaterialStateProperty<Color?>? overlayColor = (foreground == null)
205
      ? null
206
      : _ElevatedButtonDefaultOverlay(foreground);
207
    final MaterialStateProperty<double>? elevationValue = (elevation == null)
208
      ? null
209
      : _ElevatedButtonDefaultElevation(elevation);
210
    final MaterialStateProperty<MouseCursor?>? mouseCursor = (enabledMouseCursor == null && disabledMouseCursor == null)
211
      ? null
212
      : _ElevatedButtonDefaultMouseCursor(enabledMouseCursor, disabledMouseCursor);
213 214

    return ButtonStyle(
215
      textStyle: MaterialStatePropertyAll<TextStyle?>(textStyle),
216 217
      backgroundColor: backgroundColorProp,
      foregroundColor: foregroundColorProp,
218 219
      overlayColor: overlayColor,
      shadowColor: ButtonStyleButton.allOrNull<Color>(shadowColor),
220
      surfaceTintColor: ButtonStyleButton.allOrNull<Color>(surfaceTintColor),
221 222 223
      elevation: elevationValue,
      padding: ButtonStyleButton.allOrNull<EdgeInsetsGeometry>(padding),
      minimumSize: ButtonStyleButton.allOrNull<Size>(minimumSize),
224
      fixedSize: ButtonStyleButton.allOrNull<Size>(fixedSize),
225
      maximumSize: ButtonStyleButton.allOrNull<Size>(maximumSize),
226 227 228 229 230 231 232
      side: ButtonStyleButton.allOrNull<BorderSide>(side),
      shape: ButtonStyleButton.allOrNull<OutlinedBorder>(shape),
      mouseCursor: mouseCursor,
      visualDensity: visualDensity,
      tapTargetSize: tapTargetSize,
      animationDuration: animationDuration,
      enableFeedback: enableFeedback,
233
      alignment: alignment,
234
      splashFactory: splashFactory,
235 236 237 238 239 240 241 242 243 244 245 246 247 248 249
    );
  }

  /// Defines the button's default appearance.
  ///
  /// The button [child]'s [Text] and [Icon] widgets are rendered with
  /// the [ButtonStyle]'s foreground color. The button's [InkWell] adds
  /// the style's overlay color when the button is focused, hovered
  /// or pressed. The button's background color becomes its [Material]
  /// color.
  ///
  /// All of the ButtonStyle's defaults appear below. In this list
  /// "Theme.foo" is shorthand for `Theme.of(context).foo`. Color
  /// scheme values like "onSurface(0.38)" are shorthand for
  /// `onSurface.withOpacity(0.38)`. [MaterialStateProperty] valued
nt4f04uNd's avatar
nt4f04uNd committed
250
  /// properties that are not followed by a sublist have the same
251 252 253 254
  /// value for all states, otherwise the values are as specified for
  /// each state, and "others" means all other states.
  ///
  /// The `textScaleFactor` is the value of
255
  /// `MediaQuery.textScaleFactorOf(context)` and the names of the
256 257 258
  /// EdgeInsets constructors and `EdgeInsetsGeometry.lerp` have been
  /// abbreviated for readability.
  ///
259 260
  /// The color of the [ButtonStyle.textStyle] is not used, the
  /// [ButtonStyle.foregroundColor] color is used instead.
261
  ///
262 263
  /// ## Material 2 defaults
  ///
264 265 266 267 268 269 270 271 272 273
  /// * `textStyle` - Theme.textTheme.button
  /// * `backgroundColor`
  ///   * disabled - Theme.colorScheme.onSurface(0.12)
  ///   * others - Theme.colorScheme.primary
  /// * `foregroundColor`
  ///   * disabled - Theme.colorScheme.onSurface(0.38)
  ///   * others - Theme.colorScheme.onPrimary
  /// * `overlayColor`
  ///   * hovered - Theme.colorScheme.onPrimary(0.08)
  ///   * focused or pressed - Theme.colorScheme.onPrimary(0.24)
274
  /// * `shadowColor` - Theme.shadowColor
275 276
  /// * `elevation`
  ///   * disabled - 0
277 278 279
  ///   * default - 2
  ///   * hovered or focused - 4
  ///   * pressed - 8
280
  /// * `padding`
281
  ///   * `textScaleFactor <= 1` - horizontal(16)
282 283 284 285
  ///   * `1 < textScaleFactor <= 2` - lerp(horizontal(16), horizontal(8))
  ///   * `2 < textScaleFactor <= 3` - lerp(horizontal(8), horizontal(4))
  ///   * `3 < textScaleFactor` - horizontal(4)
  /// * `minimumSize` - Size(64, 36)
286
  /// * `fixedSize` - null
287
  /// * `maximumSize` - Size.infinite
288
  /// * `side` - null
289 290
  /// * `shape` - RoundedRectangleBorder(borderRadius: BorderRadius.circular(4))
  /// * `mouseCursor`
291
  ///   * disabled - SystemMouseCursors.basic
292 293 294 295 296
  ///   * others - SystemMouseCursors.click
  /// * `visualDensity` - theme.visualDensity
  /// * `tapTargetSize` - theme.materialTapTargetSize
  /// * `animationDuration` - kThemeChangeDuration
  /// * `enableFeedback` - true
297
  /// * `alignment` - Alignment.center
298
  /// * `splashFactory` - InkRipple.splashFactory
299
  ///
300
  /// The default padding values for the [ElevatedButton.icon] factory are slightly different:
301 302 303 304 305 306
  ///
  /// * `padding`
  ///   * `textScaleFactor <= 1` - start(12) end(16)
  ///   * `1 < textScaleFactor <= 2` - lerp(start(12) end(16), horizontal(8))
  ///   * `2 < textScaleFactor <= 3` - lerp(horizontal(8), horizontal(4))
  ///   * `3 < textScaleFactor` - horizontal(4)
307 308 309 310 311
  ///
  /// The default value for `side`, which defines the appearance of the button's
  /// outline, is null. That means that the outline is defined by the button
  /// shape's [OutlinedBorder.side]. Typically the default value of an
  /// [OutlinedBorder]'s side is [BorderSide.none], so an outline is not drawn.
312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335
  ///
  /// ## Material 3 defaults
  ///
  /// If [ThemeData.useMaterial3] is set to true the following defaults will
  /// be used:
  ///
  /// * `textStyle` - Theme.textTheme.labelLarge
  /// * `backgroundColor`
  ///   * disabled - Theme.colorScheme.onSurface(0.12)
  ///   * others - Theme.colorScheme.surface
  /// * `foregroundColor`
  ///   * disabled - Theme.colorScheme.onSurface(0.38)
  ///   * others - Theme.colorScheme.primary
  /// * `overlayColor`
  ///   * hovered - Theme.colorScheme.primary(0.08)
  ///   * focused or pressed - Theme.colorScheme.primary(0.12)
  /// * `shadowColor` - Theme.colorScheme.shadow
  /// * `surfaceTintColor` - Theme.colorScheme.surfaceTint
  /// * `elevation`
  ///   * disabled - 0
  ///   * default - 1
  ///   * hovered - 3
  ///   * focused or pressed - 1
  /// * `padding`
336 337 338 339
  ///   * `textScaleFactor <= 1` - horizontal(24)
  ///   * `1 < textScaleFactor <= 2` - lerp(horizontal(24), horizontal(12))
  ///   * `2 < textScaleFactor <= 3` - lerp(horizontal(12), horizontal(6))
  ///   * `3 < textScaleFactor` - horizontal(6)
340 341 342 343 344 345 346 347 348 349 350 351 352 353
  /// * `minimumSize` - Size(64, 40)
  /// * `fixedSize` - null
  /// * `maximumSize` - Size.infinite
  /// * `side` - null
  /// * `shape` - StadiumBorder()
  /// * `mouseCursor`
  ///   * disabled - SystemMouseCursors.basic
  ///   * others - SystemMouseCursors.click
  /// * `visualDensity` - Theme.visualDensity
  /// * `tapTargetSize` - Theme.materialTapTargetSize
  /// * `animationDuration` - kThemeChangeDuration
  /// * `enableFeedback` - true
  /// * `alignment` - Alignment.center
  /// * `splashFactory` - Theme.splashFactory
354 355 356 357
  ///
  /// For the [ElevatedButton.icon] factory, the start (generally the left) value of
  /// [padding] is reduced from 24 to 16.

358 359
  @override
  ButtonStyle defaultStyleOf(BuildContext context) {
360
    final ThemeData theme = Theme.of(context);
361 362
    final ColorScheme colorScheme = theme.colorScheme;

363
    return Theme.of(context).useMaterial3
364
      ? _ElevatedButtonDefaultsM3(context)
365
      : styleFrom(
366 367 368 369
          backgroundColor: colorScheme.primary,
          foregroundColor: colorScheme.onPrimary,
          disabledBackgroundColor: colorScheme.onSurface.withOpacity(0.12),
          disabledForegroundColor: colorScheme.onSurface.withOpacity(0.38),
370 371
          shadowColor: theme.shadowColor,
          elevation: 2,
372
          textStyle: theme.textTheme.labelLarge,
373 374 375 376 377 378 379 380 381 382 383 384 385
          padding: _scaledPadding(context),
          minimumSize: const Size(64, 36),
          maximumSize: Size.infinite,
          shape: const RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(4))),
          enabledMouseCursor: SystemMouseCursors.click,
          disabledMouseCursor: SystemMouseCursors.basic,
          visualDensity: theme.visualDensity,
          tapTargetSize: theme.materialTapTargetSize,
          animationDuration: kThemeChangeDuration,
          enableFeedback: true,
          alignment: Alignment.center,
          splashFactory: InkRipple.splashFactory,
        );
386 387
  }

388 389
  /// Returns the [ElevatedButtonThemeData.style] of the closest
  /// [ElevatedButtonTheme] ancestor.
390
  @override
391 392
  ButtonStyle? themeStyleOf(BuildContext context) {
    return ElevatedButtonTheme.of(context).style;
393 394 395
  }
}

396
EdgeInsetsGeometry _scaledPadding(BuildContext context) {
397 398
  final bool useMaterial3 = Theme.of(context).useMaterial3;
  final double padding1x = useMaterial3 ? 24.0 : 16.0;
399
  return ButtonStyleButton.scaledPadding(
400 401 402
     EdgeInsets.symmetric(horizontal: padding1x),
     EdgeInsets.symmetric(horizontal: padding1x / 2),
     EdgeInsets.symmetric(horizontal: padding1x / 2 / 2),
403
    MediaQuery.textScaleFactorOf(context),
404 405 406
  );
}

407
@immutable
408 409
class _ElevatedButtonDefaultColor extends MaterialStateProperty<Color?> with Diagnosticable {
  _ElevatedButtonDefaultColor(this.color, this.disabled);
410

411 412
  final Color? color;
  final Color? disabled;
413 414

  @override
415
  Color? resolve(Set<MaterialState> states) {
416
    if (states.contains(MaterialState.disabled)) {
417
      return disabled;
418
    }
419
    return color;
420 421 422 423
  }
}

@immutable
424
class _ElevatedButtonDefaultOverlay extends MaterialStateProperty<Color?> with Diagnosticable {
425
  _ElevatedButtonDefaultOverlay(this.overlay);
426

427
  final Color overlay;
428 429

  @override
430
  Color? resolve(Set<MaterialState> states) {
431
    if (states.contains(MaterialState.hovered)) {
432
      return overlay.withOpacity(0.08);
433 434
    }
    if (states.contains(MaterialState.focused) || states.contains(MaterialState.pressed)) {
435
      return overlay.withOpacity(0.24);
436
    }
437 438 439 440 441
    return null;
  }
}

@immutable
442 443
class _ElevatedButtonDefaultElevation extends MaterialStateProperty<double> with Diagnosticable {
  _ElevatedButtonDefaultElevation(this.elevation);
444 445 446 447 448

  final double elevation;

  @override
  double resolve(Set<MaterialState> states) {
449
    if (states.contains(MaterialState.disabled)) {
450
      return 0;
451 452
    }
    if (states.contains(MaterialState.hovered)) {
453
      return elevation + 2;
454 455
    }
    if (states.contains(MaterialState.focused)) {
456
      return elevation + 2;
457 458
    }
    if (states.contains(MaterialState.pressed)) {
459
      return elevation + 6;
460
    }
461 462 463 464 465
    return elevation;
  }
}

@immutable
466
class _ElevatedButtonDefaultMouseCursor extends MaterialStateProperty<MouseCursor?> with Diagnosticable {
467
  _ElevatedButtonDefaultMouseCursor(this.enabledCursor, this.disabledCursor);
468

469 470
  final MouseCursor? enabledCursor;
  final MouseCursor? disabledCursor;
471 472

  @override
473
  MouseCursor? resolve(Set<MaterialState> states) {
474
    if (states.contains(MaterialState.disabled)) {
475
      return disabledCursor;
476
    }
477 478 479 480
    return enabledCursor;
  }
}

481 482
class _ElevatedButtonWithIcon extends ElevatedButton {
  _ElevatedButtonWithIcon({
483 484 485 486 487 488 489
    super.key,
    required super.onPressed,
    super.onLongPress,
    super.onHover,
    super.onFocusChange,
    super.style,
    super.focusNode,
490 491
    bool? autofocus,
    Clip? clipBehavior,
492
    super.statesController,
493 494
    required Widget icon,
    required Widget label,
495
  }) : super(
496 497 498 499 500 501 502
         autofocus: autofocus ?? false,
         clipBehavior: clipBehavior ?? Clip.none,
         child: _ElevatedButtonWithIconChild(icon: icon, label: label),
      );

  @override
  ButtonStyle defaultStyleOf(BuildContext context) {
503 504 505 506 507 508 509
    final bool useMaterial3 = Theme.of(context).useMaterial3;
    final EdgeInsetsGeometry scaledPadding = useMaterial3 ?  ButtonStyleButton.scaledPadding(
      const EdgeInsetsDirectional.fromSTEB(16, 0, 24, 0),
      const EdgeInsetsDirectional.fromSTEB(8, 0, 12, 0),
      const EdgeInsetsDirectional.fromSTEB(4, 0, 6, 0),
      MediaQuery.textScaleFactorOf(context),
    ) : ButtonStyleButton.scaledPadding(
510 511 512
      const EdgeInsetsDirectional.fromSTEB(12, 0, 16, 0),
      const EdgeInsets.symmetric(horizontal: 8),
      const EdgeInsetsDirectional.fromSTEB(8, 0, 4, 0),
513
      MediaQuery.textScaleFactorOf(context),
514 515
    );
    return super.defaultStyleOf(context).copyWith(
516
      padding: MaterialStatePropertyAll<EdgeInsetsGeometry>(scaledPadding),
517 518 519 520 521
    );
  }
}

class _ElevatedButtonWithIconChild extends StatelessWidget {
522
  const _ElevatedButtonWithIconChild({ required this.label, required this.icon });
523 524 525 526 527 528

  final Widget label;
  final Widget icon;

  @override
  Widget build(BuildContext context) {
529
    final double scale = MediaQuery.textScaleFactorOf(context);
530
    final double gap = scale <= 1 ? 8 : lerpDouble(8, 4, math.min(scale - 1, 1))!;
531 532
    return Row(
      mainAxisSize: MainAxisSize.min,
533
      children: <Widget>[icon, SizedBox(width: gap), Flexible(child: label)],
534 535 536
    );
  }
}
537

538
// BEGIN GENERATED TOKEN PROPERTIES - ElevatedButton
539

540 541 542 543
// Do not edit by hand. The code between the "BEGIN GENERATED" and
// "END GENERATED" comments are generated from data in the Material
// Design token database by the script:
//   dev/tools/gen_defaults/bin/gen_defaults.dart.
544

545
// Token database version: v0_162
546 547 548

class _ElevatedButtonDefaultsM3 extends ButtonStyle {
  _ElevatedButtonDefaultsM3(this.context)
549 550 551 552 553 554 555 556 557 558 559
   : super(
       animationDuration: kThemeChangeDuration,
       enableFeedback: true,
       alignment: Alignment.center,
     );

  final BuildContext context;
  late final ColorScheme _colors = Theme.of(context).colorScheme;

  @override
  MaterialStateProperty<TextStyle?> get textStyle =>
560
    MaterialStatePropertyAll<TextStyle?>(Theme.of(context).textTheme.labelLarge);
561 562 563 564

  @override
  MaterialStateProperty<Color?>? get backgroundColor =>
    MaterialStateProperty.resolveWith((Set<MaterialState> states) {
565
      if (states.contains(MaterialState.disabled)) {
566
        return _colors.onSurface.withOpacity(0.12);
567
      }
568 569 570 571 572 573
      return _colors.surface;
    });

  @override
  MaterialStateProperty<Color?>? get foregroundColor =>
    MaterialStateProperty.resolveWith((Set<MaterialState> states) {
574
      if (states.contains(MaterialState.disabled)) {
575
        return _colors.onSurface.withOpacity(0.38);
576
      }
577 578 579 580 581 582
      return _colors.primary;
    });

  @override
  MaterialStateProperty<Color?>? get overlayColor =>
    MaterialStateProperty.resolveWith((Set<MaterialState> states) {
583
      if (states.contains(MaterialState.hovered)) {
584
        return _colors.primary.withOpacity(0.08);
585 586
      }
      if (states.contains(MaterialState.focused)) {
587
        return _colors.primary.withOpacity(0.12);
588 589
      }
      if (states.contains(MaterialState.pressed)) {
590
        return _colors.primary.withOpacity(0.12);
591
      }
592 593 594 595 596
      return null;
    });

  @override
  MaterialStateProperty<Color>? get shadowColor =>
597
    MaterialStatePropertyAll<Color>(_colors.shadow);
598 599 600

  @override
  MaterialStateProperty<Color>? get surfaceTintColor =>
601
    MaterialStatePropertyAll<Color>(_colors.surfaceTint);
602 603 604 605

  @override
  MaterialStateProperty<double>? get elevation =>
    MaterialStateProperty.resolveWith((Set<MaterialState> states) {
606
      if (states.contains(MaterialState.disabled)) {
607
        return 0.0;
608 609
      }
      if (states.contains(MaterialState.hovered)) {
610
        return 3.0;
611 612
      }
      if (states.contains(MaterialState.focused)) {
613
        return 1.0;
614 615
      }
      if (states.contains(MaterialState.pressed)) {
616
        return 1.0;
617
      }
618 619 620 621 622
      return 1.0;
    });

  @override
  MaterialStateProperty<EdgeInsetsGeometry>? get padding =>
623
    MaterialStatePropertyAll<EdgeInsetsGeometry>(_scaledPadding(context));
624 625 626

  @override
  MaterialStateProperty<Size>? get minimumSize =>
627
    const MaterialStatePropertyAll<Size>(Size(64.0, 40.0));
628 629 630 631 632

  // No default fixedSize

  @override
  MaterialStateProperty<Size>? get maximumSize =>
633
    const MaterialStatePropertyAll<Size>(Size.infinite);
634 635 636 637 638

  // No default side

  @override
  MaterialStateProperty<OutlinedBorder>? get shape =>
639
    const MaterialStatePropertyAll<OutlinedBorder>(StadiumBorder());
640 641 642 643

  @override
  MaterialStateProperty<MouseCursor?>? get mouseCursor =>
    MaterialStateProperty.resolveWith((Set<MaterialState> states) {
644
      if (states.contains(MaterialState.disabled)) {
645
        return SystemMouseCursors.basic;
646
      }
647 648 649 650 651 652 653 654 655 656 657 658 659
      return SystemMouseCursors.click;
    });

  @override
  VisualDensity? get visualDensity => Theme.of(context).visualDensity;

  @override
  MaterialTapTargetSize? get tapTargetSize => Theme.of(context).materialTapTargetSize;

  @override
  InteractiveInkFeatureFactory? get splashFactory => Theme.of(context).splashFactory;
}

660
// END GENERATED TOKEN PROPERTIES - ElevatedButton