Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
f4d784dc
Commit
f4d784dc
authored
Feb 11, 2016
by
Adam Barth
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add an example of creating a custom RenderBox
parent
75bc0277
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
42 additions
and
0 deletions
+42
-0
custom_render_box.dart
examples/widgets/custom_render_box.dart
+42
-0
No files found.
examples/widgets/custom_render_box.dart
0 → 100644
View file @
f4d784dc
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import
'package:flutter/rendering.dart'
;
import
'package:flutter/widgets.dart'
;
class
_CustomRenderBox
extends
RenderConstrainedBox
{
_CustomRenderBox
()
:
super
(
additionalConstraints:
const
BoxConstraints
.
expand
());
// Makes this render box hittable so that we'll get pointer events.
bool
hitTestSelf
(
Point
position
)
=>
true
;
final
Map
<
int
,
Point
>
_dots
=
<
int
,
Point
>{};
void
handleEvent
(
PointerEvent
event
,
BoxHitTestEntry
entry
)
{
if
(
event
is
PointerDownEvent
||
event
is
PointerMoveEvent
)
{
_dots
[
event
.
pointer
]
=
event
.
position
;
markNeedsPaint
();
}
else
if
(
event
is
PointerUpEvent
||
event
is
PointerCancelEvent
)
{
_dots
.
remove
(
event
.
pointer
);
markNeedsPaint
();
}
}
void
paint
(
PaintingContext
context
,
Offset
offset
)
{
final
Canvas
canvas
=
context
.
canvas
;
canvas
.
drawRect
(
offset
&
size
,
new
Paint
()..
color
=
new
Color
(
0xFF00FF00
));
Paint
paint
=
new
Paint
()..
color
=
new
Color
(
0xFF0000FF
);
for
(
Point
point
in
_dots
.
values
)
canvas
.
drawCircle
(
point
,
50.0
,
paint
);
}
}
class
_CustomRenderBoxWidget
extends
OneChildRenderObjectWidget
{
_CustomRenderBox
createRenderObject
()
=>
new
_CustomRenderBox
();
}
void
main
(
)
{
runApp
(
new
_CustomRenderBoxWidget
());
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment