MaterialStateOutlinedBorder typedef
- @Deprecated('Use WidgetStateOutlinedBorder instead. ' 'Moved to the Widgets layer to make code available outside of Material. ' 'This feature was deprecated after v3.19.0-0.3.pre.')
Defines an OutlinedBorder whose value depends on a set of MaterialStates which represent the interactive state of a component.
To use a MaterialStateOutlinedBorder, you should create a subclass of an
OutlinedBorder and implement MaterialStateOutlinedBorder's abstract
resolve method.
This example defines a subclass of RoundedRectangleBorder and an implementation of MaterialStateOutlinedBorder, that resolves to RoundedRectangleBorder when its widget is selected.
To see it in action, copy and run this code snippet on DartPad.
import 'package:material_ui/material_ui.dart';
/// Flutter code sample for [WidgetStateOutlinedBorder].
void main() => runApp(const WidgetStateOutlinedBorderExampleApp());
class WidgetStateOutlinedBorderExampleApp extends StatelessWidget {
const WidgetStateOutlinedBorderExampleApp({super.key});
@override
Widget build(BuildContext context) {
return const MaterialApp(home: WidgetStateOutlinedBorderExample());
}
}
class SelectedBorder extends RoundedRectangleBorder
implements WidgetStateOutlinedBorder {
const SelectedBorder();
@override
OutlinedBorder? resolve(Set<WidgetState> states) {
if (states.contains(WidgetState.selected)) {
return const RoundedRectangleBorder();
}
return null; // Defer to default value on the theme or widget.
}
}
class WidgetStateOutlinedBorderExample extends StatefulWidget {
const WidgetStateOutlinedBorderExample({super.key});
@override
State<WidgetStateOutlinedBorderExample> createState() =>
_WidgetStateOutlinedBorderExampleState();
}
class _WidgetStateOutlinedBorderExampleState
extends State<WidgetStateOutlinedBorderExample> {
bool isSelected = true;
@override
Widget build(BuildContext context) {
return Material(
child: FilterChip(
label: const Text('Select chip'),
selected: isSelected,
onSelected: (bool value) {
setState(() {
isSelected = value;
});
},
shape: const SelectedBorder(),
),
);
}
}
This class should only be used for parameters which are documented to take MaterialStateOutlinedBorder, otherwise only the default state will be used.
See also:
- WidgetStateOutlinedBorder, the non-Material version that can be used
interchangeably with
MaterialStateOutlinedBorder. - ShapeBorder the base class for shape outlines.
Implementation
// TODO(framework): Replace the following block with a @dartpad directive
// when it's supported. https://github.com/dart-lang/dartdoc/issues/4123
/// {@macro material_ui.dartpad_guide}
///
/// {@example /example/lib/material_state/material_state_outlined_border.0.dart#body}
///
/// </callout-box>
///
/// This class should only be used for parameters which are documented to take
/// [MaterialStateOutlinedBorder], otherwise only the default state will be used.
///
/// See also:
///
/// * [WidgetStateOutlinedBorder], the non-Material version that can be used
/// interchangeably with `MaterialStateOutlinedBorder`.
/// * [ShapeBorder] the base class for shape outlines.
@Deprecated(
'Use WidgetStateOutlinedBorder instead. '
'Moved to the Widgets layer to make code available outside of Material. '
'This feature was deprecated after v3.19.0-0.3.pre.',
)
typedef MaterialStateOutlinedBorder = WidgetStateOutlinedBorder;