You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

124 lines
3.2 KiB

4 years ago
import 'package:dio/dio.dart';
import 'package:flutter/material.dart';
import 'package:power_logger/power_logger.dart';
void main() {
WidgetsFlutterBinding.ensureInitialized();
FlutterError.onError = (details) {
LoggerData.addData(details);
FlutterError.presentError(details);
};
4 years ago
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
4 years ago
title: 'PowerLogger\nDemo',
home: MyHomePage(title: 'PowerLogger Demo'),
//theme: ThemeData.dark(),
4 years ago
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key? key, required this.title}) : super(key: key);
4 years ago
final String title;
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
TextEditingController _textController =
TextEditingController(text: 'https://');
4 years ago
@override
void initState() {
super.initState();
NetTool.init();
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.get(
"https://www.baidu.com/img/PCtm_d9c8750bed0b3c7d089fa7d55720d6cf.png");
PowerLogger.start(context);
LoggerData.addData('TEST', tag: 'TAG');
4 years ago
}
4 years ago
bool loading = false;
String? nullableValue;
@override
void dispose() {
_textController.dispose();
super.dispose();
}
4 years ago
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Column(
children: [
TextButton(
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => Text(nullableValue!)),
);
},
child: Text('FAIL PAGE'),
),
TextField(
controller: _textController,
decoration: InputDecoration(
filled: true,
),
),
],
),
4 years ago
floatingActionButton: FloatingActionButton.extended(
icon: loading
? CircularProgressIndicator(
valueColor: AlwaysStoppedAnimation(Colors.white))
: Icon(Icons.send),
label: Text('发送'),
onPressed: loading
? null
: () async {
loading = true;
setState(() {});
4 years ago
await NetTool.dio.get(_textController.text).catchError((_) {});
4 years ago
loading = false;
setState(() {});
},
4 years ago
),
4 years ago
);
}
}
class NetTool {
static Dio dio = Dio();
static init() {
dio.interceptors.add(InterceptorsWrapper(
onRequest: (options, handler) async {
return handler.next(options);
},
onResponse: (response, handler) async {
LoggerData.addData(response);
return handler.next(response);
},
onError: (DioError e, handler) async {
LoggerData.addData(e);
return handler.next(e);
},
));
}
}