Git Product home page Git Product logo

overlay_container's Introduction

”Premature optimization is the root of all evil, 97% of the time; Yet we should not pass opportunities in that critical 3%.” - David Knut

Here's My Introduction:

I’m (almost) a polyglot programmer who solves problems through code. I hate stereotyping and respect other people’s opinion in a workspace.
Even though I know it's not possible or feasible sometimes, but I'd still prefer writing clean code any day. And smart code isn't always clean 💡. I’m also always on a lookout for tools that improve my code and my workflow.

I really admire people who understand the value of time and respect flexibility among their colleagues. Remote work is one such example.

When I’m not pushing commits, I think about traveling the world and riding a bike with my wife.

Here's What I Do Professionally:

I'm part of geographically distributed team called Hubilo. We help bring people together in virtual events and try to recreate experiences that are akin to physical meetups.

I spend most of my time authoring and maintaining Hubilo's distributed backend.

Here's My Internet Footprint:

  • I write all my blog posts here.
  • I create or live stream videos and tutorials related to computer programming here.
  • I post stuff on X twitter icon here.
  • I'm available on LinkedIn too, that's here.

Here Are My Top Repositories:







Here are My LeetCode Solutions:

LeetCode Stats

I know! This is still a work in progress. ;)

Here is My StackOverflow Flair:

profile for Mustansir Zia at Stack Overflow, Q&A for professional and enthusiast programmers

Here's How to Support Me:

Buy Me A Pizza

visitors

overlay_container's People

Contributors

mustansirzia avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

overlay_container's Issues

How to show/hide with animation?

I need Transform scale (0-1 when show and 1-0 when hide, with duration) and animationcontroller but I can not achive this, can you help me?

Transparent background

Hello,

I am trying to create an overlay with content that isn't square.
However, the OverlayContainer seems to have a gray background.
Do you have any tips to make it transparent ?

Thanks in advance :)

ReConfirming Null Safety

Hi,
Its been almost a month so just checking if there is a tentative date for null safety release

Showing gray screen when app is in release mode

Hi ,

i am using overlay how showing over view for menu tab in flutter web , it works correctly in debug mode , below screenshot is taken when i run flutter in release mode in chrome . gray is the overlay where it should be transparent and able to see letter . but in release mode gray is applying

please let me know whats the issue .

image

TextField inside Overlay

Adding TextField and when focusing rebuilds the overlay and looses focus. Any idea how to fix this?

Null Safety

Hi, is null safety going to be supported soon?

A few questions

Hey,

Thank you for the widget, I always wanted to use Overlays. You've made it so easy that I had to give it a go :)

I ran into a couple of issues using overlay_container with my custom logic. I've managed to resolve them by changing a few things and I wanted to ask you if I may have missed something.

1: Why did you decide to put a Future.delayed in your _show method?
2: all WidgetsBinding.instance.addPostFrameCallback are ensured to be executed in the order in which they are called. Is there a reason why you're calling _overlayEntry.remove(); again in show?

I managed to resolve my issues by changing _show and _hide to:

  void _show() {
    if (!_opened) {
      WidgetsBinding.instance.addPostFrameCallback((_) async {
        _overlayEntry = _buildOverlayEntry();
        Overlay.of(context).insert(_overlayEntry);
        _opened = true;
      });
    }
  }

  void _hide() {
    if (_opened) {
      WidgetsBinding.instance.addPostFrameCallback((_) {
        _overlayEntry.remove();
        _opened = false;
      });
    }
  }

Am I missing something here?

When using in Scroll Widget

When using it in to a scroll widget. the overlay widget will not stick with the parent widget.
Once i set show to true, and scroll the screen, the Overlay Container will keep in the same position at i set it show to true.
It stick in the position that when i open the overlay.
Is there any ways to fix this issue?
https://imgur.com/MaXQduB
https://imgur.com/x8CyVdw

Null Safety here!

Copy and continue with the rest that is important

import 'package:flutter/material.dart';

class OverlayContainer extends StatefulWidget {
  /// The child to render inside the container.
  final Widget child;

  /// By default, the child will be rendered right below (if the parent is `Column`)
  /// the widget which is defined alongside the OverlayContainer.
  /// It would appear as though the Overlay is inside its parent
  /// but in reality it would be outside and above
  /// the original widget hierarchy.
  /// It's position can be altered and the overlay can
  /// be moved to any part of the screen by supplying a `position`
  /// argument.
  final OverlayContainerPosition position;

  /// Controlling whether the overlay is current showing or not.
  final bool show;

  /// Whether the overlay is wide as its enclosing parent.
  final bool asWideAsParent;

  /// `color` attribute for the `Material` component that wraps `child`.
  final Color materialColor;

  const OverlayContainer({
    Key? key,
    required this.show,
    required this.child,
    this.asWideAsParent = false,
    this.position = const OverlayContainerPosition(0.0, 0.0),
    this.materialColor = Colors.transparent,
  }) : super(key: key);

  @override
  _OverlayContainerState createState() => _OverlayContainerState();
}

class _OverlayContainerState extends State<OverlayContainer>
    with WidgetsBindingObserver {
  OverlayEntry? _overlayEntry;
  bool _opened = false;

  @override
  void initState() {
    super.initState();
    if (widget.show) {
      _show();
    }
    WidgetsBinding.instance!.addObserver(this);
  }

  @override
  void didChangeMetrics() {
    // We would want to re render the overlay if any metrics
    // ever change.
    if (widget.show) {
      _show();
    } else {
      _hide();
    }
  }

  @override
  void didChangeDependencies() {
    super.didChangeDependencies();
    // We would want to re render the overlay if any of the dependencies
    // ever change.
    if (widget.show) {
      _show();
    } else {
      _hide();
    }
  }

  @override
  void didUpdateWidget(OverlayContainer oldWidget) {
    super.didUpdateWidget(oldWidget);
    if (widget.show) {
      _show();
    } else {
      _hide();
    }
  }

  @override
  void dispose() {
    if (widget.show) {
      _hide();
    }
    WidgetsBinding.instance!.removeObserver(this);
    super.dispose();
  }

  void _show() {
    WidgetsBinding.instance!.addPostFrameCallback((_) async {
      await Future.delayed(const Duration(milliseconds: 280));
      if (_opened) {
        _overlayEntry!.remove();
      }
      _overlayEntry = _buildOverlayEntry();
      Overlay.of(context)!.insert(_overlayEntry!);
      _opened = true;
    });
  }

  void _hide() {
    if (_opened) {
      WidgetsBinding.instance!.addPostFrameCallback((_) {
        _overlayEntry!.remove();
        _opened = false;
      });
    }
  }

  @override
  Widget build(BuildContext context) {
    // Listen to changes in media query such as when a device orientation changes
    // or when the keyboard is toggled.
    MediaQuery.of(context);
    return Container();
  }

  OverlayEntry _buildOverlayEntry() {
    RenderBox renderBox = context.findRenderObject() as RenderBox;
    final size = renderBox.size;
    final offset = renderBox.localToGlobal(Offset.zero);
    return OverlayEntry(
      builder: (context) {
        return Positioned(
          left: offset.dx + widget.position.left,
          top: offset.dy - widget.position.bottom,
          width: widget.asWideAsParent ? size.width : null,
          child: Material(
            child: widget.child,
            color: widget.materialColor,
          ),
        );
      },
    );
  }
}

/// Class to help position the overlay on the screen.
/// By default it will be rendered right below (if the parent is `Column`)
/// the widget which is alongside the OverlayContainer.
/// The Overlay can however be moved around by giving a left value
/// and a bottom value just like in the case of a `Positioned` widget.
/// The default values for `left` and `bottom` are 0 and 0 respectively.
class OverlayContainerPosition {
  final double left;
  final double bottom;

  const OverlayContainerPosition(this.left, this.bottom);
}


Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.