问题
I'm trying to open a navigation drawer like bottom sheet, on appBar button click . I browsed it for but couldn't get any solution.
See below image:
The Code I was trying:
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),
),
)
);
but background is black not able to see partial view of previous page.
回答1:
You can see an example widget BackDrop
I think if you change the position of the top and bottom, everything will work perfectly
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));
}
回答2:
There is a widget BackDrop
in flutter to do the functions you want.You need to use backdrop 0.2.7
library.You can get reference from Flutter Backdrop
回答3:
At last I added animation with SlideTransition()
Widget . Because I didn't get any perfect solution for it but it's working perfect & i'm very happy with it :).
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(.....)
)
);
}
}
来源:https://stackoverflow.com/questions/59464729/how-to-make-top-navigation-drawer-with-flutter