你可以使用Stack的widget来解决此问题。在Stack中,您可以使用“Positioned”widget来设置一个按钮,以使其始终显示在顶部,以免被其他小部件遮盖。下面是一个示例代码:
import 'package:flutter/material.dart';
class ButtonStack extends StatefulWidget {
@override
_ButtonStackState createState() => _ButtonStackState();
}
class _ButtonStackState extends State {
bool _pressed = false;
@override
Widget build(BuildContext context) {
return Stack(
children: [
Center(
child: Text(
'Click the button below to see the effect',
style: TextStyle(fontSize: 20.0),
),
),
Positioned(
bottom: 40.0,
right: 40.0,
child: RaisedButton(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(30.0)),
onPressed: () {
setState(() {
_pressed = !_pressed;
});
},
color: Colors.grey,
padding: EdgeInsets.symmetric(vertical: 15.0, horizontal: 50.0),
child: Text(
_pressed ? 'Pressed' : 'Not Pressed',
style: TextStyle(fontSize: 20.0),
),
),
),
],
);
}
}
在这个例子中,我们创建了一个“Stack”容器,并在中心添加了一个文本小部件。然后,我们使用“Positioned”widget将按钮放在底部右侧。这将确保当您点击按钮时,它不会被其他小部件遮盖。