pulp_flash
用于向用户宣布不同消息并与之交互的简单多功能闪烁提示。可以同时显示多个闪烁提示,避免为处理应用程序的不同情况编写数千行额外的代码。
特点
- 显示多条消息
- 固定消息
- 可自定义状态
- 每条消息可自定义显示时长

更多功能即将推出。如果您认为有任何有益于该软件包的错误或功能,请随时报告
用法
您只需设置一个 ChangeNotifierProvider<PulpFlash>(我建议将其放在 MaterialApp 的上方,这样您就不必担心上下文,并且可以轻松地在任何地方使用它),然后像这样调用它
Provider.of<PulpFlash>(context, listen: false)
.showMessage(context,messageThatYouWantToShow);
消息
Message({
String? title,
String? description,
required MessageStatus status,
String? actionLabel,
void Function()? onActionPressed,
bool pinned = false,
Duration displayDuration = const Duration(seconds: 10),
})
示例
void main() => runApp(ChangeNotifierProvider<PulpFlash>(
create: (context) => PulpFlash(),
child: const MaterialApp(
home: MyApp(),
),
builder: (context, child) => child!));
class MyApp extends StatelessWidget {
const MyApp({ Key? key }) : super(key: key);
@override
Widget build(BuildContext context) {
return Scaffold(floatingActionButton: FloatingActionButton(
onPressed: (){
Provider.of<PulpFlash>(context, listen: false)
.showMessage(context,
inputMessage:Message(
status: MessageStatus.successful,
actionLabel: 'Upload new one',
onActionPressed: (){
//TODO:
},
title: 'Hurayyyy!',
description:
"Your file successfully uploaded. you can change whenever you want in the account section.",
),
);
},
),
);
}
}