You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When creating a screen, sometimes we need to add a lot of top-level configuration widgets:
// screen.dart@overrideWidgetbuild(BuildContext context) {
// 1returnFocusScopeDismissible(
// 2
child:BlocProvider<Bloc>(
create: (context) =>injector(),
// Aand the actual UI comes at this point...// 3
child:Scaffold(
// Aand the core part of it is here
body:Column(
children:const [],
),
),
),
);
}
At least 3 top-level things just to make the screen work normally. And it can be more.
The solution
The body of the screen could be moved to a separate widget:
// screen.dart@overrideWidgetbuild(BuildContext context) {
returnFocusScopeDismissible(
child:BlocProvider<Bloc>(
create: (context) =>injector(),
child:Scaffold(
body:constScreenBody(),
),
),
);
}
...
classScreenBodyextendsStatelessWidget {
constScreenBody({super.key});
@overrideWidgetbuild(BuildContext context) {
// The bloc's data could still be accessible via selectors and bloc buildersfinal stateData = context.select((Bloc bloc) => bloc.state.data);
returnconstText("I'm the actual UI of the screen!");
}
}
Pros
Makes you to follow smaller widgets approach;
Reduces the waterfall in the body of a screen.
Cons
So far I don't see it. We followed this approach on two projects and it was quite good.
Additional instruments that may help us
We can write a simple script that will generate the files on command from our IDE. I have already written a very similar script for a VSCode extension for my package, it is here. It can be a create_feature, not a module.
The text was updated successfully, but these errors were encountered:
The problem
When creating a screen, sometimes we need to add a lot of top-level configuration widgets:
At least 3 top-level things just to make the screen work normally. And it can be more.
The solution
The body of the screen could be moved to a separate widget:
Pros
Cons
Additional instruments that may help us
We can write a simple script that will generate the files on command from our IDE. I have already written a very similar script for a VSCode extension for my package, it is here. It can be a
create_feature
, not a module.The text was updated successfully, but these errors were encountered: