full migrate to sound null safety.

master
小赖 4 years ago
parent db34dbeb40
commit 9ef7e0a047

@ -164,7 +164,7 @@ packages:
path: ".."
relative: true
source: path
version: "0.1.3"
version: "1.0.0-nullsafety.0"
sky_engine:
dependency: transitive
description: flutter

@ -5,42 +5,34 @@ import 'package:power_logger/src/view/dio_error_view.dart';
///Dio Error builder
class DioErrorBuilder extends StatefulWidget {
final DioError data;
DioErrorBuilder({Key key, @required this.data}) : super(key: key);
DioErrorBuilder({Key? key, required this.data}) : super(key: key);
@override
_DioErrorBuilderState createState() => _DioErrorBuilderState();
}
class _DioErrorBuilderState extends State<DioErrorBuilder> {
RequestOptions get _request => widget?.data?.requestOptions;
RequestOptions get _request => widget.data.requestOptions;
String renderErrText(DioErrorType type) {
switch (type) {
case DioErrorType.connectTimeout:
return '连接超时';
break;
case DioErrorType.sendTimeout:
return '发送超时';
break;
case DioErrorType.receiveTimeout:
return '接收超时';
break;
case DioErrorType.response:
return 'Serve Side Error';
break;
case DioErrorType.cancel:
return '取消连接';
break;
case DioErrorType.other:
return '未知错误';
break;
}
return '';
}
@override
Widget build(BuildContext context) {
if (widget.data == null) return ListTile(title: Text('NULL Dio Error'));
return Material(
color: Colors.red[100],
child: Column(

@ -5,14 +5,14 @@ import 'package:power_logger/src/view/dio_response_view.dart';
/// Dio Response Builder
class DioResponseBuilder extends StatefulWidget {
final Response data;
DioResponseBuilder({Key key, this.data}) : super(key: key);
DioResponseBuilder({Key? key,required this.data}) : super(key: key);
@override
_DioResponseBuilderState createState() => _DioResponseBuilderState();
}
class _DioResponseBuilderState extends State<DioResponseBuilder> {
RequestOptions get _request => widget?.data?.requestOptions;
RequestOptions? get _request => widget.data.requestOptions;
@override
Widget build(BuildContext context) {
@ -27,7 +27,7 @@ class _DioResponseBuilderState extends State<DioResponseBuilder> {
),
),
title: Text(
_request.path,
_request!.path,
style: TextStyle(
color: Colors.black87,
),
@ -37,7 +37,7 @@ class _DioResponseBuilderState extends State<DioResponseBuilder> {
children: [
Chip(
backgroundColor: Colors.green.withOpacity(0.8),
label: Text(_request.method),
label: Text(_request!.method),
),
],
),

@ -13,7 +13,7 @@ class LoggerData {
/// set the logger max number.
static setMax(int max) {
_maxLength = max ?? 100;
_maxLength = max;
}
/// add data to logger
@ -35,12 +35,12 @@ class LoggerData {
/// add data listener
static addListener(Function listener) {
_listenableData.addListener(listener);
_listenableData.addListener(listener as void Function());
}
/// remove data listener
static removeListener(Function listener) {
_listenableData.removeListener(listener);
_listenableData.removeListener(listener as void Function());
}
}

@ -15,20 +15,20 @@ enum ContentType {
/// Dio parse
class DioParser {
Response _response;
DioParser(Response response) {
Response? _response;
DioParser(Response? response) {
_response = response;
}
/// get dio request
RequestOptions get request => _response.requestOptions;
RequestOptions get request => _response!.requestOptions;
/// get dio response
Response get response => _response;
Response? get response => _response;
/// get dio contentType
ContentType get type {
String _ctype = response.headers.map['content-type'].first;
String _ctype = response!.headers.map['content-type']!.first;
switch (_ctype) {
case 'text/plain':
return ContentType.TEXT_PLAIN;

@ -3,7 +3,7 @@ import 'package:flutter/material.dart';
/// UnfocusParser
class UnfocusParser extends StatelessWidget {
final dynamic data;
const UnfocusParser({Key key, @required this.data}) : super(key: key);
const UnfocusParser({Key? key, required this.data}) : super(key: key);
@override
Widget build(BuildContext context) {

@ -26,14 +26,14 @@ class PowerLogger {
///PowerLogger.start(context,debug:true);
///```
static start(BuildContext context, {bool debug = true}) {
WidgetsBinding.instance.addPostFrameCallback((_) {
WidgetsBinding.instance!.addPostFrameCallback((_) {
PowerLogger.debug = debug;
if (debug) _insertToOverlay(context);
});
}
static _insertToOverlay(BuildContext context) {
Overlay.of(context).insert(OverlayEntry(
Overlay.of(context)!.insert(OverlayEntry(
builder: (context) {
return LoggerFab();
},

@ -6,7 +6,7 @@ import 'package:power_logger/src/views/settings_view.dart';
///Logger view
class PowerLoggerView extends StatefulWidget {
PowerLoggerView({Key key}) : super(key: key);
PowerLoggerView({Key? key}) : super(key: key);
@override
_PowerLoggerViewState createState() => _PowerLoggerViewState();
@ -15,7 +15,7 @@ class PowerLoggerView extends StatefulWidget {
class _PowerLoggerViewState extends State<PowerLoggerView> {
PageController _pageController = PageController();
int _currentIndex = 0;
void Function(void Function()) _setState;
void Function(void Function())? _setState;
@override
Widget build(BuildContext context) {
return Theme(
@ -37,7 +37,7 @@ class _PowerLoggerViewState extends State<PowerLoggerView> {
controller: _pageController,
onPageChanged: (index) {
_currentIndex = index;
if (_setState != null) _setState(() {});
if (_setState != null) _setState!(() {});
},
children: [
LoggerView(),

@ -3,12 +3,12 @@ import 'package:flutter/material.dart';
///BoxView
class BoxView extends StatelessWidget {
final Widget title;
final Widget child;
final List<Widget> children;
final Widget? child;
final List<Widget>? children;
const BoxView({
Key key,
Key? key,
this.child,
@required this.title,
required this.title,
this.children,
}) : assert(child != null || children != null),
super(key: key);

@ -6,7 +6,7 @@ import 'package:power_logger/src/view/title_view.dart';
class DioErrorView extends StatefulWidget {
final DioError data;
DioErrorView({Key key, @required this.data}) : super(key: key);
DioErrorView({Key? key, required this.data}) : super(key: key);
@override
_DioErrorViewState createState() => _DioErrorViewState();
@ -15,7 +15,7 @@ class DioErrorView extends StatefulWidget {
class _DioErrorViewState extends State<DioErrorView> {
RequestOptions get _request => widget.data.requestOptions;
_buildBaseURL() {
return _request.baseUrl == null || _request.baseUrl.length == 0
return _request.baseUrl.length == 0
? const SizedBox()
: BoxView(
title: Text('BaseURL'),

@ -14,8 +14,8 @@ import 'package:power_logger/src/view/title_view.dart';
// enum
class DioResponseView extends StatefulWidget {
final Response data;
DioResponseView({Key key, @required this.data}) : super(key: key);
final Response? data;
DioResponseView({Key? key, required this.data}) : super(key: key);
@override
_DioResponseViewState createState() => _DioResponseViewState();
@ -24,9 +24,9 @@ class DioResponseView extends StatefulWidget {
class _DioResponseViewState extends State<DioResponseView> {
bool _showRawData = false;
RequestOptions get _request => _dioParser.request;
DioParser _dioParser;
late DioParser _dioParser;
_buildBaseURL() {
return _request.baseUrl == null || _request.baseUrl.length == 0
return _request.baseUrl.length == 0
? const SizedBox()
: BoxView(
title: Text('BaseURL'),
@ -46,9 +46,9 @@ class _DioResponseViewState extends State<DioResponseView> {
title: const Text('Status'),
children: [
Chip(
label: Text(widget.data.statusCode.toString()),
label: Text(widget.data!.statusCode.toString()),
),
Text(widget.data.statusMessage),
Text(widget.data!.statusMessage!),
],
);
}
@ -77,7 +77,7 @@ class _DioResponseViewState extends State<DioResponseView> {
return BoxView(
title: Text('Data'),
child: HighlightView(
widget.data.data,
widget.data!.data,
language: _dioParser.highlight,
theme: atomOneLightTheme,
),
@ -85,9 +85,9 @@ class _DioResponseViewState extends State<DioResponseView> {
case ContentType.JSON:
//JSON.
//parse json of String type.
if (widget.data.data is String) {
if (widget.data!.data is String) {
String json = '';
json = prettyJson(jsonDecode(widget.data.data));
json = prettyJson(jsonDecode(widget.data!.data));
return BoxView(
title: Text('Data'),
child: HighlightView(
@ -100,12 +100,11 @@ class _DioResponseViewState extends State<DioResponseView> {
return BoxView(
title: Text('Data'),
child: HighlightView(
prettyJson(widget.data.data),
prettyJson(widget.data!.data),
language: 'json',
theme: atomOneLightTheme,
),
);
break;
case ContentType.IMAGE:
return Text("IMAGE");
case ContentType.AUDIO:
@ -118,7 +117,7 @@ class _DioResponseViewState extends State<DioResponseView> {
return BoxView(
title: Text('Data'),
child: HighlightView(
prettyJson(widget.data.data),
prettyJson(widget.data!.data),
language: 'json',
theme: atomOneLightTheme,
),
@ -128,7 +127,7 @@ class _DioResponseViewState extends State<DioResponseView> {
_buildRawData() {
return BoxView(
title: Text('Raw Data'),
child: SelectableText(widget.data.data.toString()),
child: SelectableText(widget.data!.data.toString()),
);
}
@ -152,10 +151,10 @@ class _DioResponseViewState extends State<DioResponseView> {
return Scaffold(
appBar: AppBar(
backgroundColor: Colors.green[600],
title: Text(widget.data.requestOptions.path),
title: Text(widget.data!.requestOptions.path),
actions: [
Chip(
label: Text(widget.data.requestOptions.method),
label: Text(widget.data!.requestOptions.method),
backgroundColor: Colors.lightGreen,
),
SizedBox(width: 8),
@ -171,7 +170,7 @@ class _DioResponseViewState extends State<DioResponseView> {
_buildMap(_request.queryParameters),
_buildMap(_request.data),
TitleView(title: Text('Response')),
_buildMap(widget.data.headers.map),
_buildMap(widget.data!.headers.map),
_buildStatus(),
SwitchListTile(
value: _showRawData,

@ -1,8 +1,8 @@
import 'package:flutter/material.dart';
class TableView extends StatelessWidget {
final Map map;
const TableView({Key key, @required this.map}) : super(key: key);
final Map? map;
const TableView({Key? key, required this.map}) : super(key: key);
Widget _buildTableTitle(String title) {
return Padding(
padding: EdgeInsets.all(5),

@ -2,7 +2,7 @@ import 'package:flutter/material.dart';
class TitleView extends StatelessWidget {
final Widget title;
const TitleView({Key key, @required this.title}) : super(key: key);
const TitleView({Key? key, required this.title}) : super(key: key);
@override
Widget build(BuildContext context) {

@ -8,7 +8,7 @@ import 'package:flutter/services.dart';
import 'package:package_info/package_info.dart';
class InfoView extends StatefulWidget {
InfoView({Key key}) : super(key: key);
InfoView({Key? key}) : super(key: key);
@override
_InfoViewState createState() => _InfoViewState();
@ -16,9 +16,9 @@ class InfoView extends StatefulWidget {
class _InfoViewState extends State<InfoView>
with AutomaticKeepAliveClientMixin {
PackageInfo packageInfo;
AndroidDeviceInfo androidInfo;
IosDeviceInfo iosInfo;
PackageInfo? packageInfo;
AndroidDeviceInfo? androidInfo;
IosDeviceInfo? iosInfo;
Future getAllInfo() async {
DeviceInfoPlugin deviceInfo = DeviceInfoPlugin();
@ -58,7 +58,7 @@ class _InfoViewState extends State<InfoView>
children: [
Text(title),
AutoSizeText(
subTitle ?? '',
subTitle,
style: TextStyle(fontSize: 26),
maxLines: 2,
),
@ -68,7 +68,7 @@ class _InfoViewState extends State<InfoView>
);
}
_buildTile(String title, String subTitle) {
_buildTile(String title, String? subTitle) {
return DefaultTextStyle(
style: TextStyle(color: Colors.black),
child: ListTile(
@ -93,53 +93,53 @@ class _InfoViewState extends State<InfoView>
_buildAndroidList() {
return SliverList(
delegate: SliverChildListDelegate([
_buildTile('androidId', androidInfo.androidId),
_buildTile('board', androidInfo.board),
_buildTile('bootloader', androidInfo.bootloader),
_buildTile('brand', androidInfo.brand),
_buildTile('device', androidInfo.device),
_buildTile('display', androidInfo.display),
_buildTile('fingerprint', androidInfo.fingerprint),
_buildTile('hardware', androidInfo.hardware),
_buildTile('host', androidInfo.host),
_buildTile('id', androidInfo.id),
_buildTile('manufacturer', androidInfo.manufacturer),
_buildTile('model', androidInfo.model),
_buildTile('product', androidInfo.product),
_buildTile('tags', androidInfo.tags),
_buildTile('type', androidInfo.type),
_buildTile('isPhysicalDevice', androidInfo.isPhysicalDevice.toString()),
_buildTile('androidId', androidInfo!.androidId),
_buildTile('board', androidInfo!.board),
_buildTile('bootloader', androidInfo!.bootloader),
_buildTile('brand', androidInfo!.brand),
_buildTile('device', androidInfo!.device),
_buildTile('display', androidInfo!.display),
_buildTile('fingerprint', androidInfo!.fingerprint),
_buildTile('hardware', androidInfo!.hardware),
_buildTile('host', androidInfo!.host),
_buildTile('id', androidInfo!.id),
_buildTile('manufacturer', androidInfo!.manufacturer),
_buildTile('model', androidInfo!.model),
_buildTile('product', androidInfo!.product),
_buildTile('tags', androidInfo!.tags),
_buildTile('type', androidInfo!.type),
_buildTile('isPhysicalDevice', androidInfo!.isPhysicalDevice.toString()),
_buildTile(
'supported32BitAbis', androidInfo.supported32BitAbis.join(',')),
'supported32BitAbis', androidInfo!.supported32BitAbis.join(',')),
_buildTile(
'supported64BitAbis', androidInfo.supported64BitAbis.join(',')),
_buildTile('supportedAbis', androidInfo.supportedAbis.join(',')),
_buildTile('baseOS', androidInfo.version.baseOS),
_buildTile('codename', androidInfo.version.codename),
_buildTile('incremental', androidInfo.version.incremental),
_buildTile('release', androidInfo.version.release),
_buildTile('securityPatch', androidInfo.version.securityPatch),
_buildTile('previewSdkInt', androidInfo.version.previewSdkInt.toString()),
_buildTile('sdkInt', androidInfo.version.sdkInt.toString()),
_buildTile('systemFeatures', androidInfo.systemFeatures.join('\n')),
'supported64BitAbis', androidInfo!.supported64BitAbis.join(',')),
_buildTile('supportedAbis', androidInfo!.supportedAbis.join(',')),
_buildTile('baseOS', androidInfo!.version.baseOS),
_buildTile('codename', androidInfo!.version.codename),
_buildTile('incremental', androidInfo!.version.incremental),
_buildTile('release', androidInfo!.version.release),
_buildTile('securityPatch', androidInfo!.version.securityPatch),
_buildTile('previewSdkInt', androidInfo!.version.previewSdkInt.toString()),
_buildTile('sdkInt', androidInfo!.version.sdkInt.toString()),
_buildTile('systemFeatures', androidInfo!.systemFeatures.join('\n')),
]));
}
_buildIOSList() {
return SliverList(
delegate: SliverChildListDelegate([
_buildTile('identifierForVendor', iosInfo.identifierForVendor),
_buildTile('localizedModel', iosInfo.localizedModel),
_buildTile('model', iosInfo.model),
_buildTile('name', iosInfo.name),
_buildTile('systemName', iosInfo.systemName),
_buildTile('systemVersion', iosInfo.systemVersion),
_buildTile('isPhysicalDevice', iosInfo.isPhysicalDevice.toString()),
_buildTile('machine', iosInfo.utsname.machine),
_buildTile('nodename', iosInfo.utsname.nodename),
_buildTile('release', iosInfo.utsname.release),
_buildTile('sysname', iosInfo.utsname.sysname),
_buildTile('version', iosInfo.utsname.version),
_buildTile('identifierForVendor', iosInfo!.identifierForVendor),
_buildTile('localizedModel', iosInfo!.localizedModel),
_buildTile('model', iosInfo!.model),
_buildTile('name', iosInfo!.name),
_buildTile('systemName', iosInfo!.systemName),
_buildTile('systemVersion', iosInfo!.systemVersion),
_buildTile('isPhysicalDevice', iosInfo!.isPhysicalDevice.toString()),
_buildTile('machine', iosInfo!.utsname.machine),
_buildTile('nodename', iosInfo!.utsname.nodename),
_buildTile('release', iosInfo!.utsname.release),
_buildTile('sysname', iosInfo!.utsname.sysname),
_buildTile('version', iosInfo!.utsname.version),
]));
}
@ -171,10 +171,10 @@ class _InfoViewState extends State<InfoView>
mainAxisSpacing: 10,
crossAxisSpacing: 10,
children: [
_buildGridItem('appName', packageInfo.appName),
_buildGridItem('buildNumber', packageInfo.buildNumber),
_buildGridItem('packageName', packageInfo.packageName),
_buildGridItem('version', packageInfo.version),
_buildGridItem('appName', packageInfo!.appName),
_buildGridItem('buildNumber', packageInfo!.buildNumber),
_buildGridItem('packageName', packageInfo!.packageName),
_buildGridItem('version', packageInfo!.version),
],
),
),

@ -3,7 +3,7 @@ import 'package:power_logger/src/data/logger_data.dart';
import 'package:power_logger/src/parser/data_parser.dart';
class LoggerView extends StatefulWidget {
LoggerView({Key key}) : super(key: key);
LoggerView({Key? key}) : super(key: key);
@override
_LoggerViewState createState() => _LoggerViewState();

@ -1,7 +1,7 @@
import 'package:flutter/material.dart';
class SettingsView extends StatefulWidget {
SettingsView({Key key}) : super(key: key);
SettingsView({Key? key}) : super(key: key);
@override
_SettingsViewState createState() => _SettingsViewState();

@ -3,7 +3,7 @@ import 'package:flutter/physics.dart';
import 'package:power_logger/src/power_logger_view.dart';
class LoggerFab extends StatefulWidget {
LoggerFab({Key key}) : super(key: key);
LoggerFab({Key? key}) : super(key: key);
@override
_LoggerFabState createState() => _LoggerFabState();
@ -12,9 +12,9 @@ class LoggerFab extends StatefulWidget {
class _LoggerFabState extends State<LoggerFab>
with SingleTickerProviderStateMixin {
bool showSubPage = false;
AnimationController _animationController;
AnimationController? _animationController;
var _dragAlignment = Alignment.center;
Animation<Alignment> _animation;
late Animation<Alignment> _animation;
final _spring =
const SpringDescription(mass: 15, stiffness: 1000, damping: 0.7);
@ -34,7 +34,7 @@ class _LoggerFabState extends State<LoggerFab>
calcAlignment = Alignment(calcAlignment.x, 0.9);
if (_dragAlignment.y <= -0.9)
calcAlignment = Alignment(calcAlignment.x, -0.9);
_animation = _animationController.drive(
_animation = _animationController!.drive(
AlignmentTween(
begin: _dragAlignment,
end: calcAlignment,
@ -44,7 +44,7 @@ class _LoggerFabState extends State<LoggerFab>
final simulation =
SpringSimulation(_spring, 0, 1, _normalizeVelocity(velocity, size));
_animationController.animateWith(simulation);
_animationController!.animateWith(simulation);
}
@override
@ -69,7 +69,7 @@ class _LoggerFabState extends State<LoggerFab>
duration: Duration(milliseconds: 300),
opacity: showSubPage ? 0 : 1,
child: GestureDetector(
onPanStart: (details) => _animationController.stop(canceled: true),
onPanStart: (details) => _animationController!.stop(canceled: true),
onPanUpdate: (details) => setState(() => _dragAlignment += Alignment(
details.delta.dx / (size.width / 2),
details.delta.dy / (size.height / 2),
@ -94,7 +94,7 @@ class _LoggerFabState extends State<LoggerFab>
}
class _FabButton extends StatelessWidget {
const _FabButton({Key key}) : super(key: key);
const _FabButton({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {

@ -1,10 +1,10 @@
name: power_logger
description: A well log tool on flutter, support Dio and custom type data.
version: 0.1.3
version: 1.0.0-nullsafety.0
homepage: https://github.com/laiiihz/power_logger
environment:
sdk: ">=2.7.0 <3.0.0"
sdk: '>=2.12.0 <3.0.0'
flutter: ">=1.17.0"
dependencies:

Loading…
Cancel
Save