簡體   English   中英

一個 RenderFlex 在 Flutter 底部溢出了 86 個像素

[英]A RenderFlex overflowed by 86 pixels on the bottom in Flutter

我正在以 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;
  }
}

人像模式請參考下圖

在此處輸入圖片說明

橫向模式請參考下圖(發生錯誤的地方):

在此處輸入圖片說明

問題是您在 Column 小部件中使用硬編碼邊距,這也會給小型設備帶來問題。 您可以解決為 ListView 小部件更改列小部件的問題,但這會給您帶來滾動效果,我認為您不希望那樣。 因此,您可以使用Expanded Widget重構該 Column,並且 Stack 可以幫助該 Column 的第一部分,請嘗試下一個:

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, ), ), ), ), ), ) ], )

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM