提交 65fe89b8 编写于 作者: L linusflow

适配flutter2.0新的api

上级 50d27691
......@@ -29,7 +29,7 @@ void main() {
app: DoKitApp(MyApp()),
useInRelease: true,
logCallback: (log) {
String i = log;
// String i = log;
},
methodChannelBlackList: blackList,
exceptionCallback: (dynamic obj, StackTrace trace) {
......@@ -106,7 +106,7 @@ class _DoKitTestPageState extends State<DoKitTestPage> {
borderRadius: BorderRadius.all(Radius.circular(4)),
color: Color(0xffcccccc)),
margin: EdgeInsets.only(bottom: 30),
child: FlatButton(
child: TextButton(
child: Text('Mock Http Post',
style: TextStyle(
color: Color(0xff000000),
......@@ -120,7 +120,10 @@ class _DoKitTestPageState extends State<DoKitTestPage> {
borderRadius: BorderRadius.all(Radius.circular(4)),
color: Color(0xffcccccc)),
margin: EdgeInsets.only(bottom: 30),
child: FlatButton(
child: TextButton(
style: ButtonStyle(
padding: MaterialStateProperty.all(EdgeInsets.all(0)),
),
child: Text('Mock Http Get',
style: TextStyle(
color: Color(0xff000000),
......@@ -134,7 +137,10 @@ class _DoKitTestPageState extends State<DoKitTestPage> {
borderRadius: BorderRadius.all(Radius.circular(4)),
color: Color(0xffcccccc)),
margin: EdgeInsets.only(bottom: 30),
child: FlatButton(
child: TextButton(
style: ButtonStyle(
padding: MaterialStateProperty.all(EdgeInsets.all(0)),
),
child: Text('Test Download',
style: TextStyle(
color: Color(0xff000000),
......@@ -148,7 +154,10 @@ class _DoKitTestPageState extends State<DoKitTestPage> {
borderRadius: BorderRadius.all(Radius.circular(4)),
color: Color(0xffcccccc)),
margin: EdgeInsets.only(bottom: 30),
child: FlatButton(
child: TextButton(
style: ButtonStyle(
padding: MaterialStateProperty.all(EdgeInsets.all(0)),
),
child: Text('Test Method Channel',
style: TextStyle(
color: Color(0xff000000),
......@@ -164,7 +173,10 @@ class _DoKitTestPageState extends State<DoKitTestPage> {
borderRadius: BorderRadius.all(Radius.circular(4)),
color: Color(0xffcccccc)),
margin: EdgeInsets.only(bottom: 30),
child: FlatButton(
child: TextButton(
style: ButtonStyle(
padding: MaterialStateProperty.all(EdgeInsets.all(0)),
),
child: Text('Open Route Page',
style: TextStyle(
color: Color(0xff000000),
......@@ -187,7 +199,10 @@ class _DoKitTestPageState extends State<DoKitTestPage> {
borderRadius: BorderRadius.all(Radius.circular(4)),
color: Color(0xffcccccc)),
margin: EdgeInsets.only(bottom: 30),
child: FlatButton(
child: TextButton(
style: ButtonStyle(
padding: MaterialStateProperty.all(EdgeInsets.all(0)),
),
child: Text('Test Get Page Script',
style: TextStyle(
color: Color(0xff000000),
......@@ -203,7 +218,10 @@ class _DoKitTestPageState extends State<DoKitTestPage> {
borderRadius: BorderRadius.all(Radius.circular(4)),
color: Color(0xffcccccc)),
margin: EdgeInsets.only(bottom: 30),
child: FlatButton(
child: TextButton(
style: ButtonStyle(
padding: MaterialStateProperty.all(EdgeInsets.all(0)),
),
child: Text('Stop Timer',
style: TextStyle(
color: Color(0xff000000),
......
name: dokit_demo
description: dokit测试工程
version: 0.0.1
version: 0.8.0
homepage: http://flutter.intra.xiaojukeji.com/index.php
environment:
......
// Copyright© Dokit for Flutter.
// Copyright© Dokit for Flutter. All rights reserved.
//
// dokit.dart
// Flutter
//
// Created by linusflow on 2021/3/05
// Modified by linusflow on 2021/5/12 下午2:05
// Modified by linusflow on 2021/5/12 下午3:47
//
import 'dart:async';
......@@ -69,12 +69,19 @@ class DoKit {
return;
}
blackList = methodChannelBlackList;
await runZoned(
await runZonedGuarded(
() async => <void>{
_ensureDoKitBinding(useInRelease: useInRelease),
_runWrapperApp(app != null ? app : await appCreator!()),
_zone = Zone.current
},
(Object obj, StackTrace stack) {
_collectError(obj, stack);
if (exceptionCallback != null) {
_zone?.runBinary(exceptionCallback, obj, stack);
}
},
zoneSpecification: ZoneSpecification(
print: (Zone self, ZoneDelegate parent, Zone zone, String line) {
_collectLog(line); //手机日志
......@@ -84,12 +91,6 @@ class DoKit {
}
},
),
onError: (Object obj, StackTrace stack) {
_collectError(obj, stack);
if (exceptionCallback != null) {
_zone?.runBinary(exceptionCallback, obj, stack);
}
},
);
}
}
......
......@@ -24,8 +24,7 @@ class DoKitWidgetsFlutterBinding extends WidgetsFlutterBinding
mixin DoKitServicesBinding on BindingBase, ServicesBinding {
@override
BinaryMessenger createBinaryMessenger() {
return DoKitBinaryMessenger(
super.createBinaryMessenger() as BinaryMessenger);
return DoKitBinaryMessenger(super.createBinaryMessenger());
}
}
......
......@@ -5,6 +5,7 @@ import 'dart:typed_data';
import 'package:dokit/kit/apm/apm.dart';
import 'package:dokit/kit/apm/http_kit.dart';
import 'package:pedantic/pedantic.dart';
class DoKitHttpOverrides extends HttpOverrides {
DoKitHttpOverrides(this.origin);
......@@ -26,7 +27,6 @@ class DoKitHttpOverrides extends HttpOverrides {
class DoKitHttpClient implements HttpClient {
DoKitHttpClient(this.origin);
final HttpClient origin;
HttpInfo? httpInfo;
......@@ -45,7 +45,6 @@ class DoKitHttpClient implements HttpClient {
@override
set connectionTimeout(Duration? value) => origin.connectionTimeout = value;
@override
Duration? get connectionTimeout => origin.connectionTimeout;
......@@ -74,7 +73,8 @@ class DoKitHttpClient implements HttpClient {
}
@override
set authenticate(Future<bool> Function(Uri url, String scheme, String realm)? f) {
set authenticate(
Future<bool> Function(Uri url, String scheme, String realm)? f) {
origin.authenticate = f;
}
......@@ -102,13 +102,13 @@ class DoKitHttpClient implements HttpClient {
}
Future<HttpClientRequest> monitor(Future<HttpClientRequest> future) async {
future.catchError((dynamic error, [StackTrace? stackTrace]) {
unawaited(future.catchError((dynamic error, [StackTrace? stackTrace]) {
if (httpInfo == null) {
httpInfo = HttpInfo.error(error.toString());
final HttpKit? kit = ApmKitManager.instance.getKit(ApmKitName.KIT_HTTP);
kit?.save(httpInfo);
}
});
}));
final HttpClientRequest request = await future;
httpInfo ??= HttpInfo(request.uri, request.method);
final HttpKit? kit = ApmKitManager.instance.getKit(ApmKitName.KIT_HTTP);
......@@ -281,9 +281,7 @@ class DoKitHttpClientRequest implements HttpClientRequest {
void recordParameter(List<int> data) {
try {
httpInfo?.request.header = headers.toString();
if (encoding != null) {
httpInfo?.request.add(encoding.decode(data));
}
httpInfo?.request.add(encoding.decode(data));
} catch (e) {
print(e);
}
......@@ -353,12 +351,11 @@ class DoKitHttpClientResponse implements HttpClientResponse {
return origin.asBroadcastStream(onListen: onListen, onCancel: onCancel);
}
@override
Stream<E> asyncExpand<E>(Stream<E>? Function(List<int> event) convert) {
return asyncExpand(convert);
}
@override
Stream<E> asyncMap<E>(FutureOr<E> Function(List<int> event) convert) {
return asyncMap(convert);
......@@ -430,7 +427,6 @@ class DoKitHttpClientResponse implements HttpClientResponse {
return origin.firstWhere(test, orElse: orElse);
}
@override
Future<S> fold<S>(
S initialValue, S Function(S previous, List<int> element) combine) {
......@@ -478,8 +474,7 @@ class DoKitHttpClientResponse implements HttpClientResponse {
Future<int> get length => origin.length;
bool isTextResponse() {
return headers != null &&
headers['content-type'] != null &&
return headers['content-type'] != null &&
(headers['content-type'].toString().contains('json') ||
headers['content-type'].toString().contains('text') ||
headers['content-type'].toString().contains('xml'));
......@@ -487,9 +482,7 @@ class DoKitHttpClientResponse implements HttpClientResponse {
Encoding? getEncoding() {
String charset;
if (
headers.contentType != null &&
headers.contentType?.charset != null) {
if (headers.contentType != null && headers.contentType?.charset != null) {
charset = headers.contentType!.charset!;
} else {
charset = 'utf-8';
......
......@@ -22,7 +22,7 @@ class ApmKitManager {
ApmKitName.KIT_PAGE_LAUNCH: PageLaunchKit()
};
ApmKitManager._privateConstructor() {}
ApmKitManager._privateConstructor();
static final ApmKitManager _instance = ApmKitManager._privateConstructor();
......
......@@ -278,7 +278,7 @@ class _HttpItemWidgetState extends State<HttpItemWidget> {
onLongPress: () {
if (widget.item.response.result != null) {
Clipboard.setData(ClipboardData(text: widget.item.response.result));
Scaffold.of(context).showSnackBar(const SnackBar(
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(
duration: Duration(milliseconds: 500),
content: Text('请求返回已拷贝至剪贴板'),
));
......
......@@ -330,7 +330,7 @@ class _LogItemWidgetState extends State<LogItemWidget> {
return GestureDetector(
onLongPress: () {
Clipboard.setData(ClipboardData(text: widget.item.msg));
Scaffold.of(context).showSnackBar(const SnackBar(
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(
duration: Duration(milliseconds: 500),
content: Text('已拷贝至剪贴板'),
));
......@@ -342,12 +342,10 @@ class _LogItemWidgetState extends State<LogItemWidget> {
(SharedPreferences prefs) {
if (!prefs.containsKey(KEY_SHOW_LOG_EXPAND_TIPS)) {
prefs.setBool(KEY_SHOW_LOG_EXPAND_TIPS, true);
Scaffold.of(context).showSnackBar(
const SnackBar(
duration: Duration(milliseconds: 2000),
content: Text('日志超过7行时,点击可展开日志详情'),
),
);
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(
duration: Duration(milliseconds: 2000),
content: Text('日志超过7行时,点击可展开日志详情'),
));
}
},
);
......
......@@ -127,8 +127,7 @@ class MemoryPageState extends State<MemoryPage> {
return Container(
margin: EdgeInsets.only(top: 3),
alignment: Alignment.topLeft,
child: VmHelper.instance.memoryInfo != null &&
VmHelper.instance.memoryInfo.length > 0
child: VmHelper.instance.memoryInfo.isNotEmpty
? Column(
children: getMemoryInfo(
VmHelper.instance.memoryInfo))
......@@ -161,7 +160,7 @@ class MemoryPageState extends State<MemoryPage> {
style:
TextStyle(color: Color(0xff333333), fontSize: 16),
inputFormatters: [
BlacklistingTextInputFormatter(RegExp(
FilteringTextInputFormatter.deny(RegExp(
'[^\\u0020-\\u007E\\u00A0-\\u00BE\\u2E80-\\uA4CF\\uF900-\\uFAFF\\uFE30-\\uFE4F\\uFF00-\\uFFEF\\u0080-\\u009F\\u2000-\\u201f\r\n]'))
],
onSubmitted: (value) => {filterAllocations()},
......@@ -176,9 +175,11 @@ class MemoryPageState extends State<MemoryPage> {
),
Container(
width: 60,
child: FlatButton(
padding: EdgeInsets.only(
left: 15, right: 0, top: 15, bottom: 15),
child: TextButton(
style: ButtonStyle(
padding: MaterialStateProperty.all(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),
onPressed: filterAllocations,
......@@ -255,7 +256,6 @@ class MemoryPageState extends State<MemoryPage> {
void filterAllocations() {
String className = editingController.text;
assert(className != null);
heaps.clear();
if (className.length >= 3 && kit?.getAllocationProfile() != null) {
kit?.getAllocationProfile()?.members?.forEach((element) {
......
......@@ -45,7 +45,6 @@ class ChannelInfo implements IInfo {
'method:${method}\n' +
'arguments:${arguments}\n' +
'results:${results}';
;
}
factory ChannelInfo.error(String channelName, int type) {
......
......@@ -214,7 +214,7 @@ class RouteInfoPageState extends State<RouteInfoPage> {
final NavigatorState? navigatorState =
element.findAncestorStateOfType<NavigatorState>();
if (navigatorState != null && navigatorState.context != null) {
if (navigatorState != null) {
final RouteInfo parent = RouteInfo();
parent.current = ModalRoute.of(navigatorState.context);
routeInfo.parent = parent;
......
......@@ -7,6 +7,7 @@ import 'package:flutter/material.dart';
abstract class CommonKit implements IKit {
@override
void tabAction() {
// ignore: invalid_use_of_protected_member
ResidentPage.residentPageKey.currentState?.setState(() {
ResidentPage.tag = getKitName();
});
......@@ -20,7 +21,7 @@ class CommonKitManager {
CommonKitName.KIT_BASIC_INFO: BasicInfoKit(),
};
CommonKitManager._privateConstructor() {}
CommonKitManager._privateConstructor();
static final CommonKitManager _instance =
CommonKitManager._privateConstructor();
......@@ -29,7 +30,6 @@ class CommonKitManager {
// 如果想要自定义实现,可以用这个方式进行覆盖。后续扩展入口
void addKit(String tag, CommonKit kit) {
assert(tag != null && kit != null);
kitMap[tag] = kit;
}
......
......@@ -36,12 +36,10 @@ class VisualKitManager {
// 如果想要自定义实现,可以用这个方式进行覆盖。后续扩展入口
void addKit(String tag, IKit kit) {
assert(tag != null && kit != null);
kitMap[tag] = kit;
}
T? getKit<T extends IKit>(String name) {
assert(name != null);
if (kitMap.containsKey(name)) {
return kitMap[name] as T;
}
......
......@@ -104,12 +104,16 @@ class _DoKitAppState extends State<DoKitApp> {
children: <Widget>[
widget.origin,
_MediaQueryFromWindow(
child: Localizations(
locale: supportedLocales.first,
delegates: _localizationsDelegates.toList(),
child: Overlay(
key: doKitOverlayKey,
)))
child: Localizations(
locale: supportedLocales.first,
delegates: _localizationsDelegates.toList(),
child: ScaffoldMessenger(
child: Overlay(
key: doKitOverlayKey,
),
),
),
)
],
),
);
......
......@@ -47,8 +47,10 @@ class DoKitBtnState extends State<DoKitBtn> {
width: 70,
height: 70,
alignment: Alignment.center,
child: FlatButton(
padding: const EdgeInsets.all(0),
child: TextButton(
style: ButtonStyle(
padding: MaterialStateProperty.all(EdgeInsets.all(0)),
),
child: Image.asset('images/dokit_flutter_btn.png',
package: DK_PACKAGE_NAME, height: 70, width: 70),
onPressed: openDebugPage,
......@@ -58,8 +60,10 @@ class DoKitBtnState extends State<DoKitBtn> {
width: 70,
height: 70,
alignment: Alignment.center,
child: FlatButton(
padding: const EdgeInsets.all(0),
child: TextButton(
style: ButtonStyle(
padding: MaterialStateProperty.all(EdgeInsets.all(0)),
),
child: Image.asset('images/dokit_flutter_btn.png',
package: DK_PACKAGE_NAME, height: 70, width: 70),
onPressed: openDebugPage,
......
......@@ -314,7 +314,6 @@ class KitPageManager {
}
bool removeResidentKit(String tag) {
assert(tag != null);
if (residentList.contains(tag)) {
residentList.remove(tag);
SharedPreferences.getInstance().then((SharedPreferences prefs) =>
......
......@@ -145,7 +145,7 @@ class DashedDecoration extends Decoration {
final double strokeHeight;
final double gap;
final Color? dashedColor;
final bool dawDashed;
final bool? dawDashed;
@override
EdgeInsetsGeometry? get padding => border?.dimensions;
......@@ -333,9 +333,9 @@ class DashedDecoration extends Decoration {
final Offset center = size.center(Offset.zero);
final double distance = (position - center).distance;
return distance <= math.min(size.width, size.height) / 2.0;
default:
return false;
}
assert(shape != null);
return false;
}
@override
......@@ -356,7 +356,6 @@ class _BoxDecorationPainter extends BoxPainter {
Rect? _rectForCachedBackgroundPaint;
Paint _getBackgroundPaint(Rect rect, TextDirection textDirection) {
assert(rect != null);
assert(
_decoration.gradient != null || _rectForCachedBackgroundPaint == null);
......@@ -399,6 +398,8 @@ class _BoxDecorationPainter extends BoxPainter {
paint);
}
break;
default:
return;
}
}
......@@ -443,6 +444,8 @@ class _BoxDecorationPainter extends BoxPainter {
.toRRect(rect));
}
break;
default:
return;
}
_imagePainter!.paint(canvas, rect, clipPath, configuration);
}
......@@ -462,7 +465,7 @@ class _BoxDecorationPainter extends BoxPainter {
_paintShadows(canvas, rect, textDirection);
_paintBackgroundColor(canvas, rect, textDirection);
_paintBackgroundImage(canvas, rect, configuration);
if (_decoration.dawDashed != null && !_decoration.dawDashed) {
if (_decoration.dawDashed != null && !(_decoration.dawDashed ?? true)) {
_decoration.border?.paint(
canvas,
rect,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册