如何在颤动中将一个容器夹在另一个容器上?

Ama*_*nda 2 user-interface containers flutter flutter-dependencies flutter-layout

我想构建一个可重复使用的卡片小部件,它将具有图像和文本以及一些自定义设计布局。我尽了一切努力,但未能达到预期的结果。任何帮助将非常感激。

这就是我想做的
这就是我想做的

我被困在这里了
我被困在这里了

这是我的代码

class ReusabelCard extends StatelessWidget {
      ReusabelCard(
          {this.cardChild, @required this.assetImagePath, @required this.cardText});
      final Widget cardChild;
      final String assetImagePath;
      final String cardText;
      @override
      Widget build(BuildContext context) {
        return Container(
            height: MediaQuery.of(context).size.height * 0.35,
            width: MediaQuery.of(context).size.width * 0.5,
            decoration: BoxDecoration(
              color: Colors.white,
              borderRadius: BorderRadius.circular(MediaQuery.of(context).size.width * 0.5 * 0.28),
            ),
            child: Stack(
              children: [
                LayoutBuilder(
                  builder: (context, contraint) {
                    return Column(
                      mainAxisAlignment: MainAxisAlignment.spaceAround,
                      children: [
                        Icon(
                          Icons.trip_origin,
                          size: contraint.biggest.width,
                          color: Colors.grey[300],
                        ),
                        Container(
                          height: MediaQuery.of(context).size.height*0.05,
                          width: MediaQuery.of(context).size.width,
                          color: Colors.green,
                        ),
                      ],
                    );
                  },
                ),
              ],
            )
            
            );
      }
    }
Run Code Online (Sandbox Code Playgroud)

Try*_*Try 7

使用ClipRRect来做到这一点:

ClipRRect(
  borderRadius: BorderRadius.circular(50.0), //clipping the whole widget
  child: Container(
    height: MediaQuery.of(context).size.height * 0.4, //I adjusted here for responsiveness problems on my device
    width: MediaQuery.of(context).size.width * 0.5,
    color: Colors.white,
    child: LayoutBuilder(
      builder: (context, constraint) {
        return Stack(
          children: [
            Center(
              child: Icon(
                Icons.trip_origin,
                size: constraint.biggest.width,
                color: Colors.grey[300],
              ),
            ),
            Positioned(
              right: 0,
              left: 0,
              top: 20.0,
              child: Icon(
                Icons.sports_volleyball_rounded, //just to represent the ball
                size: constraint.biggest.width * 0.5,
              ),
            ),
            Positioned(
              bottom: 0.0,
              child: Container(
                alignment: Alignment.center,
                height: MediaQuery.of(context).size.height * 0.1,
                width: constraint.biggest.width,
                color: Colors.yellow[700],
                child: Text(
                  'Sports',
                  style: Theme.of(context)
                      .textTheme
                      .headline3
                      .copyWith(color: Colors.white),
                ),
              ),
            ),
          ],
        );
      },
    ),
  ),
);
Run Code Online (Sandbox Code Playgroud)