Skip to content

Commit 638bf1d

Browse files
authored
fix: ui inconsistency in landscape screens
1 parent 467e57b commit 638bf1d

4 files changed

Lines changed: 77 additions & 33 deletions

File tree

lib/view/logic_analyzer_screen.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,8 @@ class _LogicAnalyzerScreenState extends State<LogicAnalyzerScreen> {
283283
onOptionsPressed: _showOptionsMenu,
284284
onGuidePressed: _showInstrumentGuide,
285285
body: SafeArea(
286+
left: false,
287+
right: false,
286288
minimum: const EdgeInsets.only(right: 0, bottom: 0),
287289
child: Container(
288290
decoration: BoxDecoration(

lib/view/oscilloscope_screen.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,8 @@ class _OscilloscopeScreenState extends State<OscilloscopeScreen> {
344344
}
345345
: null,
346346
body: SafeArea(
347+
left: false,
348+
right: false,
347349
minimum: const EdgeInsets.only(right: 0, bottom: 0),
348350
child: LayoutBuilder(
349351
builder: (context, constraints) {

lib/view/robotic_arm_screen.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,8 @@ class _RoboticArmScreenState extends State<RoboticArmScreen> {
346346
body: Stack(
347347
children: [
348348
SafeArea(
349+
left: false,
350+
right: false,
349351
child: Padding(
350352
padding: const EdgeInsets.all(4.0),
351353
child: Column(

lib/view/widgets/common_scaffold_widget.dart

Lines changed: 71 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,13 @@ class CommonScaffold extends StatefulWidget {
4242
}
4343

4444
class _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

Comments
 (0)