customelevatedbutton.dart 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652
  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. import 'dart:math' as math;
  5. import 'dart:ui' show lerpDouble;
  6. import 'package:flutter/foundation.dart';
  7. import 'package:flutter/material.dart';
  8. import 'package:flyinsonolite/controls/custom/custombuttonstylebutton.dart';
  9. import 'package:flyinsonolite/infrastructure/scale.dart';
  10. /// A Material Design "elevated button".
  11. ///
  12. /// Use elevated buttons to add dimension to otherwise mostly flat
  13. /// layouts, e.g. in long busy lists of content, or in wide
  14. /// spaces. Avoid using elevated buttons on already-elevated content
  15. /// such as dialogs or cards.
  16. ///
  17. /// An elevated button is a label [child] displayed on a [Material]
  18. /// widget whose [Material.elevation] increases when the button is
  19. /// pressed. The label's [Text] and [Icon] widgets are displayed in
  20. /// [style]'s [ButtonStyle.foregroundColor] and the button's filled
  21. /// background is the [ButtonStyle.backgroundColor].
  22. ///
  23. /// The elevated button's default style is defined by
  24. /// [defaultStyleOf]. The style of this elevated button can be
  25. /// overridden with its [style] parameter. The style of all elevated
  26. /// buttons in a subtree can be overridden with the
  27. /// [ElevatedButtonTheme], and the style of all of the elevated
  28. /// buttons in an app can be overridden with the [Theme]'s
  29. /// [ThemeData.elevatedButtonTheme] property.
  30. ///
  31. /// The static [styleFrom] method is a convenient way to create a
  32. /// elevated button [ButtonStyle] from simple values.
  33. ///
  34. /// If [onPressed] and [onLongPress] callbacks are null, then the
  35. /// button will be disabled.
  36. ///
  37. /// {@tool dartpad}
  38. /// This sample produces an enabled and a disabled ElevatedButton.
  39. ///
  40. /// ** See code in examples/api/lib/material/elevated_button/elevated_button.0.dart **
  41. /// {@end-tool}
  42. ///
  43. /// See also:
  44. ///
  45. /// * [FilledButton], a filled button that doesn't elevate when pressed.
  46. /// * [FilledButton.tonal], a filled button variant that uses a secondary fill color.
  47. /// * [OutlinedButton], a button with an outlined border and no fill color.
  48. /// * [CustomTextButton], a button with no outline or fill color.
  49. /// * <https://material.io/design/components/buttons.html>
  50. /// * <https://m3.material.io/components/buttons>
  51. class CustomElevatedButton extends CustomButtonStyleButton {
  52. /// Create an ElevatedButton.
  53. ///
  54. /// The [autofocus] and [clipBehavior] arguments must not be null.
  55. const CustomElevatedButton({
  56. super.key,
  57. required super.onPressed,
  58. super.onLongPress,
  59. super.onHover,
  60. super.onFocusChange,
  61. super.style,
  62. super.focusNode,
  63. super.autofocus = false,
  64. super.clipBehavior = Clip.none,
  65. super.statesController,
  66. required super.child,
  67. });
  68. /// Create an elevated button from a pair of widgets that serve as the button's
  69. /// [icon] and [label].
  70. ///
  71. /// The icon and label are arranged in a row and padded by 12 logical pixels
  72. /// at the start, and 16 at the end, with an 8 pixel gap in between.
  73. ///
  74. /// The [icon] and [label] arguments must not be null.
  75. factory CustomElevatedButton.icon({
  76. Key? key,
  77. required VoidCallback? onPressed,
  78. VoidCallback? onLongPress,
  79. ValueChanged<bool>? onHover,
  80. ValueChanged<bool>? onFocusChange,
  81. ButtonStyle? style,
  82. FocusNode? focusNode,
  83. bool? autofocus,
  84. Clip? clipBehavior,
  85. MaterialStatesController? statesController,
  86. required Widget icon,
  87. required Widget label,
  88. }) = _ElevatedButtonWithIcon;
  89. /// A static convenience method that constructs an elevated button
  90. /// [ButtonStyle] given simple values.
  91. ///
  92. /// The [foregroundColor] and [disabledForegroundColor] colors are used
  93. /// to create a [MaterialStateProperty] [ButtonStyle.foregroundColor], and
  94. /// a derived [ButtonStyle.overlayColor].
  95. ///
  96. /// The [backgroundColor] and [disabledBackgroundColor] colors are
  97. /// used to create a [MaterialStateProperty] [ButtonStyle.backgroundColor].
  98. ///
  99. /// The button's elevations are defined relative to the [elevation]
  100. /// parameter. The disabled elevation is the same as the parameter
  101. /// value, [elevation] + 2 is used when the button is hovered
  102. /// or focused, and elevation + 6 is used when the button is pressed.
  103. ///
  104. /// Similarly, the [enabledMouseCursor] and [disabledMouseCursor]
  105. /// parameters are used to construct [ButtonStyle].mouseCursor.
  106. ///
  107. /// All of the other parameters are either used directly or used to
  108. /// create a [MaterialStateProperty] with a single value for all
  109. /// states.
  110. ///
  111. /// All parameters default to null, by default this method returns
  112. /// a [ButtonStyle] that doesn't override anything.
  113. ///
  114. /// For example, to override the default text and icon colors for a
  115. /// [CustomElevatedButton], as well as its overlay color, with all of the
  116. /// standard opacity adjustments for the pressed, focused, and
  117. /// hovered states, one could write:
  118. ///
  119. /// ```dart
  120. /// ElevatedButton(
  121. /// style: ElevatedButton.styleFrom(foregroundColor: Colors.green),
  122. /// onPressed: () {
  123. /// // ...
  124. /// },
  125. /// child: const Text('Jump'),
  126. /// ),
  127. /// ```
  128. ///
  129. /// And to change the fill color:
  130. ///
  131. /// ```dart
  132. /// ElevatedButton(
  133. /// style: ElevatedButton.styleFrom(backgroundColor: Colors.green),
  134. /// onPressed: () {
  135. /// // ...
  136. /// },
  137. /// child: const Text('Meow'),
  138. /// ),
  139. /// ```
  140. ///
  141. static ButtonStyle styleFrom({
  142. Color? foregroundColor,
  143. Color? backgroundColor,
  144. Color? disabledForegroundColor,
  145. Color? disabledBackgroundColor,
  146. Color? shadowColor,
  147. Color? surfaceTintColor,
  148. double? elevation,
  149. TextStyle? textStyle,
  150. EdgeInsetsGeometry? padding,
  151. Size? minimumSize,
  152. Size? fixedSize,
  153. Size? maximumSize,
  154. BorderSide? side,
  155. OutlinedBorder? shape,
  156. MouseCursor? enabledMouseCursor,
  157. MouseCursor? disabledMouseCursor,
  158. VisualDensity? visualDensity,
  159. MaterialTapTargetSize? tapTargetSize,
  160. Duration? animationDuration,
  161. bool? enableFeedback,
  162. AlignmentGeometry? alignment,
  163. InteractiveInkFeatureFactory? splashFactory,
  164. @Deprecated('Use backgroundColor instead. '
  165. 'This feature was deprecated after v3.1.0.')
  166. Color? primary,
  167. @Deprecated('Use foregroundColor instead. '
  168. 'This feature was deprecated after v3.1.0.')
  169. Color? onPrimary,
  170. @Deprecated(
  171. 'Use disabledForegroundColor and disabledBackgroundColor instead. '
  172. 'This feature was deprecated after v3.1.0.')
  173. Color? onSurface,
  174. }) {
  175. final Color? background = backgroundColor ?? primary;
  176. final Color? disabledBackground =
  177. disabledBackgroundColor ?? onSurface?.withOpacity(0.12);
  178. final MaterialStateProperty<Color?>? backgroundColorProp =
  179. (background == null && disabledBackground == null)
  180. ? null
  181. : _ElevatedButtonDefaultColor(background, disabledBackground);
  182. final Color? foreground = foregroundColor ?? onPrimary;
  183. final Color? disabledForeground =
  184. disabledForegroundColor ?? onSurface?.withOpacity(0.38);
  185. final MaterialStateProperty<Color?>? foregroundColorProp =
  186. (foreground == null && disabledForeground == null)
  187. ? null
  188. : _ElevatedButtonDefaultColor(foreground, disabledForeground);
  189. final MaterialStateProperty<Color?>? overlayColor =
  190. (foreground == null) ? null : _ElevatedButtonDefaultOverlay(foreground);
  191. final MaterialStateProperty<double>? elevationValue =
  192. (elevation == null) ? null : _ElevatedButtonDefaultElevation(elevation);
  193. final MaterialStateProperty<MouseCursor?>? mouseCursor =
  194. (enabledMouseCursor == null && disabledMouseCursor == null)
  195. ? null
  196. : _ElevatedButtonDefaultMouseCursor(
  197. enabledMouseCursor, disabledMouseCursor);
  198. return ButtonStyle(
  199. textStyle: MaterialStatePropertyAll<TextStyle?>(textStyle),
  200. backgroundColor: backgroundColorProp,
  201. foregroundColor: foregroundColorProp,
  202. overlayColor: overlayColor,
  203. shadowColor: CustomButtonStyleButton.allOrNull<Color>(shadowColor),
  204. surfaceTintColor:
  205. CustomButtonStyleButton.allOrNull<Color>(surfaceTintColor),
  206. elevation: elevationValue,
  207. padding: CustomButtonStyleButton.allOrNull<EdgeInsetsGeometry>(padding),
  208. minimumSize: CustomButtonStyleButton.allOrNull<Size>(minimumSize),
  209. fixedSize: CustomButtonStyleButton.allOrNull<Size>(fixedSize),
  210. maximumSize: CustomButtonStyleButton.allOrNull<Size>(maximumSize),
  211. side: CustomButtonStyleButton.allOrNull<BorderSide>(side),
  212. shape: CustomButtonStyleButton.allOrNull<OutlinedBorder>(shape),
  213. mouseCursor: mouseCursor,
  214. visualDensity: visualDensity,
  215. tapTargetSize: tapTargetSize,
  216. animationDuration: animationDuration,
  217. enableFeedback: enableFeedback,
  218. alignment: alignment,
  219. splashFactory: splashFactory,
  220. );
  221. }
  222. /// Defines the button's default appearance.
  223. ///
  224. /// The button [child]'s [Text] and [Icon] widgets are rendered with
  225. /// the [ButtonStyle]'s foreground color. The button's [InkWell] adds
  226. /// the style's overlay color when the button is focused, hovered
  227. /// or pressed. The button's background color becomes its [Material]
  228. /// color.
  229. ///
  230. /// All of the ButtonStyle's defaults appear below. In this list
  231. /// "Theme.foo" is shorthand for `Theme.of(context).foo`. Color
  232. /// scheme values like "onSurface(0.38)" are shorthand for
  233. /// `onSurface.withOpacity(0.38)`. [MaterialStateProperty] valued
  234. /// properties that are not followed by a sublist have the same
  235. /// value for all states, otherwise the values are as specified for
  236. /// each state, and "others" means all other states.
  237. ///
  238. /// The `textScaleFactor` is the value of
  239. /// `MediaQuery.of(context).textScaleFactor` and the names of the
  240. /// EdgeInsets constructors and `EdgeInsetsGeometry.lerp` have been
  241. /// abbreviated for readability.
  242. ///
  243. /// The color of the [ButtonStyle.textStyle] is not used, the
  244. /// [ButtonStyle.foregroundColor] color is used instead.
  245. ///
  246. /// ## Material 2 defaults
  247. ///
  248. /// * `textStyle` - Theme.textTheme.button
  249. /// * `backgroundColor`
  250. /// * disabled - Theme.colorScheme.onSurface(0.12)
  251. /// * others - Theme.colorScheme.primary
  252. /// * `foregroundColor`
  253. /// * disabled - Theme.colorScheme.onSurface(0.38)
  254. /// * others - Theme.colorScheme.onPrimary
  255. /// * `overlayColor`
  256. /// * hovered - Theme.colorScheme.onPrimary(0.08)
  257. /// * focused or pressed - Theme.colorScheme.onPrimary(0.24)
  258. /// * `shadowColor` - Theme.shadowColor
  259. /// * `elevation`
  260. /// * disabled - 0
  261. /// * default - 2
  262. /// * hovered or focused - 4
  263. /// * pressed - 8
  264. /// * `padding`
  265. /// * `textScaleFactor <= 1` - horizontal(16)
  266. /// * `1 < textScaleFactor <= 2` - lerp(horizontal(16), horizontal(8))
  267. /// * `2 < textScaleFactor <= 3` - lerp(horizontal(8), horizontal(4))
  268. /// * `3 < textScaleFactor` - horizontal(4)
  269. /// * `minimumSize` - Size(64, 36)
  270. /// * `fixedSize` - null
  271. /// * `maximumSize` - Size.infinite
  272. /// * `side` - null
  273. /// * `shape` - RoundedRectangleBorder(borderRadius: BorderRadius.circular(4))
  274. /// * `mouseCursor`
  275. /// * disabled - SystemMouseCursors.basic
  276. /// * others - SystemMouseCursors.click
  277. /// * `visualDensity` - theme.visualDensity
  278. /// * `tapTargetSize` - theme.materialTapTargetSize
  279. /// * `animationDuration` - kThemeChangeDuration
  280. /// * `enableFeedback` - true
  281. /// * `alignment` - Alignment.center
  282. /// * `splashFactory` - InkRipple.splashFactory
  283. ///
  284. /// The default padding values for the [ElevatedButton.icon] factory are slightly different:
  285. ///
  286. /// * `padding`
  287. /// * `textScaleFactor <= 1` - start(12) end(16)
  288. /// * `1 < textScaleFactor <= 2` - lerp(start(12) end(16), horizontal(8))
  289. /// * `2 < textScaleFactor <= 3` - lerp(horizontal(8), horizontal(4))
  290. /// * `3 < textScaleFactor` - horizontal(4)
  291. ///
  292. /// The default value for `side`, which defines the appearance of the button's
  293. /// outline, is null. That means that the outline is defined by the button
  294. /// shape's [OutlinedBorder.side]. Typically the default value of an
  295. /// [OutlinedBorder]'s side is [BorderSide.none], so an outline is not drawn.
  296. ///
  297. /// ## Material 3 defaults
  298. ///
  299. /// If [ThemeData.useMaterial3] is set to true the following defaults will
  300. /// be used:
  301. ///
  302. /// * `textStyle` - Theme.textTheme.labelLarge
  303. /// * `backgroundColor`
  304. /// * disabled - Theme.colorScheme.onSurface(0.12)
  305. /// * others - Theme.colorScheme.surface
  306. /// * `foregroundColor`
  307. /// * disabled - Theme.colorScheme.onSurface(0.38)
  308. /// * others - Theme.colorScheme.primary
  309. /// * `overlayColor`
  310. /// * hovered - Theme.colorScheme.primary(0.08)
  311. /// * focused or pressed - Theme.colorScheme.primary(0.12)
  312. /// * `shadowColor` - Theme.colorScheme.shadow
  313. /// * `surfaceTintColor` - Theme.colorScheme.surfaceTint
  314. /// * `elevation`
  315. /// * disabled - 0
  316. /// * default - 1
  317. /// * hovered - 3
  318. /// * focused or pressed - 1
  319. /// * `padding`
  320. /// * `textScaleFactor <= 1` - horizontal(16)
  321. /// * `1 < textScaleFactor <= 2` - lerp(horizontal(16), horizontal(8))
  322. /// * `2 < textScaleFactor <= 3` - lerp(horizontal(8), horizontal(4))
  323. /// * `3 < textScaleFactor` - horizontal(4)
  324. /// * `minimumSize` - Size(64, 40)
  325. /// * `fixedSize` - null
  326. /// * `maximumSize` - Size.infinite
  327. /// * `side` - null
  328. /// * `shape` - StadiumBorder()
  329. /// * `mouseCursor`
  330. /// * disabled - SystemMouseCursors.basic
  331. /// * others - SystemMouseCursors.click
  332. /// * `visualDensity` - Theme.visualDensity
  333. /// * `tapTargetSize` - Theme.materialTapTargetSize
  334. /// * `animationDuration` - kThemeChangeDuration
  335. /// * `enableFeedback` - true
  336. /// * `alignment` - Alignment.center
  337. /// * `splashFactory` - Theme.splashFactory
  338. @override
  339. ButtonStyle defaultStyleOf(BuildContext context) {
  340. final ThemeData theme = Theme.of(context);
  341. final ColorScheme colorScheme = theme.colorScheme;
  342. return Theme.of(context).useMaterial3
  343. ? _ElevatedButtonDefaultsM3(context)
  344. : styleFrom(
  345. backgroundColor: colorScheme.primary,
  346. foregroundColor: colorScheme.onPrimary,
  347. disabledBackgroundColor: colorScheme.onSurface.withOpacity(0.12),
  348. disabledForegroundColor: colorScheme.onSurface.withOpacity(0.38),
  349. shadowColor: theme.shadowColor,
  350. elevation: 2,
  351. textStyle: theme.textTheme.labelLarge,
  352. padding: _scaledPadding(context),
  353. minimumSize: Size(64.s, 36.s),
  354. maximumSize: Size.infinite,
  355. shape: RoundedRectangleBorder(
  356. borderRadius: BorderRadius.all(Radius.circular(4.s))),
  357. enabledMouseCursor: SystemMouseCursors.click,
  358. disabledMouseCursor: SystemMouseCursors.basic,
  359. visualDensity: theme.visualDensity,
  360. tapTargetSize: theme.materialTapTargetSize,
  361. animationDuration: kThemeChangeDuration,
  362. enableFeedback: true,
  363. alignment: Alignment.center,
  364. splashFactory: InkRipple.splashFactory,
  365. );
  366. }
  367. /// Returns the [ElevatedButtonThemeData.style] of the closest
  368. /// [ElevatedButtonTheme] ancestor.
  369. @override
  370. ButtonStyle? themeStyleOf(BuildContext context) {
  371. return ElevatedButtonTheme.of(context).style;
  372. }
  373. }
  374. EdgeInsetsGeometry _scaledPadding(BuildContext context) {
  375. return CustomButtonStyleButton.scaledPadding(
  376. EdgeInsets.symmetric(horizontal: 16.s),
  377. EdgeInsets.symmetric(horizontal: 8.s),
  378. EdgeInsets.symmetric(horizontal: 4.s),
  379. MediaQuery.maybeOf(context)?.textScaleFactor ?? 1,
  380. );
  381. }
  382. @immutable
  383. class _ElevatedButtonDefaultColor extends MaterialStateProperty<Color?>
  384. with Diagnosticable {
  385. _ElevatedButtonDefaultColor(this.color, this.disabled);
  386. final Color? color;
  387. final Color? disabled;
  388. @override
  389. Color? resolve(Set<MaterialState> states) {
  390. if (states.contains(MaterialState.disabled)) {
  391. return disabled;
  392. }
  393. return color;
  394. }
  395. }
  396. @immutable
  397. class _ElevatedButtonDefaultOverlay extends MaterialStateProperty<Color?>
  398. with Diagnosticable {
  399. _ElevatedButtonDefaultOverlay(this.overlay);
  400. final Color overlay;
  401. @override
  402. Color? resolve(Set<MaterialState> states) {
  403. if (states.contains(MaterialState.hovered)) {
  404. return overlay.withOpacity(0.08);
  405. }
  406. if (states.contains(MaterialState.focused) ||
  407. states.contains(MaterialState.pressed)) {
  408. return overlay.withOpacity(0.24);
  409. }
  410. return null;
  411. }
  412. }
  413. @immutable
  414. class _ElevatedButtonDefaultElevation extends MaterialStateProperty<double>
  415. with Diagnosticable {
  416. _ElevatedButtonDefaultElevation(this.elevation);
  417. final double elevation;
  418. @override
  419. double resolve(Set<MaterialState> states) {
  420. if (states.contains(MaterialState.disabled)) {
  421. return 0;
  422. }
  423. if (states.contains(MaterialState.hovered)) {
  424. return elevation + 2;
  425. }
  426. if (states.contains(MaterialState.focused)) {
  427. return elevation + 2;
  428. }
  429. if (states.contains(MaterialState.pressed)) {
  430. return elevation + 6;
  431. }
  432. return elevation;
  433. }
  434. }
  435. @immutable
  436. class _ElevatedButtonDefaultMouseCursor
  437. extends MaterialStateProperty<MouseCursor?> with Diagnosticable {
  438. _ElevatedButtonDefaultMouseCursor(this.enabledCursor, this.disabledCursor);
  439. final MouseCursor? enabledCursor;
  440. final MouseCursor? disabledCursor;
  441. @override
  442. MouseCursor? resolve(Set<MaterialState> states) {
  443. if (states.contains(MaterialState.disabled)) {
  444. return disabledCursor;
  445. }
  446. return enabledCursor;
  447. }
  448. }
  449. class _ElevatedButtonWithIcon extends CustomElevatedButton {
  450. _ElevatedButtonWithIcon({
  451. super.key,
  452. required super.onPressed,
  453. super.onLongPress,
  454. super.onHover,
  455. super.onFocusChange,
  456. super.style,
  457. super.focusNode,
  458. bool? autofocus,
  459. Clip? clipBehavior,
  460. super.statesController,
  461. required Widget icon,
  462. required Widget label,
  463. }) : assert(icon != null),
  464. assert(label != null),
  465. super(
  466. autofocus: autofocus ?? false,
  467. clipBehavior: clipBehavior ?? Clip.none,
  468. child: _ElevatedButtonWithIconChild(icon: icon, label: label),
  469. );
  470. @override
  471. ButtonStyle defaultStyleOf(BuildContext context) {
  472. final EdgeInsetsGeometry scaledPadding =
  473. CustomButtonStyleButton.scaledPadding(
  474. EdgeInsetsDirectional.fromSTEB(12.s, 0, 16.s, 0),
  475. EdgeInsets.symmetric(horizontal: 8.s),
  476. EdgeInsetsDirectional.fromSTEB(8.s, 0, 4.s, 0),
  477. MediaQuery.maybeOf(context)?.textScaleFactor ?? 1,
  478. );
  479. return super.defaultStyleOf(context).copyWith(
  480. padding: MaterialStatePropertyAll<EdgeInsetsGeometry>(scaledPadding),
  481. );
  482. }
  483. }
  484. class _ElevatedButtonWithIconChild extends StatelessWidget {
  485. const _ElevatedButtonWithIconChild({required this.label, required this.icon});
  486. final Widget label;
  487. final Widget icon;
  488. @override
  489. Widget build(BuildContext context) {
  490. final double scale = MediaQuery.maybeOf(context)?.textScaleFactor ?? 1;
  491. final double gap =
  492. scale <= 1 ? 8 : lerpDouble(8, 4, math.min(scale - 1, 1))!;
  493. return Row(
  494. mainAxisSize: MainAxisSize.min,
  495. children: <Widget>[icon, SizedBox(width: gap.s), Flexible(child: label)],
  496. );
  497. }
  498. }
  499. // BEGIN GENERATED TOKEN PROPERTIES - ElevatedButton
  500. // Do not edit by hand. The code between the "BEGIN GENERATED" and
  501. // "END GENERATED" comments are generated from data in the Material
  502. // Design token database by the script:
  503. // dev/tools/gen_defaults/bin/gen_defaults.dart.
  504. // Token database version: v0_132
  505. class _ElevatedButtonDefaultsM3 extends ButtonStyle {
  506. _ElevatedButtonDefaultsM3(this.context)
  507. : super(
  508. animationDuration: kThemeChangeDuration,
  509. enableFeedback: true,
  510. alignment: Alignment.center,
  511. );
  512. final BuildContext context;
  513. late final ColorScheme _colors = Theme.of(context).colorScheme;
  514. @override
  515. MaterialStateProperty<TextStyle?> get textStyle =>
  516. MaterialStatePropertyAll<TextStyle?>(
  517. Theme.of(context).textTheme.labelLarge);
  518. @override
  519. MaterialStateProperty<Color?>? get backgroundColor =>
  520. MaterialStateProperty.resolveWith((Set<MaterialState> states) {
  521. if (states.contains(MaterialState.disabled)) {
  522. return _colors.onSurface.withOpacity(0.12);
  523. }
  524. return _colors.surface;
  525. });
  526. @override
  527. MaterialStateProperty<Color?>? get foregroundColor =>
  528. MaterialStateProperty.resolveWith((Set<MaterialState> states) {
  529. if (states.contains(MaterialState.disabled)) {
  530. return _colors.onSurface.withOpacity(0.38);
  531. }
  532. return _colors.primary;
  533. });
  534. @override
  535. MaterialStateProperty<Color?>? get overlayColor =>
  536. MaterialStateProperty.resolveWith((Set<MaterialState> states) {
  537. if (states.contains(MaterialState.hovered)) {
  538. return _colors.primary.withOpacity(0.08);
  539. }
  540. if (states.contains(MaterialState.focused)) {
  541. return _colors.primary.withOpacity(0.12);
  542. }
  543. if (states.contains(MaterialState.pressed)) {
  544. return _colors.primary.withOpacity(0.12);
  545. }
  546. return null;
  547. });
  548. @override
  549. MaterialStateProperty<Color>? get shadowColor =>
  550. MaterialStatePropertyAll<Color>(_colors.shadow);
  551. @override
  552. MaterialStateProperty<Color>? get surfaceTintColor =>
  553. MaterialStatePropertyAll<Color>(_colors.surfaceTint);
  554. @override
  555. MaterialStateProperty<double>? get elevation =>
  556. MaterialStateProperty.resolveWith((Set<MaterialState> states) {
  557. if (states.contains(MaterialState.disabled)) {
  558. return 0.0;
  559. }
  560. if (states.contains(MaterialState.hovered)) {
  561. return 3.0;
  562. }
  563. if (states.contains(MaterialState.focused)) {
  564. return 1.0;
  565. }
  566. if (states.contains(MaterialState.pressed)) {
  567. return 1.0;
  568. }
  569. return 1.0;
  570. });
  571. @override
  572. MaterialStateProperty<EdgeInsetsGeometry>? get padding =>
  573. MaterialStatePropertyAll<EdgeInsetsGeometry>(_scaledPadding(context));
  574. @override
  575. MaterialStateProperty<Size>? get minimumSize =>
  576. MaterialStatePropertyAll<Size>(Size(64.s, 40.s));
  577. // No default fixedSize
  578. @override
  579. MaterialStateProperty<Size>? get maximumSize =>
  580. const MaterialStatePropertyAll<Size>(Size.infinite);
  581. // No default side
  582. @override
  583. MaterialStateProperty<OutlinedBorder>? get shape =>
  584. const MaterialStatePropertyAll<OutlinedBorder>(StadiumBorder());
  585. @override
  586. MaterialStateProperty<MouseCursor?>? get mouseCursor =>
  587. MaterialStateProperty.resolveWith((Set<MaterialState> states) {
  588. if (states.contains(MaterialState.disabled)) {
  589. return SystemMouseCursors.basic;
  590. }
  591. return SystemMouseCursors.click;
  592. });
  593. @override
  594. VisualDensity? get visualDensity => Theme.of(context).visualDensity;
  595. @override
  596. MaterialTapTargetSize? get tapTargetSize =>
  597. Theme.of(context).materialTapTargetSize;
  598. @override
  599. InteractiveInkFeatureFactory? get splashFactory =>
  600. Theme.of(context).splashFactory;
  601. }
  602. // END GENERATED TOKEN PROPERTIES - ElevatedButton