Flutter DraggableScrollableSheet doesn't show up by pressing button

前端 未结 3 854
日久生厌
日久生厌 2020-12-16 04:03

I want to use DraggableScrollableSheet widget on my application, when I use that like with below code, that can show without problem:

class Home         


        
3条回答
  •  有刺的猬
    2020-12-16 05:01

    If you want to do it with Animation, here is the solution.

    class HomePage extends StatefulWidget {
      @override
      _HomePageState createState() => _HomePageState();
    }
    
    class _HomePageState extends State with SingleTickerProviderStateMixin {
      AnimationController _controller;
      Duration _duration = Duration(milliseconds: 500);
      Tween _tween = Tween(begin: Offset(0, 1), end: Offset(0, 0));
    
      @override
      void initState() {
        super.initState();
        _controller = AnimationController(vsync: this, duration: _duration);
      }
    
      @override
      Widget build(BuildContext context) {
        return Scaffold(
          floatingActionButton: GestureDetector(
            child: FloatingActionButton(
              child: AnimatedIcon(icon: AnimatedIcons.menu_close, progress: _controller),
              elevation: 5,
              backgroundColor: Colors.deepOrange,
              foregroundColor: Colors.white,
              onPressed: () async {
                if (_controller.isDismissed)
                  _controller.forward();
                 else if (_controller.isCompleted)
                  _controller.reverse();
              },
            ),
          ),
          body: SizedBox.expand(
            child: Stack(
              children: [
                FlutterLogo(size: 500),
                SizedBox.expand(
                  child: SlideTransition(
                    position: _tween.animate(_controller),
                    child: DraggableScrollableSheet(
                      builder: (BuildContext context, ScrollController scrollController) {
                        return Container(
                          color: Colors.blue[800],
                          child: ListView.builder(
                            controller: scrollController,
                            itemCount: 25,
                            itemBuilder: (BuildContext context, int index) {
                              return ListTile(title: Text('Item $index'));
                            },
                          ),
                        );
                      },
                    ),
                  ),
                ),
              ],
            ),
          ),
        );
      }
    }
    

提交回复
热议问题