stopper
一個可透過拖曳展開至預設停止高度之一的底部彈出式面板。
一個 Flutter 小部件,可透過拖曳展開至預先定義的停止高度之一。
{"sdk":"flutter"}{"sdk":"flutter"}以下為英文專案原文快照,最新內容請造訪 GitHub。
A bottom sheet that can be expanded to one of the pre-defined stop heights by dragging.
animated image
Some iOS applications have a bottom sheet that has two states: half-expanded and fully expanded.
The standard showBottomSheet method lacks such a capability. The complexity in implementing this
behavior arises when the the bottom sheet needs to be scrollable, making scroll and drag
event handling difficult as these gestures can be used for scrolling the list as well as
for dragging the bottom sheet up/down, depending on the position of the bottom sheet and the current
scroll position. The Stopper plugin addresses this problem by:
ScrollController and ScrollPhysics objects and passing them to the
bottom sheet builder;showStopper function to be used instead of showBottomSheet in
order to handle dismissal of the bottom sheet by the user.This plugin utilizes bottom sheet functionality from the Scaffold
widget and avoids copy/paste from the standard library, making the implementation clear and
easy to maintain.
import 'package:stopper/stopper.dart';
//...
final height = MediaQuery.of(context).size.height;
//...
MaterialButton(
child: Text("Show Stopper"),
onPressed: () {
showStopper(
context: context,
stops: [0.5 * height, height],
builder: (context, scrollController, scrollPhysics, stop) {
return ListView(
controller: scrollController,
physics: scrollPhysics,
children: [
//...
]
);
}
);
},
...
)
Note: The build context passed to showStopper must have a Scaffold widget as an ancestor.
Therefore it's recommended to use Builder to build the body of the Scaffold. See
the complete example app provided in this package for details on this approach.