update example file and fix contentType change

master
小赖 4 years ago
parent f717611a45
commit 34e828dfed

@ -0,0 +1,3 @@
{
"flutterSdkVersion": "1.22.6"
}

@ -25,6 +25,8 @@ class MyHomePage extends StatefulWidget {
} }
class _MyHomePageState extends State<MyHomePage> { class _MyHomePageState extends State<MyHomePage> {
TextEditingController _textController =
TextEditingController(text: 'https://');
@override @override
void initState() { void initState() {
super.initState(); super.initState();
@ -32,26 +34,39 @@ class _MyHomePageState extends State<MyHomePage> {
NetTool.dio.get("https://192.168.31.255:8888"); 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", queryParameters: {'test': 'test'});
NetTool.dio.get("https://www.baidu.com/ahefbawfbe.html"); NetTool.dio.get("https://www.baidu.com/ahefbawfbe.html");
NetTool.dio.post( NetTool.dio.post("https://www.baidu.com/ahefbawfbe.html",
"https://www.baidu.com/ahefbawfbe.html", data: FormData.fromMap({'test': 'test'}));
data: FormData.fromMap({'test': 'test'}),
);
NetTool.dio.get( NetTool.dio.get(
"https://www.baidu.com/img/PCtm_d9c8750bed0b3c7d089fa7d55720d6cf.png"); "https://www.baidu.com/img/PCtm_d9c8750bed0b3c7d089fa7d55720d6cf.png");
PowerLogger.start(context); PowerLogger.start(context);
LoggerData.addData('TEST'); LoggerData.addData('TEST');
} }
@override
void dispose() {
_textController?.dispose();
super.dispose();
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return Scaffold(
appBar: AppBar( appBar: AppBar(
title: Text(widget.title), title: Text(widget.title),
), ),
body: Container(
padding: EdgeInsets.all(10),
alignment: Alignment.center,
child: TextField(
controller: _textController,
decoration: InputDecoration(
filled: true,
),
),
),
floatingActionButton: FloatingActionButton( floatingActionButton: FloatingActionButton(
onPressed: () { onPressed: () {
NetTool.dio.get("https://www.baidu.com"); NetTool.dio.get(_textController.text);
}, },
), ),
); );

@ -29,18 +29,12 @@ class DioParser {
/// get dio contentType /// 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) {
case 'text/plain': if (_ctype.contains('text/plain')) return ContentType.TEXT_PLAIN;
return ContentType.TEXT_PLAIN; if (_ctype.contains('text/html')) return ContentType.TEXT_HTML;
case 'text/html': if (_ctype.contains('text/css')) return ContentType.TEXT_CSS;
return ContentType.TEXT_HTML; if (_ctype.contains('text/javascript')) return ContentType.TEXT_JS;
case 'text/css': if (_ctype.contains('application/json')) return ContentType.JSON;
return ContentType.TEXT_CSS;
case 'text/javascript':
return ContentType.TEXT_JS;
case 'application/json':
return ContentType.JSON;
}
if (_ctype.contains('image/')) return ContentType.IMAGE; if (_ctype.contains('image/')) return ContentType.IMAGE;
if (_ctype.contains('audio/')) return ContentType.AUDIO; if (_ctype.contains('audio/')) return ContentType.AUDIO;
if (_ctype.contains('video/')) return ContentType.VIDEO; if (_ctype.contains('video/')) return ContentType.VIDEO;

Loading…
Cancel
Save