Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 2 additions & 71 deletions packages/material_ui/lib/src/floating_action_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import 'text_theme.dart';
import 'theme.dart';
import 'tooltip.dart';

part 'generated/fab_defaults_m3.g.dart';

class _DefaultHeroTag {
const _DefaultHeroTag();
@override
Expand Down Expand Up @@ -781,74 +783,3 @@ class _FABDefaultsM2 extends FloatingActionButtonThemeData {
@override
TextStyle? get extendedTextStyle => _theme.textTheme.labelLarge!.copyWith(letterSpacing: 1.2);
}

// BEGIN GENERATED TOKEN PROPERTIES - FAB

// 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.

// dart format off
class _FABDefaultsM3 extends FloatingActionButtonThemeData {
_FABDefaultsM3(this.context, this.type, this.hasChild)
: super(
elevation: 6.0,
focusElevation: 6.0,
hoverElevation: 8.0,
highlightElevation: 6.0,
enableFeedback: true,
sizeConstraints: const BoxConstraints.tightFor(
width: 56.0,
height: 56.0,
),
smallSizeConstraints: const BoxConstraints.tightFor(
width: 40.0,
height: 40.0,
),
largeSizeConstraints: const BoxConstraints.tightFor(
width: 96.0,
height: 96.0,
),
extendedSizeConstraints: const BoxConstraints.tightFor(
height: 56.0,
),
extendedIconLabelSpacing: 8.0,
);

final BuildContext context;
final _FloatingActionButtonType type;
final bool hasChild;
late final ColorScheme _colors = Theme.of(context).colorScheme;
late final TextTheme _textTheme = Theme.of(context).textTheme;

bool get _isExtended => type == _FloatingActionButtonType.extended;

@override Color? get foregroundColor => _colors.onPrimaryContainer;
@override Color? get backgroundColor => _colors.primaryContainer;
@override Color? get splashColor => _colors.onPrimaryContainer.withOpacity(0.1);
@override Color? get focusColor => _colors.onPrimaryContainer.withOpacity(0.1);
@override Color? get hoverColor => _colors.onPrimaryContainer.withOpacity(0.08);

@override
ShapeBorder? get shape => switch (type) {
_FloatingActionButtonType.regular => const RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(16.0))),
_FloatingActionButtonType.small => const RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(12.0))),
_FloatingActionButtonType.large => const RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(28.0))),
_FloatingActionButtonType.extended => const RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(16.0))),
};

@override
double? get iconSize => switch (type) {
_FloatingActionButtonType.regular => 24.0,
_FloatingActionButtonType.small => 24.0,
_FloatingActionButtonType.large => 36.0,
_FloatingActionButtonType.extended => 24.0,
};

@override EdgeInsetsGeometry? get extendedPadding => EdgeInsetsDirectional.only(start: hasChild && _isExtended ? 16.0 : 20.0, end: 20.0);
@override TextStyle? get extendedTextStyle => _textTheme.labelLarge;
}
// dart format on

// END GENERATED TOKEN PROPERTIES - FAB
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// Do not edit by hand. The code is generated from data in the Material
// Design token database by the script:
// packages/material_ui/tool/gen_defaults/bin/gen_defaults.dart.
part of '../floating_action_button.dart';

class _FABDefaultsM3 extends FloatingActionButtonThemeData {
_FABDefaultsM3(this.context, this.type, this.hasChild)
: super(
Expand Down
4 changes: 2 additions & 2 deletions packages/material_ui/tool/gen_defaults/bin/gen_defaults.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import '../templates/card_template.dart';
// import '../templates/divider_template.dart';
// import '../templates/drawer_template.dart';
// import '../templates/expansion_tile_template.dart';
// import '../templates/fab_template.dart';
import '../templates/fab_template.dart';
// import '../templates/filter_chip_template.dart';
// import '../templates/icon_button_template.dart';
// import '../templates/input_chip_template.dart';
Expand Down Expand Up @@ -86,7 +86,7 @@ Future<void> main(List<String> args) async {
// const DividerTemplateM3().generateFile(verbose: verbose);
// const DrawerTemplateM3().generateFile(verbose: verbose);
// const ExpansionTileTemplateM3().generateFile(verbose: verbose);
// const FabTemplateM3().generateFile(verbose: verbose);
const FabTemplateM3().generateFile(verbose: verbose);
// const FilterChipTemplateM3().generateFile(verbose: verbose);
// const IconButtonTemplateM3().generateFile(verbose: verbose);
// const InputChipTemplateM3().generateFile(verbose: verbose);
Expand Down
87 changes: 87 additions & 0 deletions packages/material_ui/tool/gen_defaults/templates/fab_template.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
// Copyright 2013 The Flutter Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import '../data/extended_fab.dart';
import '../data/fab.dart';
import '../data/fab_large.dart';
import '../data/fab_primary_container.dart';
import '../data/fab_small.dart';
import 'template.dart';

class FabTemplateM3 extends TokenTemplateM3 {
const FabTemplateM3();

@override
String get name => 'FAB';

@override
String get parentFilePath => 'floating_action_button.dart';

@override
String get className => '_FABDefaultsM3';

@override
String generateContents(String className) =>
'''
class $className extends FloatingActionButtonThemeData {
$className(this.context, this.type, this.hasChild)
: super(
elevation: ${number(TokenFabPrimaryContainer.containerElevation)},
focusElevation: ${number(TokenFabPrimaryContainer.focusedContainerElevation)},
hoverElevation: ${number(TokenFabPrimaryContainer.hoveredContainerElevation)},
highlightElevation: ${number(TokenFabPrimaryContainer.pressedContainerElevation)},
enableFeedback: true,
sizeConstraints: const BoxConstraints.tightFor(
width: ${number(TokenFab.containerWidth)},
height: ${number(TokenFab.containerHeight)},
),
smallSizeConstraints: const BoxConstraints.tightFor(
width: ${number(TokenFabSmall.containerWidth)},
height: ${number(TokenFabSmall.containerHeight)},
),
largeSizeConstraints: const BoxConstraints.tightFor(
width: ${number(TokenFabLarge.containerWidth)},
height: ${number(TokenFabLarge.containerHeight)},
),
extendedSizeConstraints: const BoxConstraints.tightFor(
height: ${number(TokenExtendedFab.containerHeight)},
),
extendedIconLabelSpacing: 8.0,
);

final BuildContext context;
final _FloatingActionButtonType type;
final bool hasChild;
late final ColorScheme _colors = Theme.of(context).colorScheme;
late final TextTheme _textTheme = Theme.of(context).textTheme;

bool get _isExtended => type == _FloatingActionButtonType.extended;

@override Color? get foregroundColor => ${color(TokenFabPrimaryContainer.iconColor)};
@override Color? get backgroundColor => ${color(TokenFabPrimaryContainer.containerColor)};
@override Color? get splashColor => ${colorWithOpacity(TokenFabPrimaryContainer.pressedStateLayerColor, TokenFabPrimaryContainer.pressedStateLayerOpacity)};
@override Color? get focusColor => ${colorWithOpacity(TokenFabPrimaryContainer.focusedStateLayerColor, TokenFabPrimaryContainer.focusedStateLayerOpacity)};
@override Color? get hoverColor => ${colorWithOpacity(TokenFabPrimaryContainer.hoveredStateLayerColor, TokenFabPrimaryContainer.hoveredStateLayerOpacity)};

@override
ShapeBorder? get shape => switch (type) {
_FloatingActionButtonType.regular => ${shape(TokenFab.containerShape)},
_FloatingActionButtonType.small => ${shape(TokenFabSmall.containerShape)},
_FloatingActionButtonType.large => ${shape(TokenFabLarge.containerShape)},
_FloatingActionButtonType.extended => ${shape(TokenExtendedFab.containerShape)},
};

@override
double? get iconSize => switch (type) {
_FloatingActionButtonType.regular => ${number(TokenFab.iconSize)},
_FloatingActionButtonType.small => ${number(TokenFabSmall.iconSize)},
_FloatingActionButtonType.large => ${number(TokenFabLarge.iconSize)},
_FloatingActionButtonType.extended => ${number(TokenExtendedFab.iconSize)},
};

@override EdgeInsetsGeometry? get extendedPadding => EdgeInsetsDirectional.only(start: hasChild && _isExtended ? ${number(TokenExtendedFab.leadingSpace)} : ${number(TokenExtendedFab.trailingSpace)}, end: ${number(TokenExtendedFab.trailingSpace)});
@override TextStyle? get extendedTextStyle => ${textStyle(TokenExtendedFab.labelText, '_textTheme')};
}
''';
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import '../templates/card_template.dart';
// import '../templates/divider_template.dart';
// import '../templates/drawer_template.dart';
// import '../templates/expansion_tile_template.dart';
// import '../templates/fab_template.dart';
import '../templates/fab_template.dart';
// import '../templates/filter_chip_template.dart';
// import '../templates/icon_button_template.dart';
// import '../templates/input_chip_template.dart';
Expand Down Expand Up @@ -509,8 +509,13 @@ void main() {
});

test('FabTemplateM3 emits M3 Fab defaults from tokens', () {
// Intentionally empty, will be implemented during migration. See:
// https://github.com/flutter/flutter/issues/187899
const template = FabTemplateM3();
expect(template.className, '_FABDefaultsM3');

final String contents = _generateContents(template);
expect(contents, contains('Color? get backgroundColor => _colors.primaryContainer'));
expect(contents, contains(RegExp(r'_FloatingActionButtonType\.large\s+=> 36\.0')));
expect(contents, contains('TextStyle? get extendedTextStyle => _textTheme.labelLarge'));
});

test('FilterChipTemplateM3 emits M3 FilterChip defaults from tokens', () {
Expand Down
Loading