update document & update readme file

master
小赖 4 years ago
parent e19a619b20
commit f7546253d0

@ -1,14 +1,30 @@
# power_logger # power_logger
A new Flutter package. A well log tool on flutter, support Dio and custom type data.
## Getting Started ## Getting Started
This project is a starting point for a Dart ### Usage
[package](https://flutter.dev/developing-packages/),
a library module containing code that can be shared easily across
multiple Flutter or Dart projects.
For help getting started with Flutter, view our * init logger
[online documentation](https://flutter.dev/docs), which offers tutorials,
samples, guidance on mobile development, and a full API reference. ```dart
Future.delayed(
Duration(milliseconds: 300),
() => PowerLogger.init(context),
);
```
* add data to logger
```dart
LoggerData.addData(data);
```
## WARNING
*only tested on flutter 1.22.5
## author
[laiiihz](https://github.com/laiiihz)

@ -2,6 +2,7 @@ import 'package:dio/dio.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:power_logger/src/view/dio_error_view.dart'; import 'package:power_logger/src/view/dio_error_view.dart';
///Dio Error builder
class DioErrorBuilder extends StatefulWidget { class DioErrorBuilder extends StatefulWidget {
final DioError data; final DioError data;
DioErrorBuilder({Key key, @required this.data}) : super(key: key); DioErrorBuilder({Key key, @required this.data}) : super(key: key);

@ -2,6 +2,7 @@ import 'package:dio/dio.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:power_logger/src/view/dio_response_view.dart'; import 'package:power_logger/src/view/dio_response_view.dart';
/// Dio Response Builder
class DioResponseBuilder extends StatefulWidget { class DioResponseBuilder extends StatefulWidget {
final Response data; final Response data;
DioResponseBuilder({Key key, this.data}) : super(key: key); DioResponseBuilder({Key key, this.data}) : super(key: key);

@ -1,15 +1,20 @@
import 'package:power_logger/power_logger.dart'; import 'package:power_logger/power_logger.dart';
/// logger data storage
class LoggerData { class LoggerData {
static int _maxLength = 100; static int _maxLength = 100;
static List<dynamic> _data = []; static List<dynamic> _data = [];
/// the real logger data.
static List<dynamic> get data => _data; static List<dynamic> get data => _data;
/// set the logger max number.
static setMax(int max) { static setMax(int max) {
_maxLength = max ?? 100; _maxLength = max ?? 100;
} }
/// add data to logger
static addData(dynamic data) { static addData(dynamic data) {
if (PowerLogger.debug) { if (PowerLogger.debug) {
if (_data.length < _maxLength) if (_data.length < _maxLength)
@ -21,5 +26,6 @@ class LoggerData {
} }
} }
/// clear all logger
static clear() => _data.clear(); static clear() => _data.clear();
} }

@ -4,6 +4,7 @@ import 'package:power_logger/src/builders/dio_responses_builder.dart';
import 'package:power_logger/src/builders/dio_error_builder.dart'; import 'package:power_logger/src/builders/dio_error_builder.dart';
import 'package:power_logger/src/parser/unfocus_parser.dart'; import 'package:power_logger/src/parser/unfocus_parser.dart';
///LoggerDataParser
class LoggerDataParser { class LoggerDataParser {
static Widget builder(dynamic data) { static Widget builder(dynamic data) {
if (data is DioError) return DioErrorBuilder(data: data); if (data is DioError) return DioErrorBuilder(data: data);

@ -1,5 +1,6 @@
import 'package:dio/dio.dart'; import 'package:dio/dio.dart';
/// original http content type.
enum ContentType { enum ContentType {
TEXT_PLAIN, TEXT_PLAIN,
TEXT_HTML, TEXT_HTML,
@ -12,13 +13,20 @@ enum ContentType {
UNCATCH, UNCATCH,
} }
/// Dio parse
class DioParser { class DioParser {
Response _response; Response _response;
DioParser(Response response) { DioParser(Response response) {
_response = response; _response = response;
} }
/// get dio request
RequestOptions get request => _response.request; RequestOptions get request => _response.request;
/// get dio response
Response get response => _response; Response get response => _response;
/// get dio contentType
ContentType get type { ContentType get type {
String _ctype = response.headers.map['content-type'].first; String _ctype = response.headers.map['content-type'].first;
switch (_ctype) { switch (_ctype) {
@ -42,6 +50,7 @@ class DioParser {
return ContentType.UNCATCH; return ContentType.UNCATCH;
} }
/// get highlight type.
String get highlight { String get highlight {
switch (type) { switch (type) {
case ContentType.TEXT_HTML: case ContentType.TEXT_HTML:

@ -1,5 +1,6 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
/// UnfocusParser
class UnfocusParser extends StatelessWidget { class UnfocusParser extends StatelessWidget {
final dynamic data; final dynamic data;
const UnfocusParser({Key key, @required this.data}) : super(key: key); const UnfocusParser({Key key, @required this.data}) : super(key: key);

@ -4,11 +4,16 @@ import 'package:flutter/material.dart';
import 'package:power_logger/power_logger.dart'; import 'package:power_logger/power_logger.dart';
class PowerLogger { class PowerLogger {
/// debug tag
static bool debug = true; static bool debug = true;
/// ///
/// ///
///debug ///debug
///
///```dart
///PowerLogger.init(context,debug:true);
///```
static init(BuildContext context, {bool debug = true}) { static init(BuildContext context, {bool debug = true}) {
PowerLogger.debug = debug; PowerLogger.debug = debug;
if (debug) if (debug)
@ -20,6 +25,7 @@ class PowerLogger {
} }
} }
///Logger FAB
class LoggerFAB extends StatefulWidget { class LoggerFAB extends StatefulWidget {
LoggerFAB({Key key}) : super(key: key); LoggerFAB({Key key}) : super(key: key);

@ -1,6 +1,8 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:power_logger/power_logger.dart'; import 'package:power_logger/power_logger.dart';
///Logger view
class PowerLoggerView extends StatefulWidget { class PowerLoggerView extends StatefulWidget {
PowerLoggerView({Key key}) : super(key: key); PowerLoggerView({Key key}) : super(key: key);

@ -1,5 +1,6 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
///BoxView
class BoxView extends StatelessWidget { class BoxView extends StatelessWidget {
final Widget title; final Widget title;
final Widget child; final Widget child;

Loading…
Cancel
Save