提交 f795ba7b authored 作者: Kevin's avatar Kevin

添加了PaintEvent

上级 30902c48
## [0.0.1] - TODO: Add release date.
## [0.1.0] - TODO: 改进了CupertionPopover和添加了CupertinoPopoverMenuItem
* TODO: Describe initial release.
* TODO: 改进了CupertionPopover箭头的位置
* TODO: 改进了CupertinoPopoverMenuItem按下的动画,并且添加了onTap
## [0.0.9] - TODO: 添加了一些控件,改进了CupertionPopover
......@@ -8,7 +9,7 @@
* TODO: 添加了CupertinoPopoverMenuItem
* TODO: 修改了CupertionPopover动画,
## [0.1.0] - TODO: 改进了CupertionPopover和添加了CupertinoPopoverMenuItem
## [0.0.1] - TODO: Add release date.
* TODO: Describe initial release.
* TODO: 改进了CupertionPopover箭头的位置
* TODO: 改进了CupertinoPopoverMenuItem按下的动画,并且添加了onTap
\ No newline at end of file
import 'package:cool_ui_example/cool_u_i_example_icons.dart';
import 'package:cool_ui_example/pages/PaintEventDemo.dart';
import 'package:cool_ui_example/pages/PopoverDemo.dart';
import 'package:flutter/material.dart';
......@@ -80,6 +81,12 @@ class _MyHomePageState extends State<MyHomePage> {
onTap: (){
Navigator.of(context).push(MaterialPageRoute(builder: (context)=>PopoverDemo()));
},
),
ListTile(
title: Text("PaintEvent"),
onTap: (){
Navigator.of(context).push(MaterialPageRoute(builder: (context)=>PaintEventDemo()));
},
)
],
)
......
import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart';
import 'package:cool_ui/cool_ui.dart';
class PaintEventDemo extends StatefulWidget{
@override
State<StatefulWidget> createState() {
// TODO: implement createState
return PaintEventDemoState();
}
}
class PaintEventDemoState extends State<PaintEventDemo>{
bool isPaintBackgroud = false;
@override
Widget build(BuildContext context) {
// TODO: implement build
return Scaffold(
appBar: AppBar(
title: Text("Popover Demo"),
),
body: Row(
children: <Widget>[
FlatButton(onPressed: (){
setState((){
isPaintBackgroud = !isPaintBackgroud;
});
}, child: Text(isPaintBackgroud?"渲染前填充颜色":"渲染后填充颜色")),
PaintEvent(
child: Text("子Widget文字"),
paintAfter: (context,offset,size){
if(!isPaintBackgroud){
final Paint paint = Paint();
paint.color = Colors.red;
context.canvas.drawRect(offset&size, paint);
}
},paintBefore: (context,offset,size){
if(isPaintBackgroud){
final Paint paint = Paint();
paint.color = Colors.red;
context.canvas.drawRect(offset&size, paint);
}
},
)
],
)
);
}
Widget _buildPopoverButton(String btnTitle,String bodyMessage){
return Padding(
padding: EdgeInsets.all(20.0),
child:CupertinoPopoverButton(
child: Container(
width: 80.0,
height: 40.0,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.all(Radius.circular(5.0)),
boxShadow: [BoxShadow(color: Colors.black12,blurRadius: 5.0)]
),
child: Center(child:Text(btnTitle)),
),
popoverBuild: (context) {
return CupertinoPopoverMenuList(
children: <Widget>[
CupertinoPopoverMenuItem(leading: Icon(Icons.add),child: Text("新增"),),
CupertinoPopoverMenuItem(leading: Icon(Icons.edit),child: Text("修改"),),
CupertinoPopoverMenuItem(leading: Icon(Icons.delete),child: Text("删除"),)
],
);
},
popoverWidth: 150.0,
popoverHeight: 123.0)
);
}
}
\ No newline at end of file
......@@ -52,6 +52,7 @@ class PopoverDemoState extends State<PopoverDemo>{
return Padding(
padding: EdgeInsets.all(20.0),
child:CupertinoPopoverButton(
child: Container(
width: 80.0,
height: 40.0,
......@@ -73,6 +74,8 @@ class PopoverDemoState extends State<PopoverDemo>{
},
popoverWidth: 150.0,
popoverHeight: 123.0)
);
}
}
\ No newline at end of file
library cool_ui;
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
part 'utils/screen_utils.dart';
part 'utils/widget_utils.dart';
part 'widgets/popover/cupertino_popover.dart';
part 'widgets/popover/cupertino_popover_menu_item.dart';
part 'widgets/utils/paint_event.dart';
part of cool_ui;
typedef PaintCallback = void Function(PaintingContext context, Offset offset,Size size);
class PaintEvent extends SingleChildRenderObjectWidget{
final PaintCallback paintBefore;
final PaintCallback paintAfter;
const PaintEvent({
Key key,
this.paintBefore,
this.paintAfter,
Widget child
}) :
super(key: key, child: child);
@override
PaintEventProxyBox createRenderObject(BuildContext context) {
return PaintEventProxyBox(
paintAfter: paintAfter,
paintBefore: paintBefore
);
}
@override
void updateRenderObject(BuildContext context, PaintEventProxyBox renderObject) {
renderObject..paintAfter = paintBefore
..paintAfter = paintAfter;
}
}
class PaintEventProxyBox extends RenderProxyBox{
PaintCallback paintBefore;
PaintCallback paintAfter;
PaintEventProxyBox({
RenderBox child,
this.paintBefore,
this.paintAfter
}):super(child);
@override
void detach() {
super.detach();
markNeedsPaint();
}
@override
void paint(PaintingContext context, Offset offset) {
assert(size.width != null);
assert(size.height != null);
if(this.paintBefore != null){
this.paintBefore(context,offset,size);
}
super.paint(context, offset);
if(this.paintAfter != null){
this.paintAfter(context,offset,size);
}
}
}
\ No newline at end of file
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论