-
Notifications
You must be signed in to change notification settings - Fork 28.9k
Open
Labels
P3Issues that are less important to the Flutter projectIssues that are less important to the Flutter projectframeworkflutter/packages/flutter repository. See also f: labels.flutter/packages/flutter repository. See also f: labels.team-frameworkOwned by Framework teamOwned by Framework teamtriaged-frameworkTriaged by Framework teamTriaged by Framework team
Description
Considering the test class from #155699:
class ThemedCard extends SingleChildRenderObjectWidget {
const ThemedCard({super.key}) : super(child: const SizedBox.expand());
@override
RenderPhysicalShape createRenderObject(BuildContext context) {
final CardThemeData cardTheme = CardTheme.of(context).data;
return RenderPhysicalShape(
clipper: ShapeBorderClipper(shape: cardTheme.shape ?? const RoundedRectangleBorder()),
clipBehavior: cardTheme.clipBehavior ?? Clip.antiAlias,
color: cardTheme.color ?? Colors.white,
elevation: cardTheme.elevation ?? 0.0,
shadowColor: cardTheme.shadowColor ?? Colors.black,
);
}
@override
void updateRenderObject(BuildContext context, RenderPhysicalShape renderObject) {
final CardThemeData cardTheme = CardTheme.of(context).data;
renderObject
..clipper = ShapeBorderClipper(shape: cardTheme.shape ?? const RoundedRectangleBorder())
..clipBehavior = cardTheme.clipBehavior ?? Clip.antiAlias
..color = cardTheme.color ?? Colors.white
..elevation = cardTheme.elevation ?? 0.0
..shadowColor = cardTheme.shadowColor ?? Colors.black;
}
}
It's pretty great having the ability to hook up a RenderObjectWidget
straight to an InheritedWidget
, but having a single source of truth would help to mitigate future bugs.
Proposal: make RenderObject
constructor arguments optional
class ThemedCard extends PhysicalShape {
const MyWidget({super.key});
@override
void updateRenderObject(BuildContext context, RenderPhysicalShape renderObject) {
// single source of truth!
}
}
I should probably reiterate that this isn't strictly necessary for us to do, but it'd still be wonderful.
iapicca
Metadata
Metadata
Assignees
Labels
P3Issues that are less important to the Flutter projectIssues that are less important to the Flutter projectframeworkflutter/packages/flutter repository. See also f: labels.flutter/packages/flutter repository. See also f: labels.team-frameworkOwned by Framework teamOwned by Framework teamtriaged-frameworkTriaged by Framework teamTriaged by Framework team