Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Background Not Showing inside stack – flutter

I have a background widget inside Stack when i add a Column widget to stack the background not showing.when i remove column widget from stack it’s working alright.when using positioned widget as a parent of column widget it’s working fine.

enter image description here

my code :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

import 'package:flutter/material.dart';

class HomePage extends StatelessWidget {
  const HomePage({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    final double screenWidth = MediaQuery.of(context).size.width;
    final double screenHeight = MediaQuery.of(context).size.height;

    return Scaffold(
      body: Stack(
        children: [
          _BackGround(screenHeight: screenHeight,screenWidth: screenWidth,),
            Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                SizedBox(height: 50,)
              ],
            )
        ],
      ),
    );
  }
}


class _BackGround extends StatelessWidget {
  double screenWidth;
  double screenHeight;

  _BackGround({required this.screenWidth, required this.screenHeight});

  @override
  Widget build(BuildContext context) {
    return Positioned(
      right: 0,
      top: 0,
      width: screenWidth * 0.4,
      height: screenHeight * 0.8,
      child:ClipRRect(
        borderRadius: BorderRadius.only(bottomLeft: Radius.circular(20)),
      child: Container(
        child: ColoredBox(color: const Color(0xCC2372F0),),
      ),
      ) ,
    );
  }
}

>Solution :

You need to wrap your column with positioned widget. You can use Positioned or Align widget.

body: Stack(
  children: [
    _BackGround(
      screenHeight: screenHeight,
      screenWidth: screenWidth,
    ),
    Align(
      child: Column(
        mainAxisSize: MainAxisSize.min,
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          SizedBox(
            height: 50,
          )
        ],
      ),
    )
  ],
),

More about Stack.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading