flutter 动画展开菜单_Flutter 底部向上动画弹出菜单

在移动应用开发中,我们经常会遇到弹出菜单的开发需求,对于下拉菜单可以参考Flutter 自定义下拉菜单,而如果是向上的弹出菜单或者更加负责的扇形菜单,则需要开发者进行自定义开发。

9ec23de7fae68e6954f99cb82ccd4fca.png

上面是自定义向上弹出菜单的示例,如果要实现上面的效果,需要开发者对动画(AnimationController、Animation)和Flow组件能够很熟练的进行使用。,为了方便大家快速的进行开发,现在我们将它封装城一个组件,使用前需要添加如下插件依赖代码。

shake_animation_widget: ^2.1.2

然后,再添加如下测试代码。

class HomePage extends StatefulWidget {

@override

_TestPageState createState() => _TestPageState();

}

class _TestPageState extends State{

@override

Widget build(BuildContext context) {

return Scaffold(

appBar: AppBar(

title: Text("测试"),

),

body: Container(

//填充

constraints: BoxConstraints.expand(),

//层叠布局

child: Stack(

children: [

Positioned(

right: 33,

bottom: 33,

//悬浮按钮

child: RoteFloatingButton(

//菜单图标组

iconList: [

Icon(Icons.add),

Icon(Icons.message),

Icon(Icons.aspect_ratio),

],

//点击事件回调

clickCallback: (int index){

},

),

),

],

),

),

);

}

除了上面这种线性的菜单外,扇形菜单或者圆形菜单也是比较常用的,例如下面是扇形菜单的示例代码。

void main() {

runApp(RootPage());

}

class RootPage extends StatelessWidget {

@override

Widget build(BuildContext context) {

return MaterialApp(

home: HomePage(),

);

}

}

class HomePage extends StatefulWidget {

@override

_TestPageState createState() => _TestPageState();

}

class _TestPageState extends State{

@override

Widget build(BuildContext context) {

return Scaffold(

appBar: AppBar(

title: Text("底部弹出菜单"),

),

body: Container(

// constraints: BoxConstraints.expand(),

child: Stack(

children: [

buildContainer(),

],

),

),

);

}

Container buildContainer() {

return Container(

child: BottomRoundFlowMenu(

iconList: [

Icon(

Icons.add_circle_outline,

color: Colors.white,

),

Icon(Icons.directions_car, color: Colors.white),

Icon(Icons.camera, color: Colors.white),

Icon(Icons.local_shipping, color: Colors.white),

],

iconBackgroundColorList: [

Colors.deepOrangeAccent,

Colors.deepPurple,

Colors.blueGrey,

Colors.blueAccent,

],

//点击事件回调

clickCallBack: (int index) {},

),

);

}

}

可以发现,配合动画组件和Flow组件,我们可以开发出很多复杂的效果。

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值