Флаттер: как расположить текст перед фоном? - PullRequest
0 голосов
/ 25 марта 2020

Я учу Флаттер сейчас. И у меня есть некоторая проблема, что мой текст "добро пожаловать" не на заднем плане, но это. Как я могу это исправить? Я думаю, что это вызывает контейнер, но я не знаю, как правильно его заказать. Извините за мой неверный формат кода.

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;

}

Это моя проблема

1 Ответ

0 голосов
/ 25 марта 2020

Попробуйте это:

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)),
            )
          ],
        ),
      ),
      ]
      )
      )
    );
  }
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...