safe_area_size 0.1.1
safe_area_size: ^0.1.1 copied to clipboard

A plugin to get the SafeArea size using platform channels, making it easy to design around SafeArea's limitations.

Safe Area Size #

A plugin to get the SafeArea size using platform channels, making it easy to design around SafeArea's limitations.

Why? #

The way SafeArea is designed, if you insert it into your root structure, you no longer have access to changes of MediaQuery Insets or Padding.

So I've made this plugin to work around this limitation, allowing access to these values anyway.

How? #

Make it a dependency inside your application:

dependencies:
  safe_area_size: 0.1.0

Import it:

import 'package:safe_area_size/safe_area_size.dart';

Make one async method inside your widget that makes use of the included platform channel calls:

Future<void> initPlatformState() async {
    int navigationBarHeight;
    int statusBarHeigth;
    
    try {
      statusBarHeigth = await SafeAreaSize.statusBarSize;
      navigationBarHeight = await SafeAreaSize.navigationBarSize;
    } on PlatformException {
      statusBarHeigth = 0;
      navigationBarHeight = 0;
    }
    
    if (!mounted) return;

    setState(() {
      _statusBarHeight = statusBarHeigth;
      _navigationBarHeight = navigationBarHeight;
    });
  }

You're done!

TODO #

  • [x] Android version
  • [ ] iOS version
1
likes
90
pub points
35%
popularity

Publisher

Unknown

A plugin to get the SafeArea size using platform channels, making it easy to design around SafeArea's limitations.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (LICENSE)

Dependencies

flutter

More

Packages that depend on safe_area_size