Let’s say all screens need same size horizontal padding like the picture above so I made a base layout widget that every screen takes it.
class BaseLayout extends StatelessWidget {
final Widget child;
const BaseLayout({super.key, required this.child});
@override
Widget build(BuildContext context) {
return Scaffold(
body: Padding(
padding: const EdgeInsets.symmetric(horizontal: 15),
child: SafeArea(child: child)),
);
}
}
class HomeScreen extends StatelessWidget {
const HomeScreen({super.key});
@override
Widget build(BuildContext context) {
return BaseLayout(
child: Column(
children: [
Container( // how to make only this one take whole width of the screen unlike others?
decoration: const BoxDecoration(color: Color(0xffFFFF7E)),
),
// the below Rows need to take the padding and it does due to the BaseLayout
Row(),
Row()
],
),
);
}
}
However, a widget like the yellow box has to take whole width size of the screen(no padding needed).
Is it possible? or I should not use the layout and give it to needed ones.
Thanks in advance.
2
Answers
You can try to use a negative margin.
No, it’s an exception here.
That page doesn’t share the common visual characteristics like padding with other pages.
So, it should has a different design from other pages (Reusability can’t be applied here).
But if it’s insistent need, it can be handled by just a flag variable.
Look at the following widget :
And that’s how you call in each case:
Hope it helps.