如何使顶部导航抽屉颤抖?

时间:2019-12-24 06:32:02

标签: flutter dart drawer

我正在尝试打开导航栏(如底部),在appBar按钮上单击。 我浏览了它,但找不到任何解决方案。

请参见下图:

enter image description here

我正在尝试的代码:

 return Scaffold(
      backgroundColor: Colors.transparent,
      body: Container(
        height: MediaQuery.of(context).size.height/2,
        //constraints: BoxConstraints.expand(),
        decoration: BoxDecoration(
          color: Color.fromARGB(255, 255, 255, 255),
        ),
      )
    );

但是背景为黑色,无法看到上一页的局部视图。

4 个答案:

答案 0 :(得分:1)

您可以看到示例小部件BackDrop

我认为,如果您更改顶部和底部的位置,一切都会正常运行

Animation<RelativeRect> _getPanelAnimation(BoxConstraints constraints) {
  final double height = constraints.biggest.height;
  final double top = height - _PANEL_HEADER_HEIGHT;
  final double bottom = -_PANEL_HEADER_HEIGHT;
  return new RelativeRectTween(
    begin: new RelativeRect.fromLTRB(0.0, top, 0.0, bottom),
    end: new RelativeRect.fromLTRB(0.0, 0.0, 0.0, 0.0),
  ).animate(new CurvedAnimation(parent: _controller, curve: Curves.linear));
}

答案 1 :(得分:0)

扑朔迷离中有一个小部件BackDrop可以执行所需的功能。您需要使用backdrop 0.2.7库。您可以从Flutter Backdrop

获取引用

答案 2 :(得分:0)

最后,我添加了带有SlideTransition()小部件的动画。因为我没有得到任何完美的解决方案,但是它工作得很完美,我对此非常满意:)。


 new IconButton(
    icon: new Image.asset('assets/images/ui-16px-3-funnel-40.png'),
    onPressed: () {        
     showDialog(
      context: context,
      child: FiltersPage()
     );
   },
 ),





import 'package:flutter/material.dart';

class FiltersPage extends StatefulWidget {
  @override
  _FiltersPageState createState() => _FiltersPageState();
}

class _FiltersPageState extends State<FiltersPage> with SingleTickerProviderStateMixin{

  AnimationController controller;
  Animation<Offset> slideAnimation;

  @override
  void initState() {
    controller =  AnimationController(vsync: this, duration: Duration(milliseconds: 450)); 
    slideAnimation = Tween<Offset>(begin: Offset(0.0, -4.0), end: Offset.zero)
      .animate(CurvedAnimation(parent: controller, curve: Curves.decelerate));
    controller.addListener(() {
      setState(() {});
    });
    controller.forward();
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return SlideTransition(
      position: slideAnimation,
      child: Scaffold(
        backgroundColor: Colors.transparent,
        appBar:AppBar(.......)
        body: Container(
        padding: const EdgeInsets.all(13.0),
          height: MediaQuery.of(context).size.height/2.7,
          width: MediaQuery.of(context).size.width,
          decoration: BoxDecoration(
            color: Color.fromARGB(255, 255, 255, 255),
          ),
         child:Column(.....)
       )
    );
  }
}

答案 3 :(得分:0)

我使用 PageRouteBuilder 做了类似的事情,它是 DialogBu​​ilder 的父级,带有动画参数,您还可以设置暗色等。 比如说,在主小部件中有一个按钮:

TextButton(
        child: Text("open drawer"),
        onPressed: () {
          Navigator.of(context).push(_createRoute());
        },
      )

然后是带有动画等的路线构建器:

  Route _createRoute() {
    return PageRouteBuilder(
      pageBuilder: (context, animation, secondaryAnimation) => TopDrawer(),
      transitionsBuilder: (context, animation, secondaryAnimation, child) {
        const begin = Offset(0.0, -4.0);
        const end = Offset.zero;
        const curve = Curves.decelerate;
        var tween = Tween(begin: begin, end: end).chain(CurveTween(curve: curve));

        return SlideTransition(
          position: tween.animate(animation),
          child: child,
        );
      },
      opaque: false,
      barrierDismissible: true,
      barrierColor: Color.fromRGBO(100, 100, 100, 0.5), //color of the grayed under
      transitionDuration: Duration(milliseconds: 450),
      reverseTransitionDuration: Duration(milliseconds: 450),
    );
  }

还有它显示的抽屉页面:

import 'package:flutter/material.dart';

class TopDrawer extends StatelessWidget {
  const TopDrawer({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Column(
      children: [
        Container(
          height: MediaQuery.of(context).size.height/2,
          width: MediaQuery.of(context).size.width,
          child: Text("some content here"),
          color: Colors.green,
        ),
      ],
    );
  }
}