PaintEventDemo.dart 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. import 'package:flutter/material.dart';
  2. import 'package:flutter/cupertino.dart';
  3. import 'package:cool_ui/cool_ui.dart';
  4. class PaintEventDemo extends StatefulWidget{
  5. @override
  6. State<StatefulWidget> createState() {
  7. // TODO: implement createState
  8. return PaintEventDemoState();
  9. }
  10. }
  11. class PaintEventDemoState extends State<PaintEventDemo>{
  12. bool isPaintBackgroud = false;
  13. @override
  14. Widget build(BuildContext context) {
  15. // TODO: implement build
  16. return Scaffold(
  17. appBar: AppBar(
  18. title: Text("Popover Demo"),
  19. ),
  20. body: Row(
  21. children: <Widget>[
  22. FlatButton(onPressed: (){
  23. setState((){
  24. isPaintBackgroud = !isPaintBackgroud;
  25. });
  26. }, child: Text(isPaintBackgroud?"渲染前填充颜色":"渲染后填充颜色")),
  27. PaintEvent(
  28. child: Text("子Widget文字"),
  29. paintAfter: (context,offset,size){
  30. if(!isPaintBackgroud){
  31. final Paint paint = Paint();
  32. paint.color = Colors.red;
  33. context.canvas.drawRect(offset&size, paint);
  34. }
  35. },paintBefore: (context,offset,size){
  36. if(isPaintBackgroud){
  37. final Paint paint = Paint();
  38. paint.color = Colors.red;
  39. context.canvas.drawRect(offset&size, paint);
  40. }
  41. },
  42. )
  43. ],
  44. )
  45. );
  46. }
  47. Widget _buildPopoverButton(String btnTitle,String bodyMessage){
  48. return Padding(
  49. padding: EdgeInsets.all(20.0),
  50. child:CupertinoPopoverButton(
  51. child: Container(
  52. width: 80.0,
  53. height: 40.0,
  54. decoration: BoxDecoration(
  55. color: Colors.white,
  56. borderRadius: BorderRadius.all(Radius.circular(5.0)),
  57. boxShadow: [BoxShadow(color: Colors.black12,blurRadius: 5.0)]
  58. ),
  59. child: Center(child:Text(btnTitle)),
  60. ),
  61. popoverBuild: (context) {
  62. return CupertinoPopoverMenuList(
  63. children: <Widget>[
  64. CupertinoPopoverMenuItem(leading: Icon(Icons.add),child: Text("新增"),),
  65. CupertinoPopoverMenuItem(leading: Icon(Icons.edit),child: Text("修改"),),
  66. CupertinoPopoverMenuItem(leading: Icon(Icons.delete),child: Text("删除"),)
  67. ],
  68. );
  69. },
  70. popoverWidth: 150.0,
  71. popoverHeight: 123.0)
  72. );
  73. }
  74. }