Skip to content
Draft
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
8 changes: 8 additions & 0 deletions packages/material_ui/lib/material_3.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// 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.

/// Flutter widgets implementing Material Design 3.
library material_3;

export 'material_ui.dart';
9 changes: 9 additions & 0 deletions packages/material_ui/lib/material_3_expressive.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// 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.

/// Flutter widgets implementing Material 3 Expressive.
library material_3_expressive;

export 'material_ui.dart' hide IconButton;
export 'src/material_3_expressive/icon_button.dart';
60 changes: 58 additions & 2 deletions packages/material_ui/lib/src/button_style.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2014 The Flutter Authors. All rights reserved.
// 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.

Expand Down Expand Up @@ -31,6 +31,38 @@ import 'theme_data.dart';
// late BuildContext context;
// typedef MyAppHome = Placeholder;

/// Defines size variants for Material 3 Expressive button components.
///
/// Components interpret each size variant according to their own token set.
enum ButtonSize {
/// Extra small button size.
xSmall,

/// Small button size. This is the default for icon buttons.
small,

/// Medium button size.
medium,

/// Large button size.
large,

/// Extra large button size.
xLarge,
}

/// Defines the width variants for Material 3 Expressive [IconButton].
enum IconButtonWidth {
/// Uses the narrow leading and trailing space tokens.
narrow,

/// Uses the default leading and trailing space tokens.
standard,

/// Uses the wide leading and trailing space tokens.
wide,
}

/// The type for [ButtonStyle.backgroundBuilder] and [ButtonStyle.foregroundBuilder].
///
/// The [states] parameter is the button's current pressed/hovered/etc state. The [child] is
Expand Down Expand Up @@ -187,6 +219,8 @@ class ButtonStyle with Diagnosticable {
this.splashFactory,
this.backgroundBuilder,
this.foregroundBuilder,
this.size,
this.iconButtonWidth,
});

/// The style for a button's [Text] widget descendants.
Expand Down Expand Up @@ -423,6 +457,12 @@ class ButtonStyle with Diagnosticable {
/// configuring clipping.
final ButtonLayerBuilder? foregroundBuilder;

/// The size variant for this button.
final ButtonSize? size;

/// The width variant for this icon button.
final IconButtonWidth? iconButtonWidth;

/// Returns a copy of this ButtonStyle with the given fields replaced with
/// the new values.
ButtonStyle copyWith({
Expand Down Expand Up @@ -451,6 +491,8 @@ class ButtonStyle with Diagnosticable {
InteractiveInkFeatureFactory? splashFactory,
ButtonLayerBuilder? backgroundBuilder,
ButtonLayerBuilder? foregroundBuilder,
ButtonSize? size,
IconButtonWidth? iconButtonWidth,
}) {
return ButtonStyle(
textStyle: textStyle ?? this.textStyle,
Expand Down Expand Up @@ -478,6 +520,8 @@ class ButtonStyle with Diagnosticable {
splashFactory: splashFactory ?? this.splashFactory,
backgroundBuilder: backgroundBuilder ?? this.backgroundBuilder,
foregroundBuilder: foregroundBuilder ?? this.foregroundBuilder,
size: size ?? this.size,
iconButtonWidth: iconButtonWidth ?? this.iconButtonWidth,
);
}

Expand Down Expand Up @@ -516,6 +560,8 @@ class ButtonStyle with Diagnosticable {
splashFactory: splashFactory ?? style.splashFactory,
backgroundBuilder: backgroundBuilder ?? style.backgroundBuilder,
foregroundBuilder: foregroundBuilder ?? style.foregroundBuilder,
size: size ?? style.size,
iconButtonWidth: iconButtonWidth ?? style.iconButtonWidth,
);
}

Expand Down Expand Up @@ -547,6 +593,8 @@ class ButtonStyle with Diagnosticable {
splashFactory,
backgroundBuilder,
foregroundBuilder,
size,
iconButtonWidth,
];
return Object.hashAll(values);
}
Expand Down Expand Up @@ -584,7 +632,9 @@ class ButtonStyle with Diagnosticable {
other.alignment == alignment &&
other.splashFactory == splashFactory &&
other.backgroundBuilder == backgroundBuilder &&
other.foregroundBuilder == foregroundBuilder;
other.foregroundBuilder == foregroundBuilder &&
other.size == size &&
other.iconButtonWidth == iconButtonWidth;
}

@override
Expand Down Expand Up @@ -706,6 +756,10 @@ class ButtonStyle with Diagnosticable {
defaultValue: null,
),
);
properties.add(EnumProperty<ButtonSize>('size', size, defaultValue: null));
properties.add(
EnumProperty<IconButtonWidth>('iconButtonWidth', iconButtonWidth, defaultValue: null),
);
}

/// Linearly interpolate between two [ButtonStyle]s.
Expand Down Expand Up @@ -769,6 +823,8 @@ class ButtonStyle with Diagnosticable {
splashFactory: t < 0.5 ? a?.splashFactory : b?.splashFactory,
backgroundBuilder: t < 0.5 ? a?.backgroundBuilder : b?.backgroundBuilder,
foregroundBuilder: t < 0.5 ? a?.foregroundBuilder : b?.foregroundBuilder,
size: t < 0.5 ? a?.size : b?.size,
iconButtonWidth: t < 0.5 ? a?.iconButtonWidth : b?.iconButtonWidth,
);
}
}
13 changes: 12 additions & 1 deletion packages/material_ui/lib/src/button_style_button.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2014 The Flutter Authors. All rights reserved.
// 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.

Expand Down Expand Up @@ -87,6 +87,7 @@ abstract class ButtonStyleButton extends StatefulWidget {
required this.clipBehavior,
this.statesController,
this.isSemanticButton = true,
this.isSelected,
@Deprecated(
'Remove this parameter as it is now ignored. '
'Use ButtonStyle.iconAlignment instead. '
Expand Down Expand Up @@ -163,6 +164,9 @@ abstract class ButtonStyleButton extends StatefulWidget {
/// Defaults to true.
final bool? isSemanticButton;

/// Whether the button is selected.
final bool? isSelected;

/// {@macro flutter.material.ButtonStyle.iconAlignment}
@Deprecated(
'Remove this parameter as it is now ignored. '
Expand Down Expand Up @@ -334,6 +338,9 @@ class _ButtonStyleState extends State<ButtonStyleButton> with TickerProviderStat
internalStatesController = MaterialStatesController();
}
statesController.update(WidgetState.disabled, !widget.enabled);
if (widget.isSelected != null) {
statesController.update(WidgetState.selected, widget.isSelected!);
}
statesController.addListener(handleStatesControllerChange);
}

Expand Down Expand Up @@ -361,6 +368,9 @@ class _ButtonStyleState extends State<ButtonStyleButton> with TickerProviderStat
statesController.update(WidgetState.pressed, false);
}
}
if (widget.isSelected != oldWidget.isSelected) {
statesController.update(WidgetState.selected, widget.isSelected ?? false);
}
}

@override
Expand Down Expand Up @@ -592,6 +602,7 @@ class _ButtonStyleState extends State<ButtonStyleButton> with TickerProviderStat
container: true,
button: widget.isSemanticButton,
enabled: widget.enabled,
selected: widget.isSelected,
child: _InputPadding(
minSize: minSize,
child: ConstrainedBox(
Expand Down
Loading