我有一个视频播放器,并且有一个自定义按钮可以返回。我想在屏幕上显示该按钮,然后在1或2秒钟后隐藏。可以是透明的应用栏,可在屏幕上显示并点按并隐藏,并且该应用栏包含自定义按钮
最佳答案
void main() => runApp(MaterialApp(home: YourPage()));
class YourPage extends StatefulWidget {
@override
_YourPageState createState() => _YourPageState();
}
class _YourPageState extends State<YourPage> {
bool _showControls = false; // set it to false initially
_showAndHideControls() {
// show controls the moment user tapped on screen
setState(() => _showControls = true);
// after 2 seconds, hide the controls
Timer(Duration(seconds: 2), () {
setState(() => _showControls = false);
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: _showControls ? AppBar(title: Text("AppBar")) : null,
body: Center(
child: RaisedButton(
child: Text("Click me"),
onPressed: _showAndHideControls,
),
),
);
}
}
关于flutter - 在屏幕水龙头上显示应用栏或平面按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58138179/