Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
459 views
in Technique[技术] by (71.8m points)

flutter code painting Rect bottom line below screen - why (example attached)

Why does the lower Rect line go below the screen even through I've aimed to calculate this?

enter image description here

Code:

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;
}
question from:https://stackoverflow.com/questions/65713411/flutter-code-painting-rect-bottom-line-below-screen-why-example-attached

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Try to manage your top and bottom area for notch or bottom control, SafeArea:

SafeArea(
 child: Container(),
 top: true,
 bottom: true,
) 

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

56.9k users

...