Skip to content

Instantly share code, notes, and snippets.

@dnfield
Created August 27, 2018 21:26
Show Gist options
  • Save dnfield/7cd4b64580040abf3b9ce8982c51d68b to your computer and use it in GitHub Desktop.
Save dnfield/7cd4b64580040abf3b9ce8982c51d68b to your computer and use it in GitHub Desktop.
Rect.largest bug android
import 'package:flutter/material.dart';
void main() => runApp(new MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new MaterialApp(
title: 'Flutter Demo',
theme: new ThemeData(
primarySwatch: Colors.blue,
),
home: new MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
@override
_MyHomePageState createState() => new _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(
title: new Text(widget.title),
),
body: new Center(
child: new Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
new CustomPaint(
foregroundPainter: RectPainter(),
),
],
),
),
);
}
}
class RectPainter extends CustomPainter {
@override
void paint(Canvas canvas, Size size) {
var path = new Path()
..fillType = PathFillType.evenOdd
..addRect(Rect.largest) // error when using hardware rendering
// ..addRect(Rect.fromLTRB(-2000.0, -2000.0, 2000.0, 2000.0)) // no error with hardware rendering
..addOval(Rect.fromCircle(center: Offset(100.0, 100.0), radius: 25.0));
canvas.drawPath(
path,
new Paint()
..color = Colors.black
..style = PaintingStyle.fill);
}
@override
bool shouldRepaint(CustomPainter oldDelegate) => true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment