I’m using OrientationBuilder in my Flutter app to change the UI based on the orientation. However, when I switch back to portrait mode, the UI of the landscape mode is still showing. Here is my code:
OrientationBuilder(
builder: (context, orientation) {
bool isLandscape = orientation == Orientation.landscape;
return Padding(
padding: isLandscape
? EdgeInsets.only(
left: ResponsiveFunctions.responsiveWidth(10),
top: ResponsiveFunctions.responsiveHeight(52),
right: ResponsiveFunctions.responsiveWidth(10),
bottom: ResponsiveFunctions.responsiveHeight(3))
: EdgeInsets.only(
left: ResponsiveFunctions.responsiveWidth(16),
top: ResponsiveFunctions.responsiveHeight(42),
right: ResponsiveFunctions.responsiveWidth(16),
bottom: ResponsiveFunctions.responsiveHeight(10)),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Column(
// Additional widgets here
),
],
),
],
),
);
},
);
I’ve used OrientationBuilder to change the UI according to the landscape mode and portrait, but when I switch back to the normal screen, the UI of the landscape mode is still showing. How can I ensure that the UI updates correctly when switching landscape to portrait mode and portrait to landscape?