Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter: Positioned inside stack cuts off my widget

Tags:

flutter

dart

I am using stuck to overlapping my widget. this is my widget:

  @override
  Widget build(BuildContext context) {
    return SingleChildScrollView(
      controller: controller,
      child: SizedBox(
        height: double.maxFinite,
        child: Column(
          children: [
            Container(
              width: double.maxFinite,
              constraints: BoxConstraints(maxHeight: 200),
              color: Colors.blue,
              child: Stack(
                // clipBehavior: Clip.none,
                children: [
                  Positioned(
                    bottom: -25,
                    left: 0,
                    right: 0,
                    child: Container(
                      width: 60,
                      height: 60,
                      padding: EdgeInsets.all(8),
                      color: Colors.blue,
                      child: CircleAvatar(
                          backgroundColor: Colors.white,
                          child: Icon(Icons.mail)),
                    ),
                  ),
                ],
              ),
            )
          ],
        ),
      ),
    );
  }

this is an image :

enter image description here

as you can see my image was cut off.I added clipBehavior: Clip.none, to stack but it just increase the height of stack :

enter image description here

I want the button to come down from the blue container. Like all the pictures I took, without cut off.

like image 486
Cyrus the Great Avatar asked May 21 '26 19:05

Cyrus the Great


1 Answers

I fix this issue :

@override
  Widget build(BuildContext context) {
    return SingleChildScrollView(
      controller: controller,
      child: SizedBox(
        height: double.maxFinite,
        child: Column(
          children: [
            Container(
              width: double.maxFinite,
              height: 200,
              color: Colors.blue,
              child: Stack(
                clipBehavior: Clip.none,
                children: [
                  Align(
                    alignment: Alignment.center,
                    child: Container(
                      child: Column(
                        mainAxisSize: MainAxisSize.max,
                        crossAxisAlignment: CrossAxisAlignment.center,
                        mainAxisAlignment: MainAxisAlignment.center,
                        children: [
                          Text("test",
                              style:
                                  TextStyle(fontSize: 25, color: Colors.white)),
                        ],
                      ),
                    ),
                  ),
                  Positioned(
                    bottom: -25,
                    left: 0,
                    right: 0,
                    child: CircleAvatar(
                        backgroundColor: Colors.white,
                        child: Icon(Icons.campaign)),
                  ),
                ],
              ),
            )
          ],
        ),
      ),
    );
  }
}

result:

enter image description here

like image 191
Cyrus the Great Avatar answered May 23 '26 21:05

Cyrus the Great



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!