Flutter-将小部件置于其他小部件之上

时间:2020-01-29 17:40:43

标签: flutter flutter-layout flutter-animation

我如何将小部件置于其他小部件之上, 当专注于输入时,我需要显示背景不透明度,并在Ask小部件上方显示输入 enter image description here enter image description here enter image description here

2 个答案:

答案 0 :(得分:0)

示例代码

class SO extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return SafeArea(
      child: Scaffold(
        body: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.spaceAround,
            children: <Widget>[X(), X(), X(), X()],
          ),
        ),
      ),
    );
  }
}

class X extends StatefulWidget {
  @override
  _XState createState() => _XState();
}

class _XState extends State<X> {
  bool isElevated = false;

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: () {
        print('_XState.build() tap');
        setState(() {
          isElevated = !isElevated;
        });
      },
      child: Material(
        elevation: isElevated ? 40 : 0, //change as needed
        animationDuration: Duration(milliseconds: 400), //change as needed
        child: Container(
          width: 100,
          height: 100,
          color: Colors.red,
        ),
      ),
    );
  }
}

答案 1 :(得分:-1)

您可以尝试将堆栈作为所有其他窗口小部件的父窗口小部件。