bool _shouldShowTranslateButton = false;
@override
void initState() {
super.initState();
// 在初始化时获取翻译按钮显示状态
_checkTranslateButtonVisibility();
}
Future<void> _checkTranslateButtonVisibility() async {
bool canShowTranslation = await canShowTranslate(
isSelf: false,
wsImMessage: yourWsImMessage,
translateSwitch: true,
originalText: yourOriginalText,
);
setState(() {
_shouldShowTranslateButton = canShowTranslation;
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Your App'),
),
body: Center(
child: _shouldShowTranslateButton
? ElevatedButton(
onPressed: () {
// 处理点击翻译按钮的逻辑
},
child: Text('Translate'),
)
: Container(),
),
);
}
flutter异步刷新布局可以用下面的
于 2024-03-26 19:23:19 首次发布
这篇文章介绍了如何在Flutter应用中初始化时检查翻译按钮的显示状态,并在适当条件下添加一个点击事件处理翻译功能。
摘要由CSDN通过智能技术生成