How can i check that device has notch without using SafeArea in flutter?

Viewed 1123

I'm designing a video call screen where i have to manage selfViewContainer between hole screen.

enter image description here

On this screen, i already managed most of the parts for horizontal alignments but for vertical it's not working properly for me in devices that have a notch.

I want to make minimum padding of 50 from the top while dragging

Here is a code for orange container which is draggable

Widget _selfView() {

    return Positioned(
      top: _selfViewTop,
      left: _selfViewLeft,
      child: Draggable(
        feedback: _draggableView(),
        childWhenDragging: Container(),
        child: _draggableView(),
        onDragEnd: (dragDetail) {
          var screenWidth = AspectSize.getScreenWidth(context: context);
          var screenHeight = AspectSize.getScreenHeight(context: context);

          _selfViewLeft = dragDetail.offset.dx;
          _selfViewTop = dragDetail.offset.dy;

          if (_selfViewLeft < (screenWidth / 2)) {
            _selfViewLeft = 16.0;
          } else if (_selfViewLeft > (screenWidth / 2)) {
            _selfViewLeft = (screenWidth) - (_selfViewWidth + 16);
          }

          if (_selfViewLeft < 1.0) {
            _selfViewLeft = 16.0;
          } else if ((_selfViewLeft + _selfViewWidth) > screenWidth) {
            _selfViewLeft = (screenWidth) - (_selfViewWidth + 16);
          }
          if (_selfViewTop < 1.0) {
            _selfViewTop = 50;
          } else if ((_selfViewTop + _selfViewHeight) > screenHeight) {
            _selfViewTop = (screenHeight) - (_selfViewWidth + 50);
          }

          setState(() {});
        },
      ),
    );
  }

For this UI i used Stack widgets for managing containers the orange container is used to show the callers screen and the blue container will show pictures of another person.

Please give me some solution for this.

Thank you.

1 Answers

You can use MediaQuery.of(context).viewPadding and check whether the padding is greater than zero ,then you will need a safe area as there is a notch .

And the best way to handle notch behaviour is to use the flutter_device_type package.

the following code in the above package can determine the notch:

if( Device.get().hasNotch ){
//Do some notch business
 }

Thank You.

Related