From 34e828dfed89ba6b98c35e271dd236bb106d1a1c Mon Sep 17 00:00:00 2001 From: laiiihz Date: Mon, 29 Mar 2021 16:40:30 +0800 Subject: [PATCH 1/2] update example file and fix contentType change --- .fvm/fvm_config.json | 3 +++ example/lib/main.dart | 27 ++++++++++++++++++----- lib/src/parser/dio_parser/dio_parser.dart | 18 +++++---------- 3 files changed, 30 insertions(+), 18 deletions(-) create mode 100644 .fvm/fvm_config.json diff --git a/.fvm/fvm_config.json b/.fvm/fvm_config.json new file mode 100644 index 0000000..8971807 --- /dev/null +++ b/.fvm/fvm_config.json @@ -0,0 +1,3 @@ +{ + "flutterSdkVersion": "1.22.6" +} \ No newline at end of file diff --git a/example/lib/main.dart b/example/lib/main.dart index 2274a4b..e144fc8 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -25,6 +25,8 @@ class MyHomePage extends StatefulWidget { } class _MyHomePageState extends State { + TextEditingController _textController = + TextEditingController(text: 'https://'); @override void initState() { super.initState(); @@ -32,26 +34,39 @@ class _MyHomePageState extends State { NetTool.dio.get("https://192.168.31.255:8888"); NetTool.dio.get("https://www.baidu.com", queryParameters: {'test': 'test'}); NetTool.dio.get("https://www.baidu.com/ahefbawfbe.html"); - NetTool.dio.post( - "https://www.baidu.com/ahefbawfbe.html", - data: FormData.fromMap({'test': 'test'}), - ); - + NetTool.dio.post("https://www.baidu.com/ahefbawfbe.html", + data: FormData.fromMap({'test': 'test'})); NetTool.dio.get( "https://www.baidu.com/img/PCtm_d9c8750bed0b3c7d089fa7d55720d6cf.png"); PowerLogger.start(context); LoggerData.addData('TEST'); } + @override + void dispose() { + _textController?.dispose(); + super.dispose(); + } + @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text(widget.title), ), + body: Container( + padding: EdgeInsets.all(10), + alignment: Alignment.center, + child: TextField( + controller: _textController, + decoration: InputDecoration( + filled: true, + ), + ), + ), floatingActionButton: FloatingActionButton( onPressed: () { - NetTool.dio.get("https://www.baidu.com"); + NetTool.dio.get(_textController.text); }, ), ); diff --git a/lib/src/parser/dio_parser/dio_parser.dart b/lib/src/parser/dio_parser/dio_parser.dart index 9e7b805..e3663d7 100644 --- a/lib/src/parser/dio_parser/dio_parser.dart +++ b/lib/src/parser/dio_parser/dio_parser.dart @@ -29,18 +29,12 @@ class DioParser { /// get dio contentType ContentType get type { String _ctype = response.headers.map['content-type'].first; - switch (_ctype) { - case 'text/plain': - return ContentType.TEXT_PLAIN; - case 'text/html': - return ContentType.TEXT_HTML; - case 'text/css': - return ContentType.TEXT_CSS; - case 'text/javascript': - return ContentType.TEXT_JS; - case 'application/json': - return ContentType.JSON; - } + + if (_ctype.contains('text/plain')) return ContentType.TEXT_PLAIN; + if (_ctype.contains('text/html')) return ContentType.TEXT_HTML; + if (_ctype.contains('text/css')) return ContentType.TEXT_CSS; + if (_ctype.contains('text/javascript')) return ContentType.TEXT_JS; + if (_ctype.contains('application/json')) return ContentType.JSON; if (_ctype.contains('image/')) return ContentType.IMAGE; if (_ctype.contains('audio/')) return ContentType.AUDIO; if (_ctype.contains('video/')) return ContentType.VIDEO; From 93a47d0b3c21df14cfaaee6797662228cb69ead7 Mon Sep 17 00:00:00 2001 From: laiiihz Date: Tue, 30 Mar 2021 16:05:38 +0800 Subject: [PATCH 2/2] update example --- example/lib/main.dart | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/example/lib/main.dart b/example/lib/main.dart index e144fc8..1d78a8d 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -10,8 +10,8 @@ class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( - title: 'Flutter Demo', - home: MyHomePage(title: 'Flutter Demo Home Page'), + title: 'PowerLogger\nDemo', + home: MyHomePage(title: 'PowerLogger Demo'), ); } } @@ -42,6 +42,8 @@ class _MyHomePageState extends State { LoggerData.addData('TEST'); } + bool loading = false; + @override void dispose() { _textController?.dispose(); @@ -64,10 +66,21 @@ class _MyHomePageState extends State { ), ), ), - floatingActionButton: FloatingActionButton( - onPressed: () { - NetTool.dio.get(_textController.text); - }, + floatingActionButton: FloatingActionButton.extended( + icon: loading + ? CircularProgressIndicator( + valueColor: AlwaysStoppedAnimation(Colors.white)) + : Icon(Icons.send), + label: Text('发送'), + onPressed: loading + ? null + : () async { + loading = true; + setState(() {}); + await NetTool.dio.get(_textController.text); + loading = false; + setState(() {}); + }, ), ); }