RenderFlex在Flutter底部溢出86像素

时间:2020-03-05 17:09:31

标签: flutter

我正在以抖动方式创建一个应用程序,在纵向模式下,一切看起来都很好,但是在横向模式下,它将触发并显示错误A RenderFlex overflowed by 86 pixels on the bottom。以下是我尝试过的所有代码,并且共享了图像,请参阅相同的内容以获取更多说明。

import 'dart:math';

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
          primarySwatch: Colors.blue,
          brightness: Brightness.dark
      ),
      debugShowCheckedModeBanner: false,
      home: MyHomePage(),
    );
  }
}

class MyHomePage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {

    return Scaffold(
      resizeToAvoidBottomPadding: false,
      body: new Stack(
        children: <Widget>[
          Container(
            decoration: ShapeDecoration(
              gradient:LinearGradient(
                  begin: Alignment.bottomLeft,
                  end: Alignment.topRight,
                  colors: [Colors.yellow,Colors.yellow,Colors.orangeAccent,Colors.deepOrange,]
              ),
              // color: Colors.deepOrangeAccent,
              shape: CustomShapeBorder(),
            ),

          ),
          Column(
            children: <Widget>[
              Padding(
                padding: const EdgeInsets.only(top: 200.0,left: 50.0),
                child: Text(
                  "SET, MATCH AND CHALLENGE",
                  style: TextStyle(
                    fontSize: 40.0,
                  ),
                ),
              ),
              Padding(
                padding: const EdgeInsets.only(left: 30.0,right: 30.0, top: 30.0),
                child: Text(
                  "A simple, fun, and a creative way to "
                      "set the bespoke challenges with "
                      "either a friend or a group of "
                      "friends anywhere in the world",
                  textAlign: TextAlign.justify,
                  style: TextStyle(
                      color: Colors.white
                  ),
                ),
              ),
              Container(
                width: 300.0,
                height: 60.0,
                margin: const EdgeInsets.only(top: 140.0),
                child: RaisedButton(
                  textColor: Colors.white,
                  color: Colors.grey,
                  shape: RoundedRectangleBorder(
                    borderRadius: new BorderRadius.circular(18.0),
                  ),
                  child: Text("Sign Up",
                    textAlign: TextAlign.center,
                    style: TextStyle(
                      fontSize: 20.0,
                    ),
                  ),
                ),
              ),
            ],
          ),
          Container(
            margin: const EdgeInsets.only(bottom: 0.0, right: 0.0),
            child: Align(
              alignment: Alignment.bottomRight,
              child: Transform.rotate(
                angle: pi,
                child: Container(
                  decoration: ShapeDecoration(
                    gradient:LinearGradient(
                        begin: Alignment.bottomLeft,
                        end: Alignment.topRight,
                        colors: [Colors.yellow,Colors.yellow,Colors.orangeAccent,Colors.deepOrange,]
                    ),
                    //color: Colors.deepOrangeAccent,
                    shape: CustomShapeBorder(),
                  ),
                ),
              ),
            ),
          ),

        ],
      ),

    );
  }
}

class CustomShapeBorder extends ShapeBorder {
  final double distanceFromWall = 12;
  final double controlPointDistanceFromWall = 5;


  @override
  // TODO: implement dimensions
  EdgeInsetsGeometry get dimensions => null;

  @override
  Path getInnerPath(Rect rect, {TextDirection textDirection}) {
    // TODO: implement getInnerPath
    return null;
  }

  @override
  Path getOuterPath(Rect rect, {TextDirection textDirection}) {
    // TODO: implement getOuterPath
    return getClip(Size(260.0,180.0));
  }

  @override
  void paint(Canvas canvas, Rect rect, {TextDirection textDirection}) {
    // TODO: implement paint
  }

  @override
  ShapeBorder scale(double t) {
    // TODO: implement scale
    return null;
  }

  Path getClip(Size size) {
    Path clippedPath = new Path();

    clippedPath.lineTo(0, size.height);
    clippedPath.quadraticBezierTo(30, size.height + 10, size.width * 0.20, size.height - 50);
    clippedPath.quadraticBezierTo(70, size.height - 120, size.width * 0.40, size.height * 0.35);
    clippedPath.quadraticBezierTo(180, (size.height - (size.height* 0.6)), size.width - 40 , 32 );
    clippedPath.quadraticBezierTo(250, 0, size.width, 0);
    clippedPath.lineTo(size.width, 0);
    clippedPath.close();
    return clippedPath;
  }
}

有关人像模式,请参见下图

enter image description here

有关横向模式,请参考下图(发生错误的地方):

enter image description here

1 个答案:

答案 0 :(得分:0)

问题是您在Column小部件中使用了硬编码边距,这也会在小型设备中出现问题。您可以修复将ListView Widget更改为Column Widget的问题,但这将为您带来滚动效果,我想您不想要那样。因此,您可以使用Expanded Widget重构该列,而堆栈可以在该列的第一部分中提供帮助,请尝试下一个:

Column( children: <Widget>[ Expanded( flex: 1, child: Container( padding: EdgeInsets.symmetric(horizontal: 50), child: Stack( children: <Widget>[ Center( child: Text( "SET, MATCH AND CHALLENGE", style: TextStyle( fontSize: 40.0, ), ), ), Align( alignment: Alignment.bottomCenter, child: Text( "A simple, fun, and a creative way to " "set the bespoke challenges with " "either a friend or a group of " "friends anywhere in the world", textAlign: TextAlign.justify, style: TextStyle( color: Colors.white ), ), ) ], ), ), ), Expanded( flex: 1, child: Center( child: Container( width: 300.0, height: 60.0, child: RaisedButton( textColor: Colors.white, color: Colors.grey, shape: RoundedRectangleBorder( borderRadius: new BorderRadius.circular(18.0), ), child: Text("Sign Up", textAlign: TextAlign.center, style: TextStyle( fontSize: 20.0, ), ), ), ), ), ) ], )