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
This commit is contained in:
zjs81 committed 2026-10-07 21:06:41 -07:00
1 parent 551bf128c6
commit 1d64399d42
3 files changed
+68 -54

No files matched your search

+8 -4
View File
@@ -49,8 +49,9 @@ void main() async {
debugPrint = (String? message, {int? wrapWidth}) {}; debugPrint = (String? message, {int? wrapWidth}) {};
} }
// Android 15+ forces edge-to-edge for apps targeting SDK 35; opt older // Android 15+ forces edge-to-edge for apps targeting SDK 35; opt Android
// versions in too so every device lays out the same way under the bars. // 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) { if (PlatformInfo.isAndroid) {
await SystemChrome.setEnabledSystemUIMode(SystemUiMode.edgeToEdge); await SystemChrome.setEnabledSystemUIMode(SystemUiMode.edgeToEdge);
} }
@@ -471,7 +472,10 @@ class _MeshCoreAppState extends State<MeshCoreApp> with WidgetsBindingObserver {
final iconBrightness = isDark ? Brightness.light : Brightness.dark; final iconBrightness = isDark ? Brightness.light : Brightness.dark;
// The app draws edge-to-edge, so both system bars stay transparent and // 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( return SystemUiOverlayStyle(
statusBarColor: Colors.transparent, statusBarColor: Colors.transparent,
statusBarIconBrightness: iconBrightness, statusBarIconBrightness: iconBrightness,
@@ -479,7 +483,7 @@ class _MeshCoreAppState extends State<MeshCoreApp> with WidgetsBindingObserver {
systemNavigationBarColor: Colors.transparent, systemNavigationBarColor: Colors.transparent,
systemNavigationBarIconBrightness: iconBrightness, systemNavigationBarIconBrightness: iconBrightness,
systemNavigationBarDividerColor: Colors.transparent, systemNavigationBarDividerColor: Colors.transparent,
systemNavigationBarContrastEnforced: false, systemNavigationBarContrastEnforced: true,
); );
} }
+26 -20
View File
@@ -1,4 +1,5 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:mobile_scanner/mobile_scanner.dart'; import 'package:mobile_scanner/mobile_scanner.dart';
/// A reusable QR code scanner widget that can be embedded anywhere. /// A reusable QR code scanner widget that can be embedded anywhere.
@@ -150,28 +151,33 @@ class _QrScannerWidgetState extends State<QrScannerWidget>
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Stack( // The camera preview is dark, so keep the system bar icons light, and lift
children: [ // the controls above the navigation bar the app draws behind.
// Scanner view return AnnotatedRegion<SystemUiOverlayStyle>(
MobileScanner( value: SystemUiOverlayStyle.light,
controller: _controller, child: Stack(
onDetect: _handleDetection, children: [
errorBuilder: (context, error) { // Scanner view
return _buildErrorWidget(context, error); MobileScanner(
}, controller: _controller,
), onDetect: _handleDetection,
errorBuilder: (context, error) {
return _buildErrorWidget(context, error);
},
),
// Overlay // Overlay
widget.overlay ?? _buildDefaultOverlay(context), widget.overlay ?? _buildDefaultOverlay(context),
// Control buttons // Control buttons
Positioned( Positioned(
bottom: 16, bottom: 16 + MediaQuery.viewPaddingOf(context).bottom,
left: 0, left: 0,
right: 0, right: 0,
child: _buildControls(context), child: _buildControls(context),
), ),
], ],
),
); );
} }
+34 -30
View File
@@ -29,9 +29,8 @@
/// with whoever implements export, not here. /// with whoever implements export, not here.
library; library;
import 'dart:typed_data';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
import '../services/received_image_store.dart'; import '../services/received_image_store.dart';
@@ -618,36 +617,41 @@ class _ReceivedImageViewer extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( // Light system bar icons over the black viewer, whatever the app theme.
backgroundColor: Colors.black, return AnnotatedRegion<SystemUiOverlayStyle>(
appBar: AppBar( value: SystemUiOverlayStyle.light,
child: Scaffold(
backgroundColor: Colors.black, backgroundColor: Colors.black,
foregroundColor: Colors.white, appBar: AppBar(
), backgroundColor: Colors.black,
body: Center( foregroundColor: Colors.white,
child: Column( systemOverlayStyle: SystemUiOverlayStyle.light,
mainAxisSize: MainAxisSize.min, ),
children: [ body: Center(
Flexible( child: Column(
child: Stack( mainAxisSize: MainAxisSize.min,
children: [ children: [
InteractiveViewer(child: Image.memory(png)), Flexible(
if (synthesized) child: Stack(
const Positioned( children: [
left: 0, InteractiveViewer(child: Image.memory(png)),
right: 0, if (synthesized)
bottom: 0, const Positioned(
child: _SyntheticBanner(), left: 0,
), right: 0,
], bottom: 0,
child: _SyntheticBanner(),
),
],
),
), ),
), if (synthesized)
if (synthesized) Padding(
Padding( padding: const EdgeInsets.symmetric(horizontal: 16),
padding: const EdgeInsets.symmetric(horizontal: 16), child: _SyntheticCaption(bytes: bytes, onDark: true),
child: _SyntheticCaption(bytes: bytes, onDark: true), ),
), ],
], ),
), ),
), ),
); );