Dialog creation best practices #57
-
Is this an acceptable way to prop drilling abstract class CreateDialog extends RearchConsumer {
final String title;
const CreateDialog({
super.key,
required this.title,
});
@override
Widget build(BuildContext context, WidgetHandle use) => Column(children: [
// Title
Text(title),
// Body
buildBody(context, use),
// Create button
ElevatedButton.icon(
onPressed: () => tryCreate(use),
icon: const Icon(Icons.create),
label: const Text('Create')),
]);
Widget buildBody(BuildContext context, WidgetHandle use);
Future<void> tryCreate(WidgetHandle use);
}
class UserCreateDialog extends CreateDialog {
const UserCreateDialog({
super.key,
required super.title,
});
@override
Widget buildBody(BuildContext context, WidgetHandle use) => const Column(
children: [
Text('Field 1'),
Text('Field 2'),
Text('Field n'),
],
);
@override
Future<void> tryCreate(WidgetHandle use) {}
} |
Beta Was this translation helpful? Give feedback.
Answered by
GregoryConrad
Jan 1, 2024
Replies: 1 comment 5 replies
-
Yea, definitely don't pass an entire @rearchWidget
Widget createDialog({
// These two will be parameters to your CreateDialog constructor without the @rearchWidget macro
required Widget Function(BuildContext, WidgetHandle) bodyBuilder,
required Future<void> Function() create,
}) {
// I might also suggest use.mutation here to watch the create() function so you can give
// users an update on how the creation is going
return Column(children: [
// Title
Text(title),
// Body
RearchBuilder(builder: bodyBuilder),
ElevatedButton.icon(
onPressed: create,
icon: const Icon(Icons.create),
label: const Text('Create')),
],
);
} For reference, here's the previous discussion we had about prop drilling and scoping state: #50 |
Beta Was this translation helpful? Give feedback.
5 replies
Answer selected by
GregoryConrad
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Yea, definitely don't pass an entire
WidgetHandle
around. If you do pass something, I'd make it just aCapsuleReader
. Even then, I wouldn't use inheritance to solve this issue like you are. I'd do something like this: