简体   繁体   中英

Flutter - raise widget above other widgets

How can I raise widget above other widgets, I need to show background opacity when focus on input and show the input above ask widget在此处输入图片说明 在此处输入图片说明 在此处输入图片说明

Sample code as an example

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,
        ),
      ),
    );
  }
}

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM