即使我的目标是计算,为什么下方的 Rect 线会在屏幕下方?
代码:
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
),
body: MainScreen(),
),
);
}
}
class MainScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
var mq = MediaQuery.of(context);
final logicWidth = mq.size.width;
final logicHeight = mq.size.height;
return
SizedBox.expand(
child: Container(
color: Colors.blueGrey,
child: FittedBox(
fit: BoxFit.none, // Can more to "contain" after
alignment: Alignment.topLeft,
child: SizedBox(
width: logicWidth,
height: logicHeight,
child: CustomPaint(painter: GCPainter(),),
))));
}
}
class GCPainter extends CustomPainter {
@override
void paint(Canvas canvas, Size size) {
var paint1 = Paint()..color = Colors.red..style = PaintingStyle.stroke..strokeWidth = 50;
Rect rect = Rect.fromLTWH(0, 0, size.width, size.height);
canvas.drawRect(rect, paint1);
}
@override
bool shouldRepaint(GCPainter oldDelegate) => false;
@override
bool shouldRebuildSemantics(GCPainter oldDelegate) => false;
}