Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Dart 定制喷漆和配件盒_Dart_Flutter_Flutter Layout - Fatal编程技术网

Dart 定制喷漆和配件盒

Dart 定制喷漆和配件盒,dart,flutter,flutter-layout,Dart,Flutter,Flutter Layout,如何使我的CustomPaint适合父窗口小部件 return new Container( color: Color(0xfffff4f0), child: new Column( crossAxisAlignment: CrossAxisAlignment.stretch, mainAxisSize: MainAxisSize.max, children: <Widget>[ new Expand

如何使我的CustomPaint适合父窗口小部件

return new Container(
    color: Color(0xfffff4f0),
    child: new Column(
        crossAxisAlignment: CrossAxisAlignment.stretch,
        mainAxisSize: MainAxisSize.max,
        children: <Widget>[
          new Expanded(
          flex: 6,
          child: FittedBox(
                  fit: BoxFit.contain,
                  child: widget CustomePaint() // Containers(),

          )),
          new Expanded(
              flex: 4,
          )
    )
)
但不能使用CustomePaint()在画布矩形上绘制:

canvas.drawRect(new Rect.fromLTWH(0, 0, 10 , 30), new Paint()..color = 
Colors.red);

您似乎只提供了所需代码的一部分

我已经试过你的代码了,效果很好。我使用了其他颜色,并为CustomPaint添加了一个边框,以便更好地查看它的绘制位置


Widget getRootView() {
  return Container(
      color: Colors.green,
      child: Column(crossAxisAlignment: CrossAxisAlignment.stretch, mainAxisSize: MainAxisSize.max, children: <Widget>[
        Expanded(
          flex: 2,
          child: CustomPaint(painter: Painter3()),
        ),
        Expanded(
          flex: 1,
          child: Container(
            color: Colors.red,
            child: Center(child: Text("3")),
          ),
        )
      ]));
}

class Painter3 extends CustomPainter {
  @override
  void paint(Canvas canvas, Size size) {
    canvas.drawRect(Offset(10, 10) & Size(size.width - 20, size.height - 20), Paint()..color = Colors.blue);
  }

  @override
  bool shouldRepaint(CustomPainter oldDelegate) {
    return true;
  }
}


小部件getRootView(){
返回容器(
颜色:颜色。绿色,
子项:列(crossAxisAlignment:crossAxisAlignment.stretch,mainAxisSize:mainAxisSize.max,子项:[
扩大(
弹性:2,
子项:CustomPaint(画家:画家3()),
),
扩大(
弹性:1,
子:容器(
颜色:颜色,红色,
子对象:中间(子对象:文本(“3”)),
),
)
]));
}
类Painter3扩展了CustomPainter{
@凌驾
空心油漆(帆布,尺寸){
canvas.drawRect(偏移量(10,10)和大小(Size.width-20,Size.height-20),Paint()…color=Colors.blue);
}
@凌驾
bool应重新绘制(自定义代理){
返回true;
}
}
我在这里得到的是:


Widget getRootView() {
  return Container(
      color: Colors.green,
      child: Column(crossAxisAlignment: CrossAxisAlignment.stretch, mainAxisSize: MainAxisSize.max, children: <Widget>[
        Expanded(
          flex: 2,
          child: CustomPaint(painter: Painter3()),
        ),
        Expanded(
          flex: 1,
          child: Container(
            color: Colors.red,
            child: Center(child: Text("3")),
          ),
        )
      ]));
}

class Painter3 extends CustomPainter {
  @override
  void paint(Canvas canvas, Size size) {
    canvas.drawRect(Offset(10, 10) & Size(size.width - 20, size.height - 20), Paint()..color = Colors.blue);
  }

  @override
  bool shouldRepaint(CustomPainter oldDelegate) {
    return true;
  }
}