-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: render objects not rendering text (#98)
- Loading branch information
Showing
4 changed files
with
93 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import 'package:alchemist/alchemist.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
|
||
void main() { | ||
group('smoke test', () { | ||
goldenTest( | ||
'succeeds for custom render object drawing text', | ||
fileName: 'render_object_text_smoke_test', | ||
builder: () => const SizedBox( | ||
height: 400, | ||
width: 400, | ||
child: _CustomExampleRenderObject(), | ||
), | ||
); | ||
}); | ||
} | ||
|
||
class _CustomExampleRenderObject extends LeafRenderObjectWidget { | ||
const _CustomExampleRenderObject({Key? key}) : super(key: key); | ||
|
||
@override | ||
_CustomExampleRenderBox createRenderObject(BuildContext context) { | ||
return _CustomExampleRenderBox(); | ||
} | ||
} | ||
|
||
class _CustomExampleRenderBox extends RenderBox { | ||
@override | ||
void paint(PaintingContext context, Offset offset) { | ||
final textPainter = TextPainter( | ||
text: const TextSpan( | ||
text: 'text', | ||
style: TextStyle( | ||
fontFamily: 'Roboto', | ||
color: Colors.black, | ||
fontSize: 24, | ||
), | ||
), | ||
textDirection: TextDirection.ltr, | ||
)..layout(); | ||
textPainter.paint( | ||
context.canvas, | ||
const Offset(200, 200) - textPainter.size.center(Offset.zero), | ||
); | ||
} | ||
|
||
@override | ||
void performLayout() { | ||
size = computeDryLayout(constraints); | ||
} | ||
|
||
@override | ||
Size computeDryLayout(BoxConstraints constraints) { | ||
return constraints.constrain( | ||
Size( | ||
200, | ||
constraints.maxHeight, | ||
), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters