@@ -42,6 +42,13 @@ class CommonScaffold extends StatefulWidget {
4242}
4343
4444class _CommonScaffoldState extends State <CommonScaffold > {
45+ void _setPortraitOrientation () {
46+ SystemChrome .setPreferredOrientations ([
47+ DeviceOrientation .portraitUp,
48+ DeviceOrientation .portraitDown,
49+ ]);
50+ }
51+
4552 List <Widget > _buildResponsiveActions (double width) {
4653 final bool isVerySmall = width < 260 ;
4754 final bool isSmall = width < 320 ;
@@ -128,43 +135,74 @@ class _CommonScaffoldState extends State<CommonScaffold> {
128135 @override
129136 Widget build (BuildContext context) {
130137 final double width = MediaQuery .of (context).size.width;
138+ final bool isLandscape =
139+ MediaQuery .of (context).orientation == Orientation .landscape;
131140
132- return Scaffold (
133- backgroundColor: scaffoldBackgroundColor,
134- resizeToAvoidBottomInset: true ,
135- appBar: AppBar (
136- systemOverlayStyle: SystemUiOverlayStyle (
137- statusBarColor: appBarColor,
138- statusBarIconBrightness: Brightness .light,
139- statusBarBrightness: Brightness .dark,
140- ),
141- leading: Builder (
142- builder: (context) {
143- return IconButton (
144- onPressed: () {
145- Navigator .maybePop (context);
146- },
147- icon: Icon (
148- Icons .arrow_back,
149- color: appBarContentColor,
150- ),
151- );
152- },
153- ),
154- backgroundColor: primaryRed,
155- title: Text (
156- widget.title,
157- key: widget.scaffoldKey,
158- maxLines: 1 ,
159- overflow: TextOverflow .ellipsis,
160- style: TextStyle (
161- color: appBarContentColor,
162- fontSize: 15 ,
141+ return PopScope (
142+ canPop: false ,
143+ onPopInvokedWithResult: (bool didPop, Object ? result) {
144+ if (didPop) return ;
145+
146+ _setPortraitOrientation ();
147+ SystemChrome .setEnabledSystemUIMode (SystemUiMode .edgeToEdge);
148+
149+ if (context.mounted) {
150+ Navigator .of (context).pop (result);
151+ }
152+ },
153+ child: MediaQuery .removePadding (
154+ context: context,
155+ removeLeft: isLandscape,
156+ removeRight: isLandscape,
157+ child: Scaffold (
158+ backgroundColor: scaffoldBackgroundColor,
159+ resizeToAvoidBottomInset: true ,
160+ appBar: AppBar (
161+ automaticallyImplyLeading: false ,
162+ titleSpacing: 4 ,
163+ systemOverlayStyle: SystemUiOverlayStyle (
164+ statusBarColor: appBarColor,
165+ statusBarIconBrightness: Brightness .light,
166+ statusBarBrightness: Brightness .dark,
167+ ),
168+ backgroundColor: primaryRed,
169+ title: Row (
170+ children: [
171+ IconButton (
172+ padding: EdgeInsets .zero,
173+ constraints:
174+ const BoxConstraints (minWidth: 32 , minHeight: 32 ),
175+ onPressed: () {
176+ _setPortraitOrientation ();
177+ SystemChrome .setEnabledSystemUIMode (
178+ SystemUiMode .edgeToEdge);
179+ Navigator .maybePop (context);
180+ },
181+ icon: Icon (
182+ Icons .arrow_back,
183+ color: appBarContentColor,
184+ ),
185+ ),
186+ const SizedBox (width: 8 ),
187+ Expanded (
188+ child: Text (
189+ widget.title,
190+ key: widget.scaffoldKey,
191+ maxLines: 1 ,
192+ overflow: TextOverflow .ellipsis,
193+ style: TextStyle (
194+ color: appBarContentColor,
195+ fontSize: 15 ,
196+ ),
197+ ),
198+ ),
199+ ],
200+ ),
201+ actions: _buildResponsiveActions (width),
163202 ),
203+ body: widget.body,
164204 ),
165- actions: _buildResponsiveActions (width),
166205 ),
167- body: widget.body,
168206 );
169207 }
170208}
0 commit comments