Flutter:如何在背景前放置文本?

问题描述 投票:0回答:1

我正在学习Flutter。而且我有一个问题,我的文字“欢迎”不在背景前面,而是在背景前面。我该如何解决?我认为这是造成集装箱的原因,但我不知道如何正确订购。对不起,我的代码格式错误。

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Login',
      home: Scaffold(
      body: ListView(
        children: <Widget>[
          Container(
        child: Stack(
          children: <Widget>[
            Container(
              padding: EdgeInsets.fromLTRB(15, 11, 0, 0),
              child: Text('Welcome', style: TextStyle( fontSize: 80, fontWeight: FontWeight.bold)),
            )
          ],
        ),
      ),
        Container(
        color: Colors.orangeAccent[100],
        alignment: Alignment.center,
        width: 420,
        height: 700,
        child: CustomPaint(
          painter: MyPainter(), 
          child: Align(
            alignment: Alignment(0.0, 0.15),
            child: RichText(
            text: TextSpan(
              style: DefaultTextStyle.of(context).style,
              children: <TextSpan>[
                TextSpan(
                  text: '    JUST BECAUSE YOU\n',
                  style: TextStyle(color: Colors.indigo[700], fontSize: 20, fontWeight: FontWeight.bold),
                )
                ),
              ],
            ),
          )
          ),
        ),
      ),
      ]
      )
      )
    );
  }
}

这是我的customPainter代码。

class MyPainter extends CustomPainter{
  @override
  void paint(ui.Canvas canvas, ui.Size size) {
    //final width = size.width;

    Path pigPath = Path();
    Path ovalPath = Path();


    pigPath.moveTo(0, size.height * 0.417);
    pigPath.quadraticBezierTo(size.width * 0.25, size.height * 0.6,
        size.width * 0.5, size.height * 0.37);
    pigPath.quadraticBezierTo(size.width * 0.7, size.height * 0.23,
        size.width * 1.0, size.height * 0.2);
    pigPath.lineTo(size.width, size.height);
    pigPath.lineTo(0, size.height);
    paint.color = Colors.cyan[100];
    canvas.drawPath(pigPath, paint);
  }

  @override
  bool shouldRepaint(CustomPainter oldDelegate) => false;

}

This is my problem

flutter dart flutter-layout
1个回答
0
投票

尝试一下:

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Login',
      home: Scaffold(
      body: ListView(
        children: <Widget>[
          Container(
        child: Stack(
          children: <Widget>[

        Container(
        color: Colors.orangeAccent[100],
        alignment: Alignment.center,
        width: 420,
        height: 700,
        child: CustomPaint(
          painter: MyPainter(), 
          child: Align(
            alignment: Alignment(0.0, 0.15),
            child: RichText(
            text: TextSpan(
              style: DefaultTextStyle.of(context).style,
              children: <TextSpan>[
                TextSpan(
                  text: '    JUST BECAUSE YOU\n',
                  style: TextStyle(color: Colors.indigo[700], fontSize: 20, fontWeight: FontWeight.bold),
                )
                ),
              ],
            ),
          )
          ),
        ),
      ),
Container(
              padding: EdgeInsets.fromLTRB(15, 11, 0, 0),
              child: Text('Welcome', style: TextStyle( fontSize: 80, fontWeight: FontWeight.bold)),
            )
          ],
        ),
      ),
      ]
      )
      )
    );
  }
}
© www.soinside.com 2019 - 2024. All rights reserved.