页面来自Appbar
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
elevation: 0.0,
title: Text('Admin panel'),
leading: IconButton(
icon: Icon(Icons.menu),
onPressed: menuButtonPressed, <<<<<<?
),
),
body: BlocProvider<NavigationBloc>(
create: (context) => NavigationBloc(),
child: Stack(
children: <Widget>[
BlocBuilder<NavigationBloc, NavigationStates>(
builder: (context, navigationState) {
return navigationState as Widget;
},
),
TestMenu(),
测试菜单页面
class _TestMenu extends State<TestMenu> with SingleTickerProviderStateMixin {
AnimationController _animation;
@override
void initState() {
_animation = AnimationController(
value: 1,
vsync: this,
duration: drawerAnimationDuration,
);
super.initState();
}
@override
void dispose() {
_animation.dispose();
super.dispose();
}
void menuButtonPressed() {
if (_animation.isAnimating) return;
_animation.isCompleted ? _animation.reverse() : _animation.forward();
}
@override
Widget build(BuildContext context) {
return SlideTransition(
position: Tween<Offset>(
begin: Offset(-1, 0),
end: Offset.zero,
).animate(_animation),
child: Row(
children: <Widget>[
Container(
width: drawerWidth,
decoration: BoxDecoration(
border: Border(right: BorderSide(color: Colors.grey[300])),
),
menuButtonPressed
隐藏和显示侧边菜单。是否可以从页面 c 调用此函数AppBar
。
这是一个拐杖,但它有效:
你不擅长设计你的应用程序来做这样的事情......