|
| 1 | +import 'package:flutter/material.dart'; |
| 2 | +import 'package:flutter/rendering.dart'; |
| 3 | + |
| 4 | +void main() => runApp(MyApp()); |
| 5 | + |
| 6 | +class MyApp extends StatelessWidget { |
| 7 | + @override |
| 8 | + Widget build(BuildContext context) { |
| 9 | + return MaterialApp( |
| 10 | + title: 'Blog Demo', |
| 11 | + theme: ThemeData( |
| 12 | + primarySwatch: Colors.blue, |
| 13 | + ), |
| 14 | + home: MyHomePage(title: 'Blog Demo'), |
| 15 | + ); |
| 16 | + } |
| 17 | +} |
| 18 | + |
| 19 | +class MyHomePage extends StatefulWidget { |
| 20 | + MyHomePage({Key key, this.title}) : super(key: key); |
| 21 | + |
| 22 | + final String title; |
| 23 | + |
| 24 | + @override |
| 25 | + _MyHomePageState createState() => _MyHomePageState(); |
| 26 | +} |
| 27 | + |
| 28 | +class _MyHomePageState extends State<MyHomePage> { |
| 29 | + @override |
| 30 | + Widget build(BuildContext context) { |
| 31 | + return Scaffold( |
| 32 | + appBar: AppBar(title: Center(child: Text(widget.title))), |
| 33 | + body: ListView.builder( |
| 34 | + itemBuilder: (BuildContext context, int index) { |
| 35 | + return Container( |
| 36 | + alignment: Alignment.center, |
| 37 | + child: Transform( |
| 38 | + transform: Matrix4.translationValues(100, 0, 0), |
| 39 | + child: _CustomRenderObjectWidget( |
| 40 | + child: Transform( |
| 41 | + transform: Matrix4.translationValues(-50, 0, 0), |
| 42 | + child: Container( |
| 43 | + alignment: Alignment.center, |
| 44 | + width: 100, |
| 45 | + height: 100, |
| 46 | + color: Colors.black, |
| 47 | + child: Text( |
| 48 | + "Text", |
| 49 | + style: TextStyle(color: Colors.white), |
| 50 | + ))), |
| 51 | + ))); |
| 52 | + }, |
| 53 | + itemCount: 10), |
| 54 | + ); |
| 55 | + } |
| 56 | +} |
| 57 | + |
| 58 | +class _CustomRenderObjectWidget extends SingleChildRenderObjectWidget { |
| 59 | + final Widget child; |
| 60 | + |
| 61 | + _CustomRenderObjectWidget({this.child}) : super(child: child); |
| 62 | + @override |
| 63 | + RenderObject createRenderObject(BuildContext context) { |
| 64 | + return _CustomRenderObject(); |
| 65 | + } |
| 66 | +} |
| 67 | + |
| 68 | +class _CustomRenderObject extends RenderProxyBox { |
| 69 | + @override |
| 70 | + void paint(PaintingContext context, Offset offset) { |
| 71 | + super.paint(context, offset); |
| 72 | + print(offset); |
| 73 | + context.canvas.drawCircle(offset, 3, Paint()..color = Colors.red); |
| 74 | + } |
| 75 | +} |
| 76 | + |
| 77 | +class _BorderLinePainter extends CustomPainter { |
| 78 | + @override |
| 79 | + void paint(Canvas canvas, Size size) { |
| 80 | + canvas.drawCircle(Offset.zero, 3, Paint()..color = Colors.red); |
| 81 | + } |
| 82 | + |
| 83 | + @override |
| 84 | + bool shouldRepaint(CustomPainter oldDelegate) { |
| 85 | + return true; |
| 86 | + } |
| 87 | +} |
0 commit comments