Unverified Commit 027bb844 authored by Ian Hickson's avatar Ian Hickson Committed by GitHub

Make SlottedMultiChildRenderObjectWidgetMixin a concrete class (#126108)

This is a proof of concept for renaming SlottedMultiChildRenderObjectWidgetMixin to SlottedMultiChildRenderObjectWidget and making it a concrete class.

I also made SlottedContainerRenderObjectMixin generic instead of being specialized to RenderBox.

I don't think this is something we can easily automigrate, but we may not need to, I don't know how common this is...
parent 5235a0f0
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart'; import 'package:flutter/rendering.dart';
/// Flutter code sample for [SlottedMultiChildRenderObjectWidgetMixin]. /// Flutter code sample for [SlottedMultiChildRenderObjectWidget].
/// Slots used for the children of [Diagonal] and [RenderDiagonal]. /// Slots used for the children of [Diagonal] and [RenderDiagonal].
enum DiagonalSlot { enum DiagonalSlot {
...@@ -14,9 +14,9 @@ enum DiagonalSlot { ...@@ -14,9 +14,9 @@ enum DiagonalSlot {
} }
/// A widget that demonstrates the usage of /// A widget that demonstrates the usage of
/// [SlottedMultiChildRenderObjectWidgetMixin] by providing slots for two /// [SlottedMultiChildRenderObjectWidget] by providing slots for two
/// children that will be arranged diagonally. /// children that will be arranged diagonally.
class Diagonal extends RenderObjectWidget with SlottedMultiChildRenderObjectWidgetMixin<DiagonalSlot> { class Diagonal extends SlottedMultiChildRenderObjectWidget<DiagonalSlot, RenderBox> {
const Diagonal({ const Diagonal({
super.key, super.key,
this.topLeft, this.topLeft,
...@@ -49,7 +49,7 @@ class Diagonal extends RenderObjectWidget with SlottedMultiChildRenderObjectWidg ...@@ -49,7 +49,7 @@ class Diagonal extends RenderObjectWidget with SlottedMultiChildRenderObjectWidg
// [SlottedRenderObjectElement.update]. // [SlottedRenderObjectElement.update].
@override @override
SlottedContainerRenderObjectMixin<DiagonalSlot> createRenderObject( SlottedContainerRenderObjectMixin<DiagonalSlot, RenderBox> createRenderObject(
BuildContext context, BuildContext context,
) { ) {
return RenderDiagonal( return RenderDiagonal(
...@@ -60,7 +60,7 @@ class Diagonal extends RenderObjectWidget with SlottedMultiChildRenderObjectWidg ...@@ -60,7 +60,7 @@ class Diagonal extends RenderObjectWidget with SlottedMultiChildRenderObjectWidg
@override @override
void updateRenderObject( void updateRenderObject(
BuildContext context, BuildContext context,
SlottedContainerRenderObjectMixin<DiagonalSlot> renderObject, SlottedContainerRenderObjectMixin<DiagonalSlot, RenderBox> renderObject,
) { ) {
(renderObject as RenderDiagonal).backgroundColor = backgroundColor; (renderObject as RenderDiagonal).backgroundColor = backgroundColor;
} }
...@@ -70,7 +70,7 @@ class Diagonal extends RenderObjectWidget with SlottedMultiChildRenderObjectWidg ...@@ -70,7 +70,7 @@ class Diagonal extends RenderObjectWidget with SlottedMultiChildRenderObjectWidg
/// [SlottedContainerRenderObjectMixin] by providing slots for two children that /// [SlottedContainerRenderObjectMixin] by providing slots for two children that
/// will be arranged diagonally. /// will be arranged diagonally.
class RenderDiagonal extends RenderBox class RenderDiagonal extends RenderBox
with SlottedContainerRenderObjectMixin<DiagonalSlot>, DebugOverflowIndicatorMixin { with SlottedContainerRenderObjectMixin<DiagonalSlot, RenderBox>, DebugOverflowIndicatorMixin {
RenderDiagonal({Color? backgroundColor}) : _backgroundColor = backgroundColor; RenderDiagonal({Color? backgroundColor}) : _backgroundColor = backgroundColor;
// Getters and setters to configure the [RenderObject] with the configuration // Getters and setters to configure the [RenderObject] with the configuration
......
...@@ -1342,7 +1342,7 @@ class _RenderChipRedirectingHitDetection extends RenderConstrainedBox { ...@@ -1342,7 +1342,7 @@ class _RenderChipRedirectingHitDetection extends RenderConstrainedBox {
} }
} }
class _ChipRenderWidget extends RenderObjectWidget with SlottedMultiChildRenderObjectWidgetMixin<_ChipSlot> { class _ChipRenderWidget extends SlottedMultiChildRenderObjectWidget<_ChipSlot, RenderBox> {
const _ChipRenderWidget({ const _ChipRenderWidget({
required this.theme, required this.theme,
this.value, this.value,
...@@ -1393,7 +1393,7 @@ class _ChipRenderWidget extends RenderObjectWidget with SlottedMultiChildRenderO ...@@ -1393,7 +1393,7 @@ class _ChipRenderWidget extends RenderObjectWidget with SlottedMultiChildRenderO
} }
@override @override
SlottedContainerRenderObjectMixin<_ChipSlot> createRenderObject(BuildContext context) { SlottedContainerRenderObjectMixin<_ChipSlot, RenderBox> createRenderObject(BuildContext context) {
return _RenderChip( return _RenderChip(
theme: theme, theme: theme,
textDirection: Directionality.of(context), textDirection: Directionality.of(context),
...@@ -1478,7 +1478,7 @@ class _ChipRenderTheme { ...@@ -1478,7 +1478,7 @@ class _ChipRenderTheme {
); );
} }
class _RenderChip extends RenderBox with SlottedContainerRenderObjectMixin<_ChipSlot> { class _RenderChip extends RenderBox with SlottedContainerRenderObjectMixin<_ChipSlot, RenderBox> {
_RenderChip({ _RenderChip({
required _ChipRenderTheme theme, required _ChipRenderTheme theme,
required TextDirection textDirection, required TextDirection textDirection,
......
...@@ -693,7 +693,7 @@ class _RenderDecorationLayout { ...@@ -693,7 +693,7 @@ class _RenderDecorationLayout {
} }
// The workhorse: layout and paint a _Decorator widget's _Decoration. // The workhorse: layout and paint a _Decorator widget's _Decoration.
class _RenderDecoration extends RenderBox with SlottedContainerRenderObjectMixin<_DecorationSlot> { class _RenderDecoration extends RenderBox with SlottedContainerRenderObjectMixin<_DecorationSlot, RenderBox> {
_RenderDecoration({ _RenderDecoration({
required _Decoration decoration, required _Decoration decoration,
required TextDirection textDirection, required TextDirection textDirection,
...@@ -1637,7 +1637,7 @@ class _RenderDecoration extends RenderBox with SlottedContainerRenderObjectMixin ...@@ -1637,7 +1637,7 @@ class _RenderDecoration extends RenderBox with SlottedContainerRenderObjectMixin
} }
} }
class _Decorator extends RenderObjectWidget with SlottedMultiChildRenderObjectWidgetMixin<_DecorationSlot> { class _Decorator extends SlottedMultiChildRenderObjectWidget<_DecorationSlot, RenderBox> {
const _Decorator({ const _Decorator({
required this.textAlignVertical, required this.textAlignVertical,
required this.decoration, required this.decoration,
......
...@@ -967,7 +967,7 @@ enum _ListTileSlot { ...@@ -967,7 +967,7 @@ enum _ListTileSlot {
trailing, trailing,
} }
class _ListTile extends RenderObjectWidget with SlottedMultiChildRenderObjectWidgetMixin<_ListTileSlot> { class _ListTile extends SlottedMultiChildRenderObjectWidget<_ListTileSlot, RenderBox> {
const _ListTile({ const _ListTile({
this.leading, this.leading,
required this.title, required this.title,
...@@ -1049,7 +1049,7 @@ class _ListTile extends RenderObjectWidget with SlottedMultiChildRenderObjectWid ...@@ -1049,7 +1049,7 @@ class _ListTile extends RenderObjectWidget with SlottedMultiChildRenderObjectWid
} }
} }
class _RenderListTile extends RenderBox with SlottedContainerRenderObjectMixin<_ListTileSlot> { class _RenderListTile extends RenderBox with SlottedContainerRenderObjectMixin<_ListTileSlot, RenderBox> {
_RenderListTile({ _RenderListTile({
required bool isDense, required bool isDense,
required VisualDensity visualDensity, required VisualDensity visualDensity,
......
...@@ -1760,7 +1760,7 @@ abstract class InheritedWidget extends ProxyWidget { ...@@ -1760,7 +1760,7 @@ abstract class InheritedWidget extends ProxyWidget {
/// ///
/// * [MultiChildRenderObjectWidget], which configures a [RenderObject] with /// * [MultiChildRenderObjectWidget], which configures a [RenderObject] with
/// a single list of children. /// a single list of children.
/// * [SlottedMultiChildRenderObjectWidgetMixin], which configures a /// * [SlottedMultiChildRenderObjectWidget], which configures a
/// [RenderObject] that organizes its children in different named slots. /// [RenderObject] that organizes its children in different named slots.
abstract class RenderObjectWidget extends Widget { abstract class RenderObjectWidget extends Widget {
/// Abstract const constructor. This constructor enables subclasses to provide /// Abstract const constructor. This constructor enables subclasses to provide
...@@ -1854,7 +1854,7 @@ abstract class SingleChildRenderObjectWidget extends RenderObjectWidget { ...@@ -1854,7 +1854,7 @@ abstract class SingleChildRenderObjectWidget extends RenderObjectWidget {
/// * [Stack], which uses [MultiChildRenderObjectWidget]. /// * [Stack], which uses [MultiChildRenderObjectWidget].
/// * [RenderStack], for an example implementation of the associated render /// * [RenderStack], for an example implementation of the associated render
/// object. /// object.
/// * [SlottedMultiChildRenderObjectWidgetMixin], which configures a /// * [SlottedMultiChildRenderObjectWidget], which configures a
/// [RenderObject] that instead of having a single list of children organizes /// [RenderObject] that instead of having a single list of children organizes
/// its children in named slots. /// its children in named slots.
abstract class MultiChildRenderObjectWidget extends RenderObjectWidget { abstract class MultiChildRenderObjectWidget extends RenderObjectWidget {
......
...@@ -269,7 +269,7 @@ enum _DiagonalSlot { ...@@ -269,7 +269,7 @@ enum _DiagonalSlot {
bottomRight, bottomRight,
} }
class _Diagonal extends RenderObjectWidget with SlottedMultiChildRenderObjectWidgetMixin<_DiagonalSlot?> { class _Diagonal extends RenderObjectWidget with SlottedMultiChildRenderObjectWidgetMixin<_DiagonalSlot?, RenderBox> {
const _Diagonal({ const _Diagonal({
this.topLeft, this.topLeft,
this.bottomRight, this.bottomRight,
...@@ -296,14 +296,14 @@ class _Diagonal extends RenderObjectWidget with SlottedMultiChildRenderObjectWid ...@@ -296,14 +296,14 @@ class _Diagonal extends RenderObjectWidget with SlottedMultiChildRenderObjectWid
} }
@override @override
SlottedContainerRenderObjectMixin<_DiagonalSlot?> createRenderObject( SlottedContainerRenderObjectMixin<_DiagonalSlot?, RenderBox> createRenderObject(
BuildContext context, BuildContext context,
) { ) {
return _RenderDiagonal(); return _RenderDiagonal();
} }
} }
class _RenderDiagonal extends RenderBox with SlottedContainerRenderObjectMixin<_DiagonalSlot?> { class _RenderDiagonal extends RenderBox with SlottedContainerRenderObjectMixin<_DiagonalSlot?, RenderBox> {
RenderBox? get _topLeft => childForSlot(_DiagonalSlot.topLeft); RenderBox? get _topLeft => childForSlot(_DiagonalSlot.topLeft);
RenderBox? get _bottomRight => childForSlot(_DiagonalSlot.bottomRight); RenderBox? get _bottomRight => childForSlot(_DiagonalSlot.bottomRight);
RenderBox? get _nullSlot => childForSlot(null); RenderBox? get _nullSlot => childForSlot(null);
...@@ -370,6 +370,6 @@ class _Slot { ...@@ -370,6 +370,6 @@ class _Slot {
String toString() => describeIdentity(this); String toString() => describeIdentity(this);
} }
class _RenderTest extends RenderBox with SlottedContainerRenderObjectMixin<_Slot> { class _RenderTest extends RenderBox with SlottedContainerRenderObjectMixin<_Slot, RenderBox> {
String publicNameForSlot(_Slot slot) => debugNameForSlot(slot); String publicNameForSlot(_Slot slot) => debugNameForSlot(slot);
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment