Download this source code for
5 USD


Download this source code for
5 USD


Download this source code for
5 USD


Download this source code for
5 USD

peek_and_pop

peek & pop implementation for flutter based on the ios functionality of the same name.

finally, the v1.0.0 release! more fluent, more optimised and more beautiful than ever. very customisable and very easy to use.

it is highly recommended to read the documentation and run the example project on a real device to fully understand and inspect the full range of capabilities.

as a fan of the ios peek & pop functionality, i decided to implement it for flutter as well.

the package has been tested on ios but not yet on android as i don’t have access to an android device with force press capabilities. help about
this would be appreciated.

for devices that don’t support force press, the package comes with an adaptation to long press however the long press version of this package is
still under development and is not yet fully tested so consider it as a developers preview.

(the long press version is temporarily removed. it will be added back soon.)

the power move of this package is what i like to call “gesture recognition rerouting”. normally, when a new widget with gesturedetector or similar
is pushed over an initial widget used for detecting force press or when navigator is used to pop a new page, the user has to restart the gesture
for flutter to resume updating it. this package fixes that problem as explained in the documentation:

//this function is called by the instantiated [peekandpopchild] once it is ready to be included in the peek & pop process. perhaps the most
//essential functionality of this package also takes places in this function: the gesture recognition is rerouted from the [peekandpopdetector]
//to the instantiated [peekandpopchild]. this is important for avoiding the necessity of having the user stop and restart their force press.
//instead, the [peekandpopcontroller] does this automatically so that the existing force press can continue to update even when if
//[peekandpopdetector] is blocked by the view which is often the case especially when using platformviews.

installation

it is easy. don’t worry.

if you do not wish to use platformviews you can skip the installation instructions.

old installation instructions are removed. if you wish (for some reason) to use a version older than v0.1.9, see the readme of that version for
the relevant installation instructions.

for properly displaying platformviews, this package requires the latest flutter master
branch. maybe it will work with some other version too but tests made with the webview_flutter
seem to only properly display with the latest flutter master branch which has improved the platformviews that
allow better functionalities such as proper scaling and proper clipping.

if you do not wish to use platformviews, you can skip this step.

to use latest flutter master branch, run the following command.

note: don’t forget to add io.flutter.embedded_views_previewyes to your info.plist. see
webview_flutter for more info.

$ git download -b master https://github.com/flutter/flutter.git
$ flutter channel master
$ flutter upgrade
$ flutter doctor
$ ./flutter/bin/flutter --version

how-to-use

also easy.

first of all, as explained in the documentation:

//i noticed that a fullscreen blur effect via the [backdropfilter] widget is not good to use while running the animations required for the peek &
//pop process as it causes a noticeable drop in the framerate- especially for devices with high resolutions. during a mostly static view, the
//drop is acceptable. however, once the animations start running, this drop causes a visual disturbance. to prevent this, a new optimised blur
//effect algorithm is implemented. now, the [backdropfilter] widget is only used until the animations are about to start. at that moment, it is
//replaced by a static image. therefore, to capture this image, your root cupertinoapp/materialapp must be wrapped in a [repaintboundary] widget
//which uses the [background] key. as a result, the peek & pop process is now up to 4x more fluent.

tl;dr: wrap your root cupertinoapp/materialapp in a repaintboundary widget and use the background globalkey from “misc.dart”.

this is required for the new optimised blur effect algorithm:

import 'package:peek_and_pop/misc.dart' as peekandpopmisc;

class myapp extends statelesswidget {
  @override
  widget build(buildcontext context) {
    return repaintboundary(
      key: peekandpopmisc.background,
      child: materialapp(
        title: 'peek & pop demo',
        home: myhomepage(title: 'peek & pop demo')
      )
    );
  }
}

if you wish to use the “scaleup” or the “scale down” features, wrap the widgets you wish to scale down or scale up during the peek & pop process with
the scaleupwrapper and scaledownwrapper functions from “misc.dart”:

@override
widget build(buildcontext context) {
return scaffold(
  appbar: appbar(title: text(widget.title)),
  body: peekandpopmisc.scaledownwrapper(
        ...,
        0.04,
        ),
    );    
}

then, create a peekandpopcontroller such as:

peekandpopcontroller(
  uichild(),            //widget uichild
  false,                //bool uichildusecache
  peekandpopbuilder,    //peekandpopbuilder peekandpopbuilder
  false,                //bool peekandpopbuilderusecache
 {key key,
  quickactionsbuilder           : quickactionsbuilder,
  sigma                         : 10,
  backdropcolor                 : colors.black,
  alpha                         : 126,
  overlaybuilder                : overlaybuilder,
  useoverlap                    : true,
  customoverlaprect,
  usealignment,                 : false,
  useindicator                  : true,
  indicatorscaleupcoefficient   : 0.01,
  willpeekandpopcomplete        : _willpeekandpopcomplete,
  willpushpeekandpop            : _willpushpeekandpop,
  willupdatepeekandpop          : _willupdatepeekandpop,
  willcancelpeekandpop          : _willcancelpeekandpop,
  willfinishpeekandpop          : _willfinishpeekandpop,
  willclosepeekandpop           : _willclosepeekandpop,
  onpeekandpopcomplete          : _onpeekandpopcomplete,
  onpushpeekandpop              : _onpushpeekandpop,
  onupdatepeekandpop            : _onupdatepeekandpop,
  oncancelpeekandpop            : _oncancelpeekandpop,
  onfinishpeekandpop            : _onfinishpeekandpop,
  onclosepeekandpop             : _onfinishpeekandpop,
  onpressstart                  : _onpressstart,
  onpressupdate                 : _onpressupdate,
  onpressend                    : _onpressend,
  treshold                      : 0.5,
  startpressure                 : 0.125,
  peakpressure                  : 1.0,
  peekscale                     : 0.5,
  peekcoefficient               : 0.05,
  poptransition})
  
widget uichild() {}

widget peekandpopbuilder(buildcontext context, peekandpopcontrollerstate _peekandpopcontroller);

quickactionsdata quickactionsbuilder(peekandpopcontrollerstate _peekandpopcontroller);

widget overlaybuiler();

bool _willpeekandpopcomplete(peekandpopcontrollerstate _peekandpopcontroller);
bool _willpushpeekandpop(peekandpopcontrollerstate _peekandpopcontroller);
bool _willupdatepeekandpop(peekandpopcontrollerstate _peekandpopcontroller);
bool _willcancelpeekandpop(peekandpopcontrollerstate _peekandpopcontroller);
bool _willfinishpeekandpop(peekandpopcontrollerstate _peekandpopcontroller);
bool _willclosepeekandpop(peekandpopcontrollerstate _peekandpopcontroller);

void _onpeekandpopcomplete(peekandpopcontrollerstate _peekandpopcontroller);
void _onpushpeekandpop(peekandpopcontrollerstate _peekandpopcontroller);
void _onupdatepeekandpop(peekandpopcontrollerstate _peekandpopcontroller);
void _oncancelpeekandpop(peekandpopcontrollerstate _peekandpopcontroller);
void _onfinishpeekandpop(peekandpopcontrollerstate _peekandpopcontroller);
void _onclosepeekandpop(peekandpopcontrollerstate _peekandpopcontroller);

void _onpressstart(dynamic dragdetails);
void _onpressupdate(dynamic dragdetails);
void _onpressend(dynamic dragdetails);
 

further explanations:

for a complete set of descriptions for all parameters and methods, see the documentation.

  • set [uichildusecache] to true if your [uichild] doesn’t change during the peek & pop process.
  • set [peekandpopbuilderusecache] to true if your [peekandpopbuilder] doesn’t change during the peek & pop process.
  • [overlaybuilder] is an optional second view to be displayed during the peek & pop process. this entire widget is built after everything else.
  • for all [peekandpopprocessnotifier] callbacks such as [willpeekandpopcomplete], you can return false to prevent the default action.
  • all [peekandpopprocessnotifier] and [peekandpopprocesscallback] callbacks will return a reference to the created [peekandpopcontroller] state.
    you can save this instance for further actions.
  • [pagetransition] is the transition to be used when the view is opened directly or when the view is closed. a default [slidetransition] is provided.
  • use [peekandpopcontrollerstate]’s [void closepeekandpop()] method to close the peek & pop process. do not call [navigator.of(context).pop()]
    directly.
  • use [peekandpopcontrollerstate]’s [stage] variable to get enumeration for the stage of the peek & pop process. if you want to only know when the
    peek & pop process will be or is completed, you can also use [willbedone] or [isdone] variables.
  • i realised that when an [appbar] or a [cupertinonavigationbar] is built with full transparency, their height is not included in the layout of a
    [scaffold] or a [cupertinopagescaffold]. therefore, moving from a peek stage with a transparent header to a pop stage with a non-transparent header
    causes visual conflicts. use this [peekandpopchildstate]’s [size get headersize] and [double getheaderoffset(headeroffset headeroffset)] methods to
    overcome this problem.

Download this source code for
5 USD


Download this source code for
5 USD


Download this source code for
5 USD


Download this source code for
5 USD

Top