gpt4 book ai didi

android - 如何在flutter中实现 float Snackbar动画?

转载 作者:行者123 更新时间:2023-12-05 00:07:49 26 4
gpt4 key购买 nike

我正在尝试在 float Snackbar 中实现动画,它从屏幕底部出现并向上移动,就像 Gmail 应用程序中的一个在滑动邮件时出现。有人可以发布一个例子吗?

ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text(
'Product removed from cart',
),
action: SnackBarAction(
label: 'Undo',
onPressed: () {
//
}),
duration: Duration(seconds: 3),
behavior: SnackBarBehavior.floating,
margin: EdgeInsets.only(bottom: 30,left: 10,right: 10),
animation: // **Answer Please**
}

最佳答案

默认的 Flutter Snackbar 并没有提供太多的自定义方式。您可以使用的一个库称为 getx .这是一个提供许多东西的包,其中包括一个非常灵活的 snackbar 。这是我能够提出的向上/向下动画,而不是淡入/淡出。
Snackbar demo

class SnackbarExample extends StatelessWidget {
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
final ColorScheme colorScheme = theme.colorScheme;
final bool isThemeDark = theme.brightness == Brightness.dark;
final Color themeBackgroundColor = isThemeDark
? colorScheme.onSurface
: Color.alphaBlend(colorScheme.onSurface.withOpacity(0.80), colorScheme.surface);

return Center(
child: TextButton(
child: Text(
'Show snackbar',
style: TextStyle(fontSize: 20),
),
onPressed: () {
Get.snackbar(
'',
'',
snackPosition: SnackPosition.BOTTOM,
snackStyle: SnackStyle.FLOATING,
messageText: Text(
'Product removed from cart',
style: TextStyle(
color: Colors.white,
fontSize: 15,
fontWeight: FontWeight.w400,
),
),
titleText: Container(),
margin: const EdgeInsets.only(bottom: kBottomNavigationBarHeight, left: 8, right: 8),
padding: const EdgeInsets.only(bottom: 4, left: 16, right: 16),
borderRadius: 4,
backgroundColor: themeBackgroundColor,
colorText: Theme.of(context).colorScheme.surface,
mainButton: TextButton(
child: Text('Undo'),
onPressed: () {},
),
);
},
),
);
}
}

关于android - 如何在flutter中实现 float Snackbar动画?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67219584/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com