Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DiDi
DoraemonKit
提交
73a816e2
D
DoraemonKit
项目概览
DiDi
/
DoraemonKit
12 个月 前同步成功
通知
166
Star
19623
Fork
3062
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
DoraemonKit
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
73a816e2
编写于
5月 06, 2021
作者:
J
JellyBean
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feature: 空安全改造
上级
75b11260
变更
19
隐藏空白更改
内联
并排
Showing
19 changed file
with
298 addition
and
264 deletion
+298
-264
Flutter/lib/kit/apm/apm.dart
Flutter/lib/kit/apm/apm.dart
+2
-2
Flutter/lib/kit/apm/fps_kit.dart
Flutter/lib/kit/apm/fps_kit.dart
+6
-6
Flutter/lib/kit/apm/launch/model.dart
Flutter/lib/kit/apm/launch/model.dart
+2
-2
Flutter/lib/kit/apm/launch/page_launch_kit.dart
Flutter/lib/kit/apm/launch/page_launch_kit.dart
+6
-4
Flutter/lib/kit/apm/launch/route_observer.dart
Flutter/lib/kit/apm/launch/route_observer.dart
+3
-3
Flutter/lib/kit/apm/log_kit.dart
Flutter/lib/kit/apm/log_kit.dart
+27
-24
Flutter/lib/kit/apm/memory_kit.dart
Flutter/lib/kit/apm/memory_kit.dart
+22
-23
Flutter/lib/kit/apm/method_channel_kit.dart
Flutter/lib/kit/apm/method_channel_kit.dart
+26
-27
Flutter/lib/kit/apm/route_kit.dart
Flutter/lib/kit/apm/route_kit.dart
+24
-23
Flutter/lib/kit/apm/source_code_kit.dart
Flutter/lib/kit/apm/source_code_kit.dart
+15
-12
Flutter/lib/kit/apm/vm/version.dart
Flutter/lib/kit/apm/vm/version.dart
+10
-10
Flutter/lib/kit/apm/vm/vm_helper.dart
Flutter/lib/kit/apm/vm/vm_helper.dart
+29
-24
Flutter/lib/kit/apm/vm/vm_service_wrapper.dart
Flutter/lib/kit/apm/vm/vm_service_wrapper.dart
+38
-33
Flutter/lib/kit/common/common.dart
Flutter/lib/kit/common/common.dart
+3
-4
Flutter/lib/kit/observer.dart
Flutter/lib/kit/observer.dart
+5
-5
Flutter/lib/kit/visual/color_pick.dart
Flutter/lib/kit/visual/color_pick.dart
+74
-59
Flutter/lib/kit/visual/visual.dart
Flutter/lib/kit/visual/visual.dart
+1
-1
Flutter/lib/util/byte_util.dart
Flutter/lib/util/byte_util.dart
+4
-1
Flutter/lib/widget/source_code/source_code_view.dart
Flutter/lib/widget/source_code/source_code_view.dart
+1
-1
未找到文件。
Flutter/lib/kit/apm/apm.dart
浏览文件 @
73a816e2
...
...
@@ -51,7 +51,7 @@ class ApmKitManager {
}
abstract
class
ApmKit
implements
IKit
{
IStorage
storage
;
late
IStorage
storage
;
void
start
();
...
...
@@ -68,7 +68,7 @@ abstract class ApmKit implements IKit {
@override
void
tabAction
()
{
ResidentPage
.
residentPageKey
.
currentState
.
setState
(()
{
ResidentPage
.
residentPageKey
.
currentState
?
.
setState
(()
{
ResidentPage
.
tag
=
getKitName
();
});
}
...
...
Flutter/lib/kit/apm/fps_kit.dart
浏览文件 @
73a816e2
...
...
@@ -9,11 +9,11 @@ import '../kit.dart';
import
'apm.dart'
;
class
FpsInfo
implements
IInfo
{
int
fps
;
String
pageName
;
int
?
fps
;
String
?
pageName
;
@override
int
getValue
()
{
int
?
getValue
()
{
return
fps
;
}
}
...
...
@@ -28,7 +28,7 @@ class FpsKit extends ApmKit {
@override
void
start
()
{
WidgetsBinding
.
instance
.
addTimingsCallback
((
timings
)
{
WidgetsBinding
.
instance
?
.
addTimingsCallback
((
timings
)
{
int
fps
=
0
;
timings
.
forEach
((
element
)
{
FrameTiming
frameTiming
=
element
;
...
...
@@ -75,8 +75,8 @@ class FpsPage extends StatefulWidget {
class
FpsPageState
extends
State
<
FpsPage
>
{
@override
Widget
build
(
BuildContext
context
)
{
FpsKit
kit
=
ApmKitManager
.
instance
.
getKit
<
FpsKit
>(
ApmKitName
.
KIT_FPS
);
List
<
IInfo
>
list
=
new
List
()
;
FpsKit
?
kit
=
ApmKitManager
.
instance
.
getKit
<
FpsKit
>(
ApmKitName
.
KIT_FPS
);
List
<
IInfo
>
list
=
[]
;
if
(
kit
!=
null
)
{
list
=
kit
.
storage
.
getAll
();
}
...
...
Flutter/lib/kit/apm/launch/model.dart
浏览文件 @
73a816e2
class
LaunchInfo
{
final
int
costTime
;
final
String
previousPage
;
final
String
newPage
;
final
String
?
previousPage
;
final
String
?
newPage
;
LaunchInfo
(
this
.
costTime
,
this
.
previousPage
,
this
.
newPage
);
}
\ No newline at end of file
Flutter/lib/kit/apm/launch/page_launch_kit.dart
浏览文件 @
73a816e2
...
...
@@ -15,7 +15,7 @@ class PageLaunchKit extends ApmKit {
return
TimeCounter
(
notifier
.
value
);
});
static
VoidCallback
callback
;
static
VoidCallback
?
callback
;
static
double
left
=
ScreenUtil
.
instance
.
screenWidth
/
2
;
static
double
top
=
ScreenUtil
.
instance
.
screenHeight
/
2
;
...
...
@@ -23,7 +23,9 @@ class PageLaunchKit extends ApmKit {
static
void
closeCounter
()
{
enabled
=
false
;
_open
=
false
;
notifier
.
removeListener
(
PageLaunchKit
.
callback
);
if
(
callback
!=
null
){
notifier
.
removeListener
(
PageLaunchKit
.
callback
!);
}
_overlayEntry
.
remove
();
}
...
...
@@ -98,8 +100,8 @@ class _PageLaunchPageState extends State<PageLaunchPage> {
PageLaunchKit
.
callback
=
()
{
PageLaunchKit
.
_overlayEntry
.
markNeedsBuild
();
};
notifier
.
addListener
(
PageLaunchKit
.
callback
);
doKitOverlayKey
.
currentState
.
insert
(
PageLaunchKit
.
_overlayEntry
);
notifier
.
addListener
(
PageLaunchKit
.
callback
!
);
doKitOverlayKey
.
currentState
?
.
insert
(
PageLaunchKit
.
_overlayEntry
);
}
}
...
...
Flutter/lib/kit/apm/launch/route_observer.dart
浏览文件 @
73a816e2
...
...
@@ -7,14 +7,14 @@ bool enabled = false;
class
LaunchObserver
extends
NavigatorObserver
{
@override
void
didPush
(
Route
route
,
Route
previousRoute
)
{
void
didPush
(
Route
route
,
Route
?
previousRoute
)
{
super
.
didPush
(
route
,
previousRoute
);
if
(
enabled
)
{
int
before
=
DateTime
.
now
().
millisecondsSinceEpoch
;
WidgetsBinding
.
instance
.
addPostFrameCallback
((
timeStamp
)
{
WidgetsBinding
.
instance
?
.
addPostFrameCallback
((
timeStamp
)
{
int
now
=
DateTime
.
now
().
millisecondsSinceEpoch
;
notifier
.
value
=
LaunchInfo
(
now
-
before
,
previousRoute
.
settings
.
name
,
route
.
settings
.
name
);
now
-
before
,
previousRoute
?
.
settings
.
name
,
route
.
settings
.
name
);
});
}
...
...
Flutter/lib/kit/apm/log_kit.dart
浏览文件 @
73a816e2
...
...
@@ -12,7 +12,7 @@ import '../kit.dart';
import
'apm.dart'
;
class
LogKit
extends
ApmKit
{
FlutterExceptionHandler
originOnError
;
FlutterExceptionHandler
?
originOnError
;
final
CommonStorage
_error
=
CommonStorage
();
...
...
@@ -39,7 +39,7 @@ class LogKit extends ApmKit {
}
@override
bool
save
(
IInfo
info
)
{
bool
save
(
IInfo
?
info
)
{
if
((
info
as
LogBean
).
type
==
LogBean
.
TYPE_ERROR
)
{
_error
.
save
(
info
);
}
...
...
@@ -64,9 +64,12 @@ class LogKit extends ApmKit {
void
_doKitOnError
(
FlutterErrorDetails
details
)
{
// 委托给runZone内的onError
Zone
.
current
.
handleUncaughtError
(
details
.
exception
,
details
.
stack
);
var
stack
=
details
.
stack
;
if
(
stack
!=
null
)
{
Zone
.
current
.
handleUncaughtError
(
details
.
exception
,
stack
);
}
if
(
originOnError
!=
null
)
{
originOnError
(
details
);
originOnError
?.
call
(
details
);
}
}
...
...
@@ -79,7 +82,7 @@ class LogManager {
static
final
LogManager
_instance
=
LogManager
.
_privateConstructor
();
Function
listener
;
Function
?
listener
;
void
registerListener
(
Function
listener
)
{
this
.
listener
=
listener
;
...
...
@@ -93,25 +96,25 @@ class LogManager {
return
_instance
;
}
List
<
IInfo
>
getLogs
()
{
List
<
IInfo
>
?
getLogs
()
{
return
ApmKitManager
.
instance
.
getKit
(
ApmKitName
.
KIT_LOG
)
?.
getStorage
()
?
.
getAll
();
.
getAll
();
}
List
<
IInfo
>
getErrors
()
{
List
<
IInfo
>
?
getErrors
()
{
return
ApmKitManager
.
instance
.
getKit
<
LogKit
>(
ApmKitName
.
KIT_LOG
)
?.
error
?
.
getAll
();
.
getAll
();
}
void
addLog
(
int
type
,
String
msg
)
{
if
(
ApmKitManager
.
instance
.
getKit
(
ApmKitName
.
KIT_LOG
)
!=
null
)
{
final
LogBean
log
=
LogBean
(
type
,
msg
);
final
LogKit
kit
=
ApmKitManager
.
instance
.
getKit
(
ApmKitName
.
KIT_LOG
);
kit
.
save
(
log
);
final
LogKit
?
kit
=
ApmKitManager
.
instance
.
getKit
(
ApmKitName
.
KIT_LOG
);
kit
?
.
save
(
log
);
if
(
type
!=
LogBean
.
TYPE_ERROR
||
LogPageState
.
_showError
)
{
listener
?.
call
(
log
);
}
...
...
@@ -137,8 +140,8 @@ class LogBean implements IInfo {
final
int
type
;
final
String
msg
;
int
timestamp
;
bool
expand
;
late
int
timestamp
;
late
bool
expand
;
@override
int
getValue
()
{
...
...
@@ -163,9 +166,9 @@ class LogPageState extends State<LogPage> {
return
Future
<
void
>.
value
();
}
// if there's a current frame,
if
(
SchedulerBinding
.
instance
.
schedulerPhase
!=
SchedulerPhase
.
idle
)
{
if
(
SchedulerBinding
.
instance
?
.
schedulerPhase
!=
SchedulerPhase
.
idle
)
{
// wait for the end of that frame.
await
SchedulerBinding
.
instance
.
endOfFrame
;
await
SchedulerBinding
.
instance
?
.
endOfFrame
;
if
(!
mounted
)
{
return
Future
<
void
>.
value
();
}
...
...
@@ -194,9 +197,9 @@ class LogPageState extends State<LogPage> {
@override
Widget
build
(
BuildContext
context
)
{
final
List
<
IInfo
>
items
=
LogPageState
.
_showError
?
LogManager
.
instance
.
getErrors
().
reversed
.
toList
()
:
LogManager
.
instance
.
getLogs
()
.
reversed
.
toList
()
;
final
List
<
IInfo
>
items
=
(
LogPageState
.
_showError
?
LogManager
.
instance
.
getErrors
()
?
.
reversed
.
toList
()
:
LogManager
.
instance
.
getLogs
()
?.
reversed
.
toList
())??[]
;
return
Column
(
children:
<
Widget
>[
Row
(
...
...
@@ -249,11 +252,11 @@ class LogPageState extends State<LogPage> {
setState
(()
{
ApmKitManager
.
instance
.
getKit
<
LogKit
>(
ApmKitName
.
KIT_LOG
)
.
getStorage
()
?
.
getStorage
()
.
clear
();
ApmKitManager
.
instance
.
getKit
<
LogKit
>(
ApmKitName
.
KIT_LOG
)
.
error
?
.
error
.
clear
();
});
},
...
...
@@ -306,10 +309,10 @@ class LogPageState extends State<LogPage> {
class
LogItemWidget
extends
StatefulWidget
{
const
LogItemWidget
(
{
Key
key
,
@
required
this
.
item
,
@
required
this
.
index
,
@
required
this
.
isLast
})
{
Key
?
key
,
required
this
.
item
,
required
this
.
index
,
required
this
.
isLast
})
:
super
(
key:
key
);
final
LogBean
item
;
...
...
Flutter/lib/kit/apm/memory_kit.dart
浏览文件 @
73a816e2
...
...
@@ -13,11 +13,11 @@ import 'apm.dart';
import
'vm/vm_helper.dart'
;
class
MemoryInfo
implements
IInfo
{
int
fps
;
String
pageName
;
int
?
fps
;
String
?
pageName
;
@override
int
getValue
()
{
int
?
getValue
()
{
return
fps
;
}
}
...
...
@@ -50,7 +50,7 @@ class MemoryKit extends ApmKit {
VmHelper
.
instance
.
updateMemoryUsage
();
}
AllocationProfile
getAllocationProfile
()
{
AllocationProfile
?
getAllocationProfile
()
{
return
VmHelper
.
instance
.
allocationProfile
;
}
...
...
@@ -78,23 +78,23 @@ class MemoryPage extends StatefulWidget {
}
class
MemoryPageState
extends
State
<
MemoryPage
>
{
MemoryKit
kit
=
MemoryKit
?
kit
=
ApmKitManager
.
instance
.
getKit
<
MemoryKit
>(
ApmKitName
.
KIT_MEMORY
);
List
<
ClassHeapStats
>
heaps
=
new
List
()
;
List
<
ClassHeapStats
>
heaps
=
[]
;
TextEditingController
editingController
=
TextEditingController
();
@override
void
initState
()
{
super
.
initState
();
kit
.
update
();
kit
?
.
update
();
initHeaps
();
}
void
initHeaps
()
{
if
(
kit
.
getAllocationProfile
()
!=
null
)
{
kit
.
getAllocationProfile
().
members
.
sort
(
(
left
,
right
)
=>
right
.
bytesCurrent
.
compareTo
(
left
.
bytesCurrent
)
);
kit
.
getAllocationProfile
().
members
.
forEach
((
element
)
{
if
(
kit
?
.
getAllocationProfile
()
!=
null
)
{
kit
!.
getAllocationProfile
()?.
members
?.
sort
((
left
,
right
)
=>
right
.
bytesCurrent
?.
compareTo
(
left
.
bytesCurrent
??
0
)
??
0
);
kit
?.
getAllocationProfile
()?.
members
?
.
forEach
((
element
)
{
if
(
heaps
.
length
<
32
)
{
heaps
.
add
(
element
);
}
...
...
@@ -181,9 +181,7 @@ class MemoryPageState extends State<MemoryPage> {
padding:
EdgeInsets
.
only
(
left:
15
,
right:
0
,
top:
15
,
bottom:
15
),
child:
Image
.
asset
(
'images/dk_memory_search.png'
,
package:
DK_PACKAGE_NAME
,
height:
16
,
width:
16
),
package:
DK_PACKAGE_NAME
,
height:
16
,
width:
16
),
onPressed:
filterAllocations
,
),
)
...
...
@@ -260,16 +258,17 @@ class MemoryPageState extends State<MemoryPage> {
String
className
=
editingController
.
text
;
assert
(
className
!=
null
);
heaps
.
clear
();
if
(
className
.
length
>=
3
&&
kit
.
getAllocationProfile
()
!=
null
)
{
kit
.
getAllocationProfile
().
members
.
forEach
((
element
)
{
if
(
element
.
classRef
.
name
.
toLowerCase
()
.
contains
(
className
.
toLowerCase
()))
{
if
(
className
.
length
>=
3
&&
kit
?.
getAllocationProfile
()
!=
null
)
{
kit
?.
getAllocationProfile
()?.
members
?.
forEach
((
element
)
{
if
(
element
.
classRef
?.
name
?.
toLowerCase
()
.
contains
(
className
.
toLowerCase
())
==
true
)
{
heaps
.
add
(
element
);
}
});
heaps
.
sort
(
(
left
,
right
)
=>
right
.
bytesCurrent
.
compareTo
(
left
.
bytesCurrent
)
);
heaps
.
sort
(
(
left
,
right
)
=>
right
.
bytesCurrent
?.
compareTo
(
left
.
bytesCurrent
??
0
)
??
0
);
}
setState
(()
{});
}
...
...
@@ -321,7 +320,7 @@ class HeapItemWidget extends StatelessWidget {
final
ClassHeapStats
item
;
final
int
index
;
HeapItemWidget
({
Key
key
,
@required
this
.
item
,
@
required
this
.
index
})
HeapItemWidget
({
Key
?
key
,
required
this
.
item
,
required
this
.
index
})
:
super
(
key:
key
);
@override
...
...
@@ -347,7 +346,7 @@ class HeapItemWidget extends StatelessWidget {
Container
(
width:
MediaQuery
.
of
(
context
).
size
.
width
-
193
,
alignment:
Alignment
.
center
,
child:
Text
(
'
${item.classRef.name}
'
,
child:
Text
(
'
${item.classRef
?
.name}
'
,
style:
TextStyle
(
color:
Color
(
0xff333333
),
fontSize:
12
))),
],
),
...
...
Flutter/lib/kit/apm/method_channel_kit.dart
浏览文件 @
73a816e2
...
...
@@ -55,7 +55,7 @@ class ChannelInfo implements IInfo {
}
class
MethodChannelKit
extends
ApmKit
{
Function
listener
;
Function
?
listener
;
@override
Widget
createDisplayPage
()
{
...
...
@@ -78,7 +78,7 @@ class MethodChannelKit extends ApmKit {
}
@override
bool
save
(
IInfo
info
)
{
bool
save
(
IInfo
?
info
)
{
if
(!
ChannelPageState
.
showSystemChannel
&&
((
info
as
ChannelInfo
).
type
==
ChannelInfo
.
TYPE_SYSTEM_RECEIVE
||
(
info
as
ChannelInfo
).
type
==
ChannelInfo
.
TYPE_SYSTEM_SEND
))
{
...
...
@@ -122,8 +122,8 @@ class ChannelPageState extends State<ChannelPage> {
Future
<
void
>
_listener
()
async
{
if
(!
mounted
)
return
;
if
(
SchedulerBinding
.
instance
.
schedulerPhase
!=
SchedulerPhase
.
idle
)
{
await
SchedulerBinding
.
instance
.
endOfFrame
;
if
(
SchedulerBinding
.
instance
?
.
schedulerPhase
!=
SchedulerPhase
.
idle
)
{
await
SchedulerBinding
.
instance
?
.
endOfFrame
;
if
(!
mounted
)
return
;
}
setState
(()
{
...
...
@@ -139,7 +139,7 @@ class ChannelPageState extends State<ChannelPage> {
super
.
initState
();
ApmKitManager
.
instance
.
getKit
<
MethodChannelKit
>(
ApmKitName
.
KIT_CHANNEL
)
.
registerListener
(
_listener
);
?
.
registerListener
(
_listener
);
}
@override
...
...
@@ -147,14 +147,14 @@ class ChannelPageState extends State<ChannelPage> {
super
.
dispose
();
ApmKitManager
.
instance
.
getKit
<
MethodChannelKit
>(
ApmKitName
.
KIT_CHANNEL
)
.
unregisterListener
();
?
.
unregisterListener
();
}
@override
Widget
build
(
BuildContext
context
)
{
List
<
IInfo
>
items
=
ApmKitManager
.
instance
List
<
IInfo
>
?
items
=
ApmKitManager
.
instance
.
getKit
<
MethodChannelKit
>(
ApmKitName
.
KIT_CHANNEL
)
.
getStorage
()
?
.
getStorage
()
.
getAll
()
.
reversed
.
where
((
element
)
=>
showSystemChannel
...
...
@@ -209,7 +209,7 @@ class ChannelPageState extends State<ChannelPage> {
this
.
setState
(()
{
ApmKitManager
.
instance
.
getKit
<
MethodChannelKit
>(
ApmKitName
.
KIT_CHANNEL
)
.
getStorage
()
?
.
getStorage
()
.
clear
();
});
},
...
...
@@ -256,20 +256,22 @@ class ChannelPageState extends State<ChannelPage> {
child:
Container
(
alignment:
Alignment
.
topCenter
,
color:
Color
(
0xfff5f6f7
),
child:
ListView
.
builder
(
controller:
_offsetController
,
itemCount:
items
.
length
,
padding:
EdgeInsets
.
only
(
left:
4
,
right:
4
,
bottom:
0
,
top:
0
),
reverse:
true
,
shrinkWrap:
true
,
itemBuilder:
(
context
,
index
)
{
return
ChannelItemWidget
(
item:
items
[
index
],
index:
index
,
isLast:
index
==
items
.
length
-
1
,
);
})),
child:
items
==
null
?
null
:
ListView
.
builder
(
controller:
_offsetController
,
itemCount:
items
.
length
,
padding:
EdgeInsets
.
only
(
left:
4
,
right:
4
,
bottom:
0
,
top:
0
),
reverse:
true
,
shrinkWrap:
true
,
itemBuilder:
(
context
,
index
)
{
return
ChannelItemWidget
(
item:
items
[
index
]
as
ChannelInfo
,
index:
index
,
isLast:
index
==
items
.
length
-
1
,
);
})),
)
],
);
...
...
@@ -282,10 +284,7 @@ class ChannelItemWidget extends StatefulWidget {
final
bool
isLast
;
ChannelItemWidget
(
{
Key
key
,
@required
this
.
item
,
@required
this
.
index
,
@required
this
.
isLast
})
{
Key
?
key
,
required
this
.
item
,
required
this
.
index
,
required
this
.
isLast
})
:
super
(
key:
key
);
@override
...
...
Flutter/lib/kit/apm/route_kit.dart
浏览文件 @
73a816e2
...
...
@@ -41,13 +41,13 @@ class RouteInfoPage extends StatefulWidget {
}
class
RouteInfoPageState
extends
State
<
RouteInfoPage
>
{
RouteInfo
route
;
RouteInfo
?
route
;
@override
void
initState
()
{
super
.
initState
();
WidgetsBinding
.
instance
.
addPostFrameCallback
((
Duration
timeStamp
)
{
final
RouteInfo
route
=
findRoute
();
WidgetsBinding
.
instance
?
.
addPostFrameCallback
((
Duration
timeStamp
)
{
final
RouteInfo
?
route
=
findRoute
();
if
(
route
!=
null
&&
(
route
.
current
!=
null
))
{
setState
(()
{
this
.
route
=
route
;
...
...
@@ -97,12 +97,12 @@ class RouteInfoPageState extends State<RouteInfoPage> {
List
<
Widget
>
buildRouteInfoWidget
()
{
final
List
<
Widget
>
widgets
=
<
Widget
>[];
RouteInfo
route
=
this
.
route
;
RouteInfo
?
route
=
this
.
route
;
if
(
route
==
null
)
{
return
widgets
;
}
do
{
if
(
route
.
current
!=
null
)
{
if
(
route
?
.
current
!=
null
)
{
widgets
.
add
(
Container
(
padding:
const
EdgeInsets
.
all
(
12
),
...
...
@@ -122,7 +122,7 @@ class RouteInfoPageState extends State<RouteInfoPage> {
height:
1.5
,
fontWeight:
FontWeight
.
bold
)),
TextSpan
(
text:
route
.
current
.
settings
.
name
,
text:
route
?.
current
?
.
settings
.
name
,
style:
const
TextStyle
(
fontSize:
10
,
height:
1.5
,
color:
Color
(
0xff666666
))),
const
TextSpan
(
...
...
@@ -133,7 +133,7 @@ class RouteInfoPageState extends State<RouteInfoPage> {
color:
Color
(
0xff333333
),
fontWeight:
FontWeight
.
bold
)),
TextSpan
(
text:
'
${route
.current
.settings.arguments}
'
,
text:
'
${route
?.current?
.settings.arguments}
'
,
style:
const
TextStyle
(
fontSize:
10
,
height:
1.5
,
color:
Color
(
0xff666666
))),
const
TextSpan
(
...
...
@@ -144,8 +144,8 @@ class RouteInfoPageState extends State<RouteInfoPage> {
color:
Color
(
0xff333333
),
fontWeight:
FontWeight
.
bold
)),
TextSpan
(
text:
route
.
parentNavigator
!=
null
?
route
.
parentNavigator
.
toString
()
text:
route
?
.
parentNavigator
!=
null
?
route
?
.
parentNavigator
.
toString
()
:
'未知'
,
style:
const
TextStyle
(
fontSize:
10
,
height:
1.5
,
color:
Color
(
0xff666666
))),
...
...
@@ -157,7 +157,7 @@ class RouteInfoPageState extends State<RouteInfoPage> {
color:
Color
(
0xff333333
),
fontWeight:
FontWeight
.
bold
)),
TextSpan
(
text:
route
.
current
.
toString
(),
text:
route
?
.
current
.
toString
(),
style:
const
TextStyle
(
fontSize:
10
,
height:
1.5
,
color:
Color
(
0xff666666
))),
],
...
...
@@ -166,7 +166,7 @@ class RouteInfoPageState extends State<RouteInfoPage> {
),
);
}
route
=
route
.
parent
;
route
=
route
?
.
parent
;
if
(
route
!=
null
&&
route
.
parent
!=
null
)
{
widgets
.
add
(
Container
(
...
...
@@ -182,15 +182,16 @@ class RouteInfoPageState extends State<RouteInfoPage> {
return
widgets
;
}
RouteInfo
findRoute
()
{
Element
topElement
;
final
ModalRoute
<
dynamic
>
rootRoute
=
ModalRoute
.
of
(
DoKitApp
.
appKey
.
currentContext
);
RouteInfo
?
findRoute
()
{
Element
?
topElement
;
var
context
=
DoKitApp
.
appKey
.
currentContext
;
if
(
context
==
null
)
return
null
;
final
ModalRoute
<
dynamic
>?
rootRoute
=
ModalRoute
.
of
(
context
);
void
listTopView
(
Element
element
)
{
if
(
element
.
widget
is
!
PositionedDirectional
)
{
if
(
element
is
RenderObjectElement
&&
element
.
renderObject
is
RenderBox
)
{
final
ModalRoute
<
dynamic
>
route
=
ModalRoute
.
of
(
element
);
final
ModalRoute
<
dynamic
>
?
route
=
ModalRoute
.
of
(
element
);
if
(
route
!=
null
&&
route
!=
rootRoute
)
{
topElement
=
element
;
}
...
...
@@ -199,11 +200,11 @@ class RouteInfoPageState extends State<RouteInfoPage> {
}
}
DoKitApp
.
appKey
.
currentC
ontext
.
visitChildElements
(
listTopView
);
c
ontext
.
visitChildElements
(
listTopView
);
if
(
topElement
!=
null
)
{
final
RouteInfo
routeInfo
=
RouteInfo
();
routeInfo
.
current
=
ModalRoute
.
of
(
topElement
);
buildNavigatorTree
(
topElement
,
routeInfo
);
routeInfo
.
current
=
ModalRoute
.
of
(
topElement
!
);
buildNavigatorTree
(
topElement
!
,
routeInfo
);
return
routeInfo
;
}
return
null
;
...
...
@@ -211,7 +212,7 @@ class RouteInfoPageState extends State<RouteInfoPage> {
/// 反向遍历生成路由树
void
buildNavigatorTree
(
Element
element
,
RouteInfo
routeInfo
)
{
final
NavigatorState
navigatorState
=
final
NavigatorState
?
navigatorState
=
element
.
findAncestorStateOfType
<
NavigatorState
>();
if
(
navigatorState
!=
null
&&
navigatorState
.
context
!=
null
)
{
...
...
@@ -225,9 +226,9 @@ class RouteInfoPageState extends State<RouteInfoPage> {
}
class
RouteInfo
extends
IInfo
{
ModalRoute
<
dynamic
>
current
;
Widget
parentNavigator
;
RouteInfo
parent
;
ModalRoute
<
dynamic
>
?
current
;
Widget
?
parentNavigator
;
RouteInfo
?
parent
;
@override
int
getValue
()
{
...
...
Flutter/lib/kit/apm/source_code_kit.dart
浏览文件 @
73a816e2
...
...
@@ -41,16 +41,16 @@ class SourceCodePage extends StatefulWidget {
}
class
_SourceCodePageState
extends
State
<
SourceCodePage
>
{
String
sourceCode
;
String
?
sourceCode
;
@override
void
initState
()
{
super
.
initState
();
WidgetsBinding
.
instance
.
addPostFrameCallback
((
timeStamp
)
{
WidgetsBinding
.
instance
?
.
addPostFrameCallback
((
timeStamp
)
{
var
renderObject
=
findTopRenderObject
();
WidgetInspectorService
.
instance
.
selection
.
current
=
renderObject
;
final
String
nodeDesc
=
WidgetInspectorService
.
instance
.
getSelectedSummaryWidget
(
null
,
null
);
WidgetInspectorService
.
instance
.
getSelectedSummaryWidget
(
''
,
''
);
if
(
nodeDesc
!=
null
)
{
final
Map
<
String
,
dynamic
>
map
=
json
.
decode
(
nodeDesc
)
as
Map
<
String
,
dynamic
>;
...
...
@@ -62,7 +62,7 @@ class _SourceCodePageState extends State<SourceCodePage> {
final
fileName
=
fileLocation
.
split
(
"/"
).
last
;
getScriptList
(
fileName
).
then
((
value
)
=>
{
setState
(()
{
sourceCode
=
value
.
source
;
sourceCode
=
value
!
.
source
;
})
});
}
...
...
@@ -71,15 +71,18 @@ class _SourceCodePageState extends State<SourceCodePage> {
});
}
RenderObject
findTopRenderObject
()
{
Element
topElement
;
final
ModalRoute
<
dynamic
>
rootRoute
=
ModalRoute
.
of
(
DoKitApp
.
appKey
.
currentContext
);
RenderObject
?
findTopRenderObject
()
{
Element
?
topElement
;
var
context
=
DoKitApp
.
appKey
.
currentContext
;
if
(
context
==
null
)
{
return
null
;
}
final
ModalRoute
<
dynamic
>?
rootRoute
=
ModalRoute
.
of
(
context
);
void
listTopView
(
Element
element
)
{
if
(
element
.
widget
is
!
PositionedDirectional
)
{
if
(
element
is
RenderObjectElement
&&
element
.
renderObject
is
RenderBox
)
{
final
ModalRoute
<
dynamic
>
route
=
ModalRoute
.
of
(
element
);
final
ModalRoute
<
dynamic
>
?
route
=
ModalRoute
.
of
(
element
);
if
(
route
!=
null
&&
route
!=
rootRoute
)
{
topElement
=
element
;
}
...
...
@@ -88,9 +91,9 @@ class _SourceCodePageState extends State<SourceCodePage> {
}
}
DoKitApp
.
appKey
.
currentC
ontext
.
visitChildElements
(
listTopView
);
c
ontext
.
visitChildElements
(
listTopView
);
if
(
topElement
!=
null
)
{
return
topElement
.
renderObject
;
return
topElement
!
.
renderObject
;
}
return
null
;
}
...
...
@@ -105,7 +108,7 @@ class _SourceCodePageState extends State<SourceCodePage> {
)
:
Padding
(
padding:
const
EdgeInsets
.
all
(
8.0
),
child:
SourceCodeView
(
sourceCode:
sourceCode
),
child:
SourceCodeView
(
sourceCode:
sourceCode
??
''
),
),
);
}
...
...
Flutter/lib/kit/apm/vm/version.dart
浏览文件 @
73a816e2
...
...
@@ -2,13 +2,13 @@ import 'package:flutter/material.dart';
class
FlutterVersion
extends
SemanticVersion
{
FlutterVersion
.
_
({
@
required
this
.
version
,
@
required
this
.
channel
,
@
required
this
.
repositoryUrl
,
@
required
this
.
frameworkRevision
,
@
required
this
.
frameworkCommitDate
,
@
required
this
.
engineRevision
,
@
required
this
.
dartSdkVersion
,
required
this
.
version
,
required
this
.
channel
,
required
this
.
repositoryUrl
,
required
this
.
frameworkRevision
,
required
this
.
frameworkCommitDate
,
required
this
.
engineRevision
,
required
this
.
dartSdkVersion
,
})
{
// Flutter versions can come in as '1.10.7-pre.42', so we strip out any
// characters that are not digits. We do not currently have a need to know
...
...
@@ -24,9 +24,9 @@ class FlutterVersion extends SemanticVersion {
patch
=
_versionParts
.
length
>
2
?
int
.
tryParse
(
_versionParts
[
2
])
??
0
:
0
;
}
factory
FlutterVersion
.
parse
(
Map
<
String
,
dynamic
>
json
)
{
factory
FlutterVersion
.
parse
(
Map
<
String
,
dynamic
>
?
json
)
{
if
(
json
==
null
)
{
return
null
;
json
={}
;
}
return
FlutterVersion
.
_
(
version:
json
[
'frameworkVersion'
]
as
String
,
...
...
@@ -97,7 +97,7 @@ class SemanticVersion implements Comparable<SemanticVersion> {
int
patch
;
bool
isSupported
({
@
required
SemanticVersion
supportedVersion
})
=>
bool
isSupported
({
required
SemanticVersion
supportedVersion
})
=>
compareTo
(
supportedVersion
)
>=
0
;
@override
...
...
Flutter/lib/kit/apm/vm/vm_helper.dart
浏览文件 @
73a816e2
...
...
@@ -15,13 +15,13 @@ class VmHelper {
// 各Isolate内存使用情况
Map
<
IsolateRef
,
MemoryUsage
>
memoryInfo
=
new
Map
();
AllocationProfile
allocationProfile
;
PackageInfo
packageInfo
;
AllocationProfile
?
allocationProfile
;
PackageInfo
?
packageInfo
;
// flutter版本
String
_flutterVersion
=
''
;
VM
get
vm
=>
VMServiceWrapper
.
instance
.
vm
;
VM
?
get
vm
=>
VMServiceWrapper
.
instance
.
vm
;
Future
<
void
>
resolveVMInfo
()
async
{
if
(!
VMServiceWrapper
.
instance
.
connected
)
{
...
...
@@ -45,53 +45,58 @@ class VmHelper {
}
updateMemoryUsage
()
{
if
(!
VMServiceWrapper
.
instance
.
connected
)
{
var
mainId
=
VMServiceWrapper
.
instance
.
main
?.
id
;
if
(!
VMServiceWrapper
.
instance
.
connected
||
mainId
==
null
)
{
return
;
}
VMServiceWrapper
.
instance
.
service
.
getMemoryUsage
(
VMServiceWrapper
.
instance
.
main
.
i
d
)
.
then
((
value
)
=>
memoryInfo
[
VMServiceWrapper
.
instance
.
main
]
=
value
);
?.
getMemoryUsage
(
mainI
d
)
.
then
((
value
)
=>
memoryInfo
[
VMServiceWrapper
.
instance
.
main
!
]
=
value
);
}
updateFlutterVersion
()
{
if
(!
VMServiceWrapper
.
instance
.
connected
)
{
return
;
}
VMServiceWrapper
.
instance
.
callExtensionService
(
'flutterVersion'
)?.
then
(
(
value
)
=>
_flutterVersion
=
FlutterVersion
.
parse
(
value
?.
json
)?.
version
);
VMServiceWrapper
.
instance
.
callExtensionService
(
'flutterVersion'
).
then
(
(
value
)
=>
_flutterVersion
=
FlutterVersion
.
parse
(
value
.
json
).
version
);
}
updateAllocationProfile
()
{
if
(!
VMServiceWrapper
.
instance
.
connected
)
{
var
mainId
=
VMServiceWrapper
.
instance
.
main
?.
id
;
if
(!
VMServiceWrapper
.
instance
.
connected
||
mainId
==
null
)
{
return
;
}
VMServiceWrapper
.
instance
.
service
.
getAllocationProfile
(
VMServiceWrapper
.
instance
.
main
.
i
d
)
?.
getAllocationProfile
(
mainI
d
)
.
then
((
value
)
=>
allocationProfile
=
value
);
}
testPrintScript
()
async
{
Script
script
=
await
compute
(
getScriptList
,
'main.dart'
);
// Script
script = await getScriptList('main.dart');
print
(
script
?.
source
);
//
Script script = await compute(getScriptList, 'main.dart');
Script
?
script
=
await
getScriptList
(
'main.dart'
);
print
(
script
?.
source
??
"null"
);
}
}
Future
<
Script
>
getScriptList
(
String
fileName
)
async
{
Future
<
Script
?
>
getScriptList
(
String
fileName
)
async
{
if
(!
VMServiceWrapper
.
instance
.
connected
)
{
await
VMServiceWrapper
.
instance
.
connect
();
}
if
(
VMServiceWrapper
.
instance
.
service
!=
null
&&
VMServiceWrapper
.
instance
.
connected
)
{
var
mainId
=
VMServiceWrapper
.
instance
.
main
?.
id
;
if
(
VMServiceWrapper
.
instance
.
connected
&&
mainId
!=
null
)
{
return
VMServiceWrapper
.
instance
.
service
.
getScripts
(
VMServiceWrapper
.
instance
.
main
.
id
)
.
then
<
Script
>((
scriptList
)
async
=>
await
VMServiceWrapper
.
instance
.
service
.
getObject
(
VMServiceWrapper
.
instance
.
main
.
id
,
scriptList
?.
scripts
?.
firstWhere
((
element
)
=>
element
.
id
.
contains
(
fileName
))
?.
id
)
as
Script
);
?.
getScripts
(
mainId
)
.
then
<
Script
>((
scriptList
)
async
{
String
?
id
=
scriptList
.
scripts
?.
firstWhere
((
element
)
=>
element
.
id
?.
contains
(
fileName
)
==
true
)
.
id
;
if
(
id
==
null
)
{
return
Future
.
value
(
null
);
}
return
await
VMServiceWrapper
.
instance
.
service
?.
getObject
(
mainId
,
id
)
as
Script
;
});
}
return
null
;
...
...
Flutter/lib/kit/apm/vm/vm_service_wrapper.dart
浏览文件 @
73a816e2
...
...
@@ -14,13 +14,13 @@ class VMServiceWrapper {
static
VMServiceWrapper
get
instance
=>
_instance
;
VmService
service
;
VmService
?
service
;
IsolateRef
main
;
IsolateRef
?
main
;
VM
vm
;
VM
?
vm
;
ExtensionService
_extensionService
;
ExtensionService
?
_extensionService
;
bool
connected
=
false
;
Future
<
VmService
>
getService
(
info
)
async
{
...
...
@@ -36,33 +36,34 @@ class VMServiceWrapper {
}
service
=
await
getService
(
info
);
print
(
'socket connected in service
$info
'
);
vm
=
await
service
.
getVM
();
List
<
IsolateRef
>
isolates
=
vm
.
isolates
;
main
=
isolates
.
firstWhere
((
ref
)
=>
ref
.
name
.
contains
(
'main'
)
);
main
??=
isolates
.
first
;
vm
=
await
service
?
.
getVM
();
List
<
IsolateRef
>
?
isolates
=
vm
?
.
isolates
;
main
=
isolates
?.
firstWhere
((
ref
)
=>
ref
.
name
?.
contains
(
'main'
)
==
true
);
main
??=
isolates
?
.
first
;
connected
=
true
;
}
Future
<
Response
>
callExtensionService
(
String
method
)
async
{
if
(
_extensionService
==
null
)
{
_extensionService
=
new
ExtensionService
(
service
,
main
);
await
_extensionService
.
loadExtensionService
();
if
(
_extensionService
==
null
&&
service
!=
null
&&
main
!=
null
)
{
_extensionService
=
new
ExtensionService
(
service
!,
main
!
);
await
_extensionService
?
.
loadExtensionService
();
}
return
_extensionService
.
callMethod
(
method
);
return
_extensionService
!
.
callMethod
(
method
);
}
gc
()
{
if
(
connected
)
{
service
.
getAllocationProfile
(
main
.
id
,
gc:
true
);
var
isolateId
=
main
?.
id
;
if
(
connected
&&
isolateId
!=
null
)
{
service
?.
getAllocationProfile
(
isolateId
,
gc:
true
);
}
}
disConnect
()
async
{
if
(
service
!=
null
)
{
print
(
'waiting for client to shut down...'
);
service
.
dispose
();
service
?
.
dispose
();
await
service
.
onDone
;
await
service
?
.
onDone
;
connected
=
false
;
service
=
null
;
print
(
'service client shut down'
);
...
...
@@ -73,8 +74,8 @@ class VMServiceWrapper {
class
ExtensionService
{
final
VmService
serviceClient
;
final
IsolateRef
main
;
Version
_protocolVersion
;
Version
_dartIoVersion
;
Version
?
_protocolVersion
;
Version
?
_dartIoVersion
;
Map
<
String
,
List
<
String
>>
get
registeredMethodsForService
=>
_registeredMethodsForService
;
...
...
@@ -115,38 +116,41 @@ class ExtensionService {
:
'_Service'
;
Future
<
bool
>
isProtocolVersionSupported
({
@
required
SemanticVersion
supportedVersion
,
required
SemanticVersion
supportedVersion
,
})
async
{
_protocolVersion
??=
await
serviceClient
.
getVersion
();
return
isProtocolVersionSupportedNow
(
supportedVersion:
supportedVersion
);
}
bool
isProtocolVersionSupportedNow
({
@
required
SemanticVersion
supportedVersion
,
required
SemanticVersion
supportedVersion
,
})
{
if
(
_protocolVersion
==
null
)
{
return
false
;
}
return
_versionSupported
(
version:
_protocolVersion
,
version:
_protocolVersion
!
,
supportedVersion:
supportedVersion
,
);
}
bool
_versionSupported
({
@
required
Version
version
,
@
required
SemanticVersion
supportedVersion
,
required
Version
version
,
required
SemanticVersion
supportedVersion
,
})
{
return
SemanticVersion
(
major:
version
.
major
,
minor:
version
.
minor
,
major:
version
.
major
??
0
,
minor:
version
.
minor
??
0
,
).
isSupported
(
supportedVersion:
supportedVersion
);
}
Future
<
bool
>
isDartIoVersionSupported
({
@
required
SemanticVersion
supportedVersion
,
@
required
String
isolateId
,
required
SemanticVersion
supportedVersion
,
required
String
isolateId
,
})
async
{
_dartIoVersion
??=
await
getDartIOVersion
(
isolateId
);
return
_versionSupported
(
version:
_dartIoVersion
,
version:
_dartIoVersion
!
,
supportedVersion:
supportedVersion
,
);
}
...
...
@@ -155,11 +159,11 @@ class ExtensionService {
serviceClient
.
getDartIOVersion
(
isolateId
);
void
handleServiceEvent
(
Event
e
)
{
if
(
e
.
kind
==
EventKind
.
kServiceRegistered
)
{
final
serviceName
=
e
.
service
;
if
(
e
.
kind
==
EventKind
.
kServiceRegistered
&&
e
.
method
!=
null
)
{
final
serviceName
=
e
.
service
??
''
;
_registeredMethodsForService
.
putIfAbsent
(
serviceName
,
()
=>
[])
.
add
(
e
.
method
);
.
add
(
e
.
method
!
);
}
if
(
e
.
kind
==
EventKind
.
kServiceUnregistered
)
{
...
...
@@ -170,10 +174,11 @@ class ExtensionService {
Future
<
Response
>
callMethod
(
String
method
)
{
if
(
registeredMethodsForService
.
containsKey
(
method
))
{
return
(
serviceClient
.
callMethod
(
registeredMethodsForService
[
method
].
last
,
return
(
serviceClient
.
callMethod
(
registeredMethodsForService
[
method
]!.
last
,
isolateId:
main
.
id
));
}
return
null
;
return
Future
.
value
(
null
)
;
}
}
...
...
Flutter/lib/kit/common/common.dart
浏览文件 @
73a816e2
...
...
@@ -8,7 +8,7 @@ import 'basic_info.dart';
abstract
class
CommonKit
implements
IKit
{
@override
void
tabAction
()
{
ResidentPage
.
residentPageKey
.
currentState
.
setState
(()
{
ResidentPage
.
residentPageKey
.
currentState
?
.
setState
(()
{
ResidentPage
.
tag
=
getKitName
();
});
}
...
...
@@ -33,10 +33,9 @@ class CommonKitManager {
kitMap
[
tag
]
=
kit
;
}
T
getKit
<
T
extends
CommonKit
>(
String
name
)
{
assert
(
name
!=
null
);
T
?
getKit
<
T
extends
CommonKit
?>(
String
name
)
{
if
(
kitMap
.
containsKey
(
name
))
{
return
kitMap
[
name
];
return
kitMap
[
name
]
as
T
;
}
return
null
;
}
...
...
Flutter/lib/kit/observer.dart
浏览文件 @
73a816e2
...
...
@@ -8,7 +8,7 @@ class DokitNavigatorObserver extends NavigatorObserver {
@override
void
didPush
(
Route
route
,
Route
previousRoute
)
{
void
didPush
(
Route
route
,
Route
?
previousRoute
)
{
super
.
didPush
(
route
,
previousRoute
);
_observers
.
forEach
((
element
)
{
element
.
didPush
(
route
,
previousRoute
);
...
...
@@ -16,7 +16,7 @@ class DokitNavigatorObserver extends NavigatorObserver {
}
@override
void
didPop
(
Route
route
,
Route
previousRoute
)
{
void
didPop
(
Route
route
,
Route
?
previousRoute
)
{
super
.
didPop
(
route
,
previousRoute
);
_observers
.
forEach
((
element
)
{
element
.
didPop
(
route
,
previousRoute
);
...
...
@@ -24,7 +24,7 @@ class DokitNavigatorObserver extends NavigatorObserver {
}
@override
void
didRemove
(
Route
route
,
Route
previousRoute
)
{
void
didRemove
(
Route
route
,
Route
?
previousRoute
)
{
super
.
didRemove
(
route
,
previousRoute
);
_observers
.
forEach
((
element
)
{
element
.
didRemove
(
route
,
previousRoute
);
...
...
@@ -32,7 +32,7 @@ class DokitNavigatorObserver extends NavigatorObserver {
}
@override
void
didReplace
({
Route
newRoute
,
Route
oldRoute
})
{
void
didReplace
({
Route
?
newRoute
,
Route
?
oldRoute
})
{
super
.
didReplace
(
newRoute:
newRoute
,
oldRoute:
oldRoute
);
_observers
.
forEach
((
element
)
{
element
.
didReplace
(
newRoute:
newRoute
,
oldRoute:
oldRoute
);
...
...
@@ -40,7 +40,7 @@ class DokitNavigatorObserver extends NavigatorObserver {
}
@override
void
didStartUserGesture
(
Route
route
,
Route
previousRoute
)
{
void
didStartUserGesture
(
Route
route
,
Route
?
previousRoute
)
{
super
.
didStartUserGesture
(
route
,
previousRoute
);
_observers
.
forEach
((
element
)
{
element
.
didStartUserGesture
(
route
,
previousRoute
);
...
...
Flutter/lib/kit/visual/color_pick.dart
浏览文件 @
73a816e2
...
...
@@ -17,37 +17,40 @@ class ColorPickerKit extends VisualKit {
_initPosition
=
ScreenUtil
.
instance
.
screenCenter
-
Offset
(
diameter
/
2
,
diameter
/
2
);
_position
=
ValueNotifier
<
Offset
>(
initPosition
);
_focusEntry
=
OverlayEntry
(
builder:
(
BuildContext
context
)
{
return
ColorPickerWidget
();
});
_infoEntry
=
OverlayEntry
(
builder:
(
BuildContext
context
)
{
return
ColorPickerInfoWidget
();
});
isShown
=
false
;
}
static
final
ColorPickerKit
_instance
=
ColorPickerKit
.
_privateConstructor
();
static
ColorPickerKit
get
instance
=>
_instance
;
bool
isShown
;
bool
isShown
=
false
;
// 选中的颜色
final
ValueNotifier
<
Color
>
color
=
ValueNotifier
<
Color
>(
Colors
.
white
);
// 当前屏幕的截图快照
final
ValueNotifier
<
ui
.
Image
>
snapshot
=
ValueNotifier
<
ui
.
Image
>(
null
);
final
ValueNotifier
<
ui
.
Image
?>
snapshot
=
ValueNotifier
<
ui
.
Image
?
>(
null
);
// 放大镜当前位置(左上角)
ValueNotifier
<
Offset
>
_position
;
late
ValueNotifier
<
Offset
>
_position
;
ValueNotifier
<
Offset
>
get
position
=>
_position
;
// 放大镜的直径
final
double
diameter
=
170
;
// 像素点放大的倍数
final
double
scale
=
8
;
Offset
_initPosition
;
late
Offset
_initPosition
;
Offset
get
initPosition
=>
_initPosition
;
OverlayEntry
_focusEntry
;
OverlayEntry
_infoEntry
;
OverlayEntry
_focusEntry
=
OverlayEntry
(
builder:
(
BuildContext
context
)
{
return
ColorPickerWidget
();
});
OverlayEntry
_infoEntry
=
OverlayEntry
(
builder:
(
BuildContext
context
)
{
return
ColorPickerInfoWidget
();
});
@override
String
getIcon
()
{
...
...
@@ -61,22 +64,22 @@ class ColorPickerKit extends VisualKit {
@override
void
tabAction
()
{
final
DoKitBtnState
state
=
DoKitBtn
.
doKitBtnKey
.
currentState
;
state
.
closeDebugPage
();
show
(
DoKitBtn
.
doKitBtnKey
.
currentContext
,
state
.
owner
);
final
DoKitBtnState
?
state
=
DoKitBtn
.
doKitBtnKey
.
currentState
;
state
?
.
closeDebugPage
();
show
(
DoKitBtn
.
doKitBtnKey
.
currentContext
,
state
?
.
owner
);
}
static
void
show
(
BuildContext
context
,
OverlayEntry
entrance
)
{
static
void
show
(
BuildContext
?
context
,
OverlayEntry
?
entrance
)
{
_instance
.
_show
(
context
,
entrance
);
}
void
_show
(
BuildContext
context
,
OverlayEntry
entrance
)
{
void
_show
(
BuildContext
?
context
,
OverlayEntry
?
entrance
)
{
if
(
isShown
)
{
return
;
}
isShown
=
true
;
doKitOverlayKey
.
currentState
.
insert
(
_focusEntry
,
below:
entrance
);
doKitOverlayKey
.
currentState
.
insert
(
_infoEntry
,
below:
_focusEntry
);
doKitOverlayKey
.
currentState
?
.
insert
(
_focusEntry
,
below:
entrance
);
doKitOverlayKey
.
currentState
?
.
insert
(
_infoEntry
,
below:
_focusEntry
);
}
static
bool
hide
(
BuildContext
context
)
{
...
...
@@ -101,10 +104,11 @@ class ColorPickerWidget extends StatefulWidget {
class
ColorPickerWidgetState
extends
State
<
ColorPickerWidget
>
{
// 当前页面的截图快照
images
.
Image
_image
;
Future
<
images
.
Image
>
get
image
async
{
images
.
Image
?
_image
;
Future
<
images
.
Image
?>
get
image
async
{
if
(
_image
!=
null
)
{
return
_image
;
return
_image
!
;
}
await
_updateImage
();
...
...
@@ -114,15 +118,16 @@ class ColorPickerWidgetState extends State<ColorPickerWidget> {
// 是否做好显示颜色拾取器的准备
bool
_ready
=
false
;
Uint8List
_imageUint8List
;
Future
<
Uint8List
>
get
imageUint8List
async
{
Uint8List
?
_imageUint8List
;
Future
<
Uint8List
?>
get
imageUint8List
async
{
if
(
_imageUint8List
!=
null
)
{
return
_imageUint8List
;
return
_imageUint8List
!
;
}
final
RenderRepaintBoundary
boundary
=
final
RenderRepaintBoundary
?
boundary
=
_findCurrentPageRepaintBoundaryRenderObject
();
final
Uint8List
imageData
=
await
_boundaryToImageUint8List
(
boundary
);
final
Uint8List
?
imageData
=
await
_boundaryToImageUint8List
(
boundary
);
_imageUint8List
=
imageData
;
return
_imageUint8List
;
...
...
@@ -130,17 +135,20 @@ class ColorPickerWidgetState extends State<ColorPickerWidget> {
// 放大镜左上角的位置
Offset
get
position
=>
ColorPickerKit
.
instance
.
position
.
value
;
set
position
(
Offset
point
)
=>
ColorPickerKit
.
instance
.
position
.
value
=
point
;
// 手指和屏幕接触的初始位置
Offset
_touchPoint
;
Offset
?
_touchPoint
;
// 手指和屏幕接触时,放大镜左上角的位置
Offset
_lastPosition
=
ColorPickerKit
.
instance
.
position
.
value
;
Offset
get
deltaOffset
{
if
(
_touchPoint
==
null
||
_lastPosition
==
null
)
{
if
(
_touchPoint
==
null
)
{
return
Offset
.
zero
;
}
return
_touchPoint
-
_lastPosition
;
return
_touchPoint
!
-
_lastPosition
;
}
// 放大镜的半径
...
...
@@ -149,7 +157,7 @@ class ColorPickerWidgetState extends State<ColorPickerWidget> {
@override
initState
()
{
super
.
initState
();
WidgetsBinding
.
instance
.
addPostFrameCallback
((
_
)
{
WidgetsBinding
.
instance
?
.
addPostFrameCallback
((
_
)
{
// 第一次内部会调用_updateImage方法
_updateColor
();
});
...
...
@@ -169,7 +177,7 @@ class ColorPickerWidgetState extends State<ColorPickerWidget> {
position
=
event
.
position
-
deltaOffset
;
_updateColor
();
},
child:
Draggable
<
dynamic
>(
child:
Draggable
<
Object
>(
child:
_buildMagnifier
(
context
),
feedback:
_buildMagnifier
(
context
),
childWhenDragging:
Container
(),
...
...
@@ -225,11 +233,11 @@ class ColorPickerWidgetState extends State<ColorPickerWidget> {
children:
[
ValueListenableBuilder
<
Offset
>(
valueListenable:
ColorPickerKit
.
instance
.
position
,
builder:
(
BuildContext
context
,
Offset
value
,
Widget
child
)
{
return
ValueListenableBuilder
<
ui
.
Image
>(
builder:
(
BuildContext
context
,
Offset
value
,
Widget
?
child
)
{
return
ValueListenableBuilder
<
ui
.
Image
?
>(
valueListenable:
ColorPickerKit
.
instance
.
snapshot
,
builder:
(
BuildContext
context
,
ui
.
Image
value
,
Widget
child
)
{
(
BuildContext
context
,
ui
.
Image
?
value
,
Widget
?
child
)
{
return
CustomPaint
(
painter:
GridsPainter
(),
size:
Size
.
fromRadius
(
_radius
),
...
...
@@ -271,18 +279,21 @@ class ColorPickerWidgetState extends State<ColorPickerWidget> {
Future
<
void
>
_updateColor
()
async
{
final
double
dpr
=
ui
.
window
.
devicePixelRatio
;
final
center
=
(
position
+
Offset
(
_radius
,
_radius
))
*
dpr
;
final
images
.
Image
image
=
await
this
.
image
;
final
abgrPixel
=
image
.
getPixelSafe
(
center
.
dx
.
toInt
(),
center
.
dy
.
toInt
());
final
int
argbPixel
=
_abgrToArgb
(
abgrPixel
);
ColorPickerKit
.
instance
.
color
.
value
=
Color
(
argbPixel
);
final
images
.
Image
?
image
=
await
this
.
image
;
if
(
image
!=
null
)
{
final
abgrPixel
=
image
.
getPixelSafe
(
center
.
dx
.
toInt
(),
center
.
dy
.
toInt
());
final
int
argbPixel
=
_abgrToArgb
(
abgrPixel
);
ColorPickerKit
.
instance
.
color
.
value
=
Color
(
argbPixel
);
}
}
RenderRepaintBoundary
_findCurrentPageRepaintBoundaryRenderObject
()
{
RenderRepaintBoundary
?
_findCurrentPageRepaintBoundaryRenderObject
()
{
final
owner
=
context
.
findRenderObject
()?.
owner
;
assert
(
owner
!=
null
,
'当前正在build,无法获取当前页面的RepaintBoundary!'
);
bool
isRepaintBoundaryTo_ModalScopeStatus
(
String
desc
)
{
if
(
desc
?.
isEmpty
??
true
)
{
bool
isRepaintBoundaryTo_ModalScopeStatus
(
String
?
desc
)
{
if
(
desc
==
null
||
desc
.
isEmpty
)
{
return
false
;
}
final
creators
=
desc
.
split
(
' ← '
);
...
...
@@ -309,20 +320,20 @@ class ColorPickerWidgetState extends State<ColorPickerWidget> {
return
true
;
}
final
ModalRoute
<
dynamic
>
rootRoute
=
ModalRoute
.
of
<
dynamic
>(
DoKitApp
.
appKey
.
currentContext
);
final
ModalRoute
<
dynamic
>
?
rootRoute
=
ModalRoute
.
of
<
dynamic
>(
DoKitApp
.
appKey
.
currentContext
!
);
// 当前页面的_ModalScopeStatus下的RepaintBoundary的RenderObject
RenderRepaintBoundary
currentPageRepaintBoundary
;
RenderRepaintBoundary
?
currentPageRepaintBoundary
;
void
filter
(
Element
element
)
{
if
(
element
is
RenderObjectElement
&&
element
.
renderObject
is
RenderBox
)
{
final
ModalRoute
<
dynamic
>
route
=
ModalRoute
.
of
<
dynamic
>(
element
);
final
ModalRoute
<
dynamic
>
?
route
=
ModalRoute
.
of
<
dynamic
>(
element
);
if
(
route
!=
null
&&
route
!=
rootRoute
)
{
final
RenderBox
renderBox
=
element
.
renderObject
as
RenderBox
;
if
(
renderBox
.
hasSize
&&
renderBox
.
attached
&&
renderBox
.
isRepaintBoundary
)
{
String
desc
;
String
?
desc
;
if
(!
kReleaseMode
)
{
desc
=
element
.
renderObject
.
debugCreator
.
toString
();
}
...
...
@@ -336,21 +347,21 @@ class ColorPickerWidgetState extends State<ColorPickerWidget> {
element
.
visitChildren
(
filter
);
}
DoKitApp
.
appKey
.
currentContext
.
visitChildElements
(
filter
);
DoKitApp
.
appKey
.
currentContext
?
.
visitChildElements
(
filter
);
return
currentPageRepaintBoundary
;
}
Future
<
Uint8List
>
_boundaryToImageUint8List
(
RenderRepaintBoundary
boundary
)
async
{
Future
<
Uint8List
?
>
_boundaryToImageUint8List
(
RenderRepaintBoundary
?
boundary
)
async
{
if
(
boundary
==
null
)
{
return
null
;
}
final
double
dpr
=
ui
.
window
.
devicePixelRatio
;
final
ui
.
Image
image
=
await
boundary
.
toImage
(
pixelRatio:
dpr
);
final
ByteData
byteData
=
final
ByteData
?
byteData
=
await
image
.
toByteData
(
format:
ui
.
ImageByteFormat
.
png
);
final
Uint8List
pngBytes
=
byteData
.
buffer
.
asUint8List
();
final
Uint8List
?
pngBytes
=
byteData
?
.
buffer
.
asUint8List
();
return
pngBytes
;
}
...
...
@@ -367,8 +378,11 @@ class GridsPainter extends CustomPainter {
GridsPainter
();
double
get
scale
=>
ColorPickerKit
.
instance
.
scale
;
ui
.
Image
get
image
=>
ColorPickerKit
.
instance
.
snapshot
.
value
;
ui
.
Image
?
get
image
=>
ColorPickerKit
.
instance
.
snapshot
.
value
;
Offset
get
position
=>
ColorPickerKit
.
instance
.
position
.
value
;
double
get
radius
=>
ColorPickerKit
.
instance
.
diameter
/
2
;
// 水平方向上显示多少个颜色格子
...
...
@@ -392,7 +406,7 @@ class GridsPainter extends CustomPainter {
final
srcRect
=
Rect
.
fromLTWH
(
left
,
top
,
width
.
toDouble
(),
height
.
toDouble
());
final
distRect
=
Rect
.
fromLTWH
(
0
,
0
,
size
.
width
,
size
.
height
);
canvas
.
drawImageRect
(
image
,
srcRect
,
distRect
,
paint
);
canvas
.
drawImageRect
(
image
!
,
srcRect
,
distRect
,
paint
);
}
@override
...
...
@@ -460,16 +474,17 @@ class ColorPickerInfoWidget extends StatefulWidget {
class
_ColorPickerInfoWidgetState
extends
State
<
ColorPickerInfoWidget
>
{
double
top
=
infoWidgetTopMargin
;
Color
color
;
Color
?
color
;
String
get
colorDesc
=>
'#
${color?.value
?.toRadixString(16)?.padLeft(8, '0')?
.toUpperCase() ?? ''}
'
;
'#
${color?.value
.toRadixString(16).padLeft(8, '0')
.toUpperCase() ?? ''}
'
;
@override
Widget
build
(
BuildContext
context
)
{
return
Positioned
(
left:
infoWidgetHorizontalMargin
,
top:
top
,
child:
Draggable
<
dynamic
>(
child:
Draggable
<
Object
>(
child:
_buildInfoView
(),
feedback:
_buildInfoView
(),
childWhenDragging:
Container
(),
...
...
@@ -511,7 +526,7 @@ class _ColorPickerInfoWidgetState extends State<ColorPickerInfoWidget> {
children:
<
Widget
>[
ValueListenableBuilder
<
Color
>(
valueListenable:
ColorPickerKit
.
instance
.
color
,
builder:
(
BuildContext
context
,
Color
value
,
Widget
child
)
{
builder:
(
BuildContext
context
,
Color
value
,
Widget
?
child
)
{
color
=
value
;
return
Row
(
crossAxisAlignment:
CrossAxisAlignment
.
center
,
...
...
Flutter/lib/kit/visual/visual.dart
浏览文件 @
73a816e2
...
...
@@ -32,7 +32,7 @@ class VisualKitManager {
kitMap
[
tag
]
=
kit
;
}
T
getKit
<
T
extends
IKit
>(
String
name
)
{
T
?
getKit
<
T
extends
IKit
>(
String
name
)
{
assert
(
name
!=
null
);
if
(
kitMap
.
containsKey
(
name
))
{
return
kitMap
[
name
]
as
T
;
...
...
Flutter/lib/util/byte_util.dart
浏览文件 @
73a816e2
String
toByteString
(
int
bytes
)
{
String
toByteString
(
int
?
bytes
)
{
if
(
bytes
==
null
){
return
'0'
;
}
if
(
bytes
<=
(
1
<<
10
))
{
return
'
${bytes}
B'
;
}
else
if
(
bytes
<=
(
1
<<
20
))
{
...
...
Flutter/lib/widget/source_code/source_code_view.dart
浏览文件 @
73a816e2
...
...
@@ -9,7 +9,7 @@ class SourceCodeView extends StatelessWidget {
final
double
_textScaleFactor
=
1.0
;
const
SourceCodeView
({
Key
key
,
@
required
this
.
sourceCode
})
const
SourceCodeView
({
Key
?
key
,
required
this
.
sourceCode
})
:
super
(
key:
key
);
@override
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录