From 1d64399d420883155444629bf5517c143b33dac0 Mon Sep 17 00:00:00 2001 From: zjs81 Date: Wed, 7 Oct 2026 21:06:41 -0700 Subject: [PATCH] Keep system bar content usable under edge-to-edge - Lift the QR scanner's torch and camera controls above the navigation bar instead of 16 px from the screen edge - Use light system bar icons on the black QR camera and received-image viewer, and keep Android's contrast scrim behind three-button navigation for any other dark route - Note that Flutter only applies edge-to-edge from Android 10 --- lib/main.dart | 12 +++-- lib/widgets/qr_scanner_widget.dart | 46 ++++++++++-------- lib/widgets/received_image_message.dart | 64 +++++++++++++------------ 3 files changed, 68 insertions(+), 54 deletions(-) diff --git a/lib/main.dart b/lib/main.dart index 2014d5e3..fa49e65f 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -49,8 +49,9 @@ void main() async { debugPrint = (String? message, {int? wrapWidth}) {}; } - // Android 15+ forces edge-to-edge for apps targeting SDK 35; opt older - // versions in too so every device lays out the same way under the bars. + // Android 15+ forces edge-to-edge for apps targeting SDK 35; opt Android + // 10-14 in too so they lay out the same way under the bars. Flutter ignores + // this mode before Android 10, where the old layout remains. if (PlatformInfo.isAndroid) { await SystemChrome.setEnabledSystemUIMode(SystemUiMode.edgeToEdge); } @@ -471,7 +472,10 @@ class _MeshCoreAppState extends State with WidgetsBindingObserver { final iconBrightness = isDark ? Brightness.light : Brightness.dark; // The app draws edge-to-edge, so both system bars stay transparent and - // only their icon brightness follows the resolved Flutter theme. + // their icon brightness follows the resolved Flutter theme. Contrast + // enforcement keeps a scrim behind three-button navigation in case a + // route paints a dark surface under light-theme icons; dark full-screen + // routes also set light icons themselves. return SystemUiOverlayStyle( statusBarColor: Colors.transparent, statusBarIconBrightness: iconBrightness, @@ -479,7 +483,7 @@ class _MeshCoreAppState extends State with WidgetsBindingObserver { systemNavigationBarColor: Colors.transparent, systemNavigationBarIconBrightness: iconBrightness, systemNavigationBarDividerColor: Colors.transparent, - systemNavigationBarContrastEnforced: false, + systemNavigationBarContrastEnforced: true, ); } diff --git a/lib/widgets/qr_scanner_widget.dart b/lib/widgets/qr_scanner_widget.dart index 5b6cf5e3..e54b379e 100644 --- a/lib/widgets/qr_scanner_widget.dart +++ b/lib/widgets/qr_scanner_widget.dart @@ -1,4 +1,5 @@ import 'package:flutter/material.dart'; +import 'package:flutter/services.dart'; import 'package:mobile_scanner/mobile_scanner.dart'; /// A reusable QR code scanner widget that can be embedded anywhere. @@ -150,28 +151,33 @@ class _QrScannerWidgetState extends State @override Widget build(BuildContext context) { - return Stack( - children: [ - // Scanner view - MobileScanner( - controller: _controller, - onDetect: _handleDetection, - errorBuilder: (context, error) { - return _buildErrorWidget(context, error); - }, - ), + // The camera preview is dark, so keep the system bar icons light, and lift + // the controls above the navigation bar the app draws behind. + return AnnotatedRegion( + value: SystemUiOverlayStyle.light, + child: Stack( + children: [ + // Scanner view + MobileScanner( + controller: _controller, + onDetect: _handleDetection, + errorBuilder: (context, error) { + return _buildErrorWidget(context, error); + }, + ), - // Overlay - widget.overlay ?? _buildDefaultOverlay(context), + // Overlay + widget.overlay ?? _buildDefaultOverlay(context), - // Control buttons - Positioned( - bottom: 16, - left: 0, - right: 0, - child: _buildControls(context), - ), - ], + // Control buttons + Positioned( + bottom: 16 + MediaQuery.viewPaddingOf(context).bottom, + left: 0, + right: 0, + child: _buildControls(context), + ), + ], + ), ); } diff --git a/lib/widgets/received_image_message.dart b/lib/widgets/received_image_message.dart index e3f56350..253f5164 100644 --- a/lib/widgets/received_image_message.dart +++ b/lib/widgets/received_image_message.dart @@ -29,9 +29,8 @@ /// with whoever implements export, not here. library; -import 'dart:typed_data'; - import 'package:flutter/material.dart'; +import 'package:flutter/services.dart'; import 'package:provider/provider.dart'; import '../services/received_image_store.dart'; @@ -618,36 +617,41 @@ class _ReceivedImageViewer extends StatelessWidget { @override Widget build(BuildContext context) { - return Scaffold( - backgroundColor: Colors.black, - appBar: AppBar( + // Light system bar icons over the black viewer, whatever the app theme. + return AnnotatedRegion( + value: SystemUiOverlayStyle.light, + child: Scaffold( backgroundColor: Colors.black, - foregroundColor: Colors.white, - ), - body: Center( - child: Column( - mainAxisSize: MainAxisSize.min, - children: [ - Flexible( - child: Stack( - children: [ - InteractiveViewer(child: Image.memory(png)), - if (synthesized) - const Positioned( - left: 0, - right: 0, - bottom: 0, - child: _SyntheticBanner(), - ), - ], + appBar: AppBar( + backgroundColor: Colors.black, + foregroundColor: Colors.white, + systemOverlayStyle: SystemUiOverlayStyle.light, + ), + body: Center( + child: Column( + mainAxisSize: MainAxisSize.min, + children: [ + Flexible( + child: Stack( + children: [ + InteractiveViewer(child: Image.memory(png)), + if (synthesized) + const Positioned( + left: 0, + right: 0, + bottom: 0, + child: _SyntheticBanner(), + ), + ], + ), ), - ), - if (synthesized) - Padding( - padding: const EdgeInsets.symmetric(horizontal: 16), - child: _SyntheticCaption(bytes: bytes, onDark: true), - ), - ], + if (synthesized) + Padding( + padding: const EdgeInsets.symmetric(horizontal: 16), + child: _SyntheticCaption(bytes: bytes, onDark: true), + ), + ], + ), ), ), );