Skip to main content

pwa_safe_area 0.1.0 copy "pwa_safe_area: ^0.1.0" to clipboard
pwa_safe_area: ^0.1.0 copied to clipboard

Flutter web fix for iOS home-screen PWAs where env(safe-area-inset-*) reads zero: re-asserts viewport-fit=cover and merges real CSS safe-area insets into MediaQuery.

example/lib/main.dart

import 'package:flutter/widgets.dart';
import 'package:pwa_safe_area/pwa_safe_area.dart';

void main() {
  WidgetsFlutterBinding.ensureInitialized();
  setupViewportFit();
  runApp(const ExampleApp());
}

/// Displays CSS insets next to the padding Flutter widgets receive.
class ExampleApp extends StatelessWidget {
  /// Creates the example app.
  const ExampleApp({super.key});

  @override
  Widget build(BuildContext context) {
    return WidgetsApp(
      title: 'pwa_safe_area example',
      color: const Color(0xffdf4a20),
      builder: (context, _) => const PwaSafeArea(child: _HomePage()),
    );
  }
}

class _HomePage extends StatelessWidget {
  const _HomePage();

  @override
  Widget build(BuildContext context) {
    final padding = MediaQuery.paddingOf(context);
    return ColoredBox(
      // The orange band marks the area that SafeArea leaves clear.
      color: const Color(0xffdf4a20),
      child: SafeArea(
        child: ColoredBox(
          color: const Color(0xfffaf8f5),
          child: DefaultTextStyle(
            style: const TextStyle(color: Color(0xff262421), fontSize: 16),
            child: Center(
              child: Column(
                mainAxisSize: MainAxisSize.min,
                children: [
                  const Text('pwa_safe_area', style: TextStyle(fontSize: 24)),
                  const SizedBox(height: 16),
                  _InsetRow(label: 'MediaQuery top', value: padding.top),
                  _InsetRow(label: 'MediaQuery bottom', value: padding.bottom),
                  const SizedBox(height: 16),
                  StreamBuilder<EdgeInsets>(
                    stream: safeAreaInsetsStream,
                    initialData: safeAreaInsets,
                    builder: (context, snapshot) {
                      final css = snapshot.data ?? EdgeInsets.zero;
                      return Column(
                        mainAxisSize: MainAxisSize.min,
                        children: [
                          _InsetRow(label: 'CSS env top', value: css.top),
                          _InsetRow(label: 'CSS env bottom', value: css.bottom),
                        ],
                      );
                    },
                  ),
                ],
              ),
            ),
          ),
        ),
      ),
    );
  }
}

class _InsetRow extends StatelessWidget {
  const _InsetRow({required this.label, required this.value});

  final String label;
  final double value;

  @override
  Widget build(BuildContext context) {
    return Padding(
      padding: const EdgeInsets.symmetric(vertical: 2),
      child: Text('$label: ${value.toStringAsFixed(1)}px'),
    );
  }
}
0
likes
160
points
30
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

Flutter web fix for iOS home-screen PWAs where env(safe-area-inset-*) reads zero: re-asserts viewport-fit=cover and merges real CSS safe-area insets into MediaQuery.

Repository (GitHub)
View/report issues

Topics

#pwa #safe-area #ios #web

License

MIT (license)

Dependencies

flutter, web

More

Packages that depend on pwa_safe_area