Slide-up view in Flutter

被刻印的时光 ゝ 提交于 2020-06-23 02:42:50

问题


I'm trying to make something similar to google/apple maps screen in flutter. I just started experimenting in Flutter and I have a hard time understand that "Draggable widget". Could someone give me example code how they made their slide-up view, I can learn from? I can't find any.


回答1:


Draggable (and DragTarget) is not used for what you call slide-up view

slide-up view, from the android world, is for bottom aligned modals. Draggable is to transfer data using Drag&Drop.

In flutter, bottom modals are fairly simple :

First, make sure you have somewhere above in your tree a Scaffold. As it's what will position everything together.

Then, call either showBottomSheet or showModalBottomSheet with whatever content you like. The content will now automatically appear at the bottom of your screen.

That's it, your job is done ! You can optionally now add a custom close event. For this, you'll just have to call Navigator.pop(context). But both modal and non-modal bottom sheet can be closed out of the box using common gestures. Such as back button, navbar back, of click outside.

Full example :

class MyExample extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      home: new Scaffold(
        appBar: new AppBar(title: new Text('Example')),
        body: new Center(
          child: new Builder(builder: (context) {
            return new Row(
              mainAxisAlignment: MainAxisAlignment.spaceEvenly,
              children: <Widget>[
                new RaisedButton(
                  onPressed: () => modal(context),
                  child: new Text("modal"),
                ),
                new RaisedButton(
                  onPressed: () => showSlideupView(context),
                  child: new Text("non modal"),
                ),
              ],
            );
          }),
        ),
      ),
    );
  }

  void showSlideupView(BuildContext context) {
    showBottomSheet(
        context: context,
        builder: (context) {
          return new Container(
            child: new GestureDetector(
              onTap: () => Navigator.pop(context),
              child: new Text("Click me to close this non-modal bottom sheet"),
            ),
          );
        });
  }

  modal(BuildContext context) {
    showModalBottomSheet(
        context: context,
        builder: (context) {
          return new Container(
            child: new Text("This is a modal bottom sheet !"),
          );
        });
  }
}




回答2:


There's also the sliding_up_panel Flutter library you could use to implement the same sort of design that Google/Apple Maps uses.




回答3:


Now you can use Sliding Up Panel plugin to do that, its awesome.




回答4:


To add this plugin And use it however you want :- SlidingUpPanel

Imported Suggestion :- A draggable Flutter widget that makes implementing a SlidingUpPanel much easier



来源:https://stackoverflow.com/questions/49159900/slide-up-view-in-flutter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!