|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333 |
- part of let_log;
-
- class NetWidget extends StatefulWidget {
- const NetWidget({Key key}) : super(key: key);
-
- @override
- _NetWidgetState createState() => _NetWidgetState();
- }
-
- class _NetWidgetState extends State<NetWidget> {
- bool _showSearch = false;
- String _keyword = "";
- TextEditingController _textController;
- ScrollController _scrollController;
- FocusNode _focusNode;
- bool _goDown = true;
-
- @override
- void initState() {
- _textController = TextEditingController(text: _keyword);
- _scrollController = ScrollController();
- _focusNode = FocusNode();
- super.initState();
- }
-
- @override
- void dispose() {
- _textController.dispose();
- _scrollController.dispose();
- super.dispose();
- }
-
- @override
- Widget build(BuildContext context) {
- return Scaffold(
- body: Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: <Widget>[
- ValueListenableBuilder<int>(
- valueListenable: _Net.typeLength,
- builder: (context, value, child) {
- return _buildTools();
- },
- ),
- Expanded(
- child: ValueListenableBuilder<int>(
- valueListenable: _Net.length,
- builder: (context, value, child) {
- List<_Net> logs = _Net.list;
- if (!_selectTypes.contains(_Net.all)) {
- logs = _Net.list.where((test) {
- return _selectTypes.contains(test.type) &&
- test.contains(_keyword);
- }).toList();
- } else if (_keyword.isNotEmpty) {
- logs = _Net.list.where((test) {
- return test.contains(_keyword);
- }).toList();
- }
-
- final len = logs.length;
- return ListView.separated(
- itemBuilder: (context, index) {
- final item = Logger.config.reverse
- ? logs[len - index - 1]
- : logs[index];
- return _buildItem(item, context);
- },
- itemCount: len,
- controller: _scrollController,
- reverse: Logger.config.reverse,
- separatorBuilder: (context, index) {
- return const Divider(
- height: 10,
- thickness: 0.5,
- color: Color(0xFFE0E0E0),
- );
- },
- );
- },
- ),
- ),
- ],
- ),
- floatingActionButton: FloatingActionButton(
- onPressed: () {
- if (_goDown) {
- _scrollController.animateTo(
- _scrollController.position.maxScrollExtent * 2,
- curve: Curves.easeOut,
- duration: const Duration(milliseconds: 300),
- );
- } else {
- _scrollController.animateTo(
- 0,
- curve: Curves.easeOut,
- duration: const Duration(milliseconds: 300),
- );
- }
- _goDown = !_goDown;
- setState(() {});
- },
- mini: true,
- child: Icon(
- _goDown ? Icons.arrow_downward : Icons.arrow_upward,
- ),
- ),
- );
- }
-
- Widget _buildItem(_Net item, context) {
- final color = _getColor(item.status);
- return InkWell(
- onTap: () {
- item.showDetail = !item.showDetail;
- setState(() {});
- },
- child: Padding(
- padding: const EdgeInsets.fromLTRB(16, 8, 16, 0),
- child: Row(
- children: [
- Expanded(
- child: Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- Text(
- "[${item.type}] ${item.api}",
- style: const TextStyle(fontSize: 16),
- ),
- // if (item.showDetail)
- Visibility(
- visible: item.showDetail,
- child: Padding(
- padding: const EdgeInsets.only(top: 8),
- child: Text(
- "Request: ${item.req ?? ""}",
- maxLines: 100,
- overflow: TextOverflow.ellipsis,
- style: const TextStyle(fontSize: 14),
- ),
- ),
- ),
- // if (item.showDetail)
- Visibility(
- visible: item.showDetail,
- child: Padding(
- padding: const EdgeInsets.only(top: 8),
- child: Text(
- "Response: ${item.res ?? ""}",
- maxLines: 100,
- overflow: TextOverflow.ellipsis,
- style: const TextStyle(fontSize: 14),
- ),
- ),
- ),
- // if (item.showDetail && item.headers != null)
- Visibility(
- visible: (item.showDetail && item.headers != null),
- child: Padding(
- padding: const EdgeInsets.only(top: 8),
- child: Text(
- "Headers: ${item.headers ?? ""}",
- maxLines: 100,
- overflow: TextOverflow.ellipsis,
- style: const TextStyle(fontSize: 14),
- ),
- ),
- ),
- Padding(
- padding: const EdgeInsets.only(top: 8, bottom: 8),
- child: Row(
- children: [
- SizedBox(
- width: 120,
- child: Text(
- "${item.start.hour}:${item.start.minute}:${item.start.second}:${item.start.millisecond}",
- style: const TextStyle(fontSize: 14),
- maxLines: 1,
- ),
- ),
- SizedBox(
- width: 100,
- child: Text(
- "${item.spend ?? "0"} ms",
- style: const TextStyle(fontSize: 14),
- overflow: TextOverflow.visible,
- maxLines: 1,
- ),
- ),
- Text(
- "${item.getReqSize()}/${item.getResSize()}B",
- style: const TextStyle(fontSize: 14),
- overflow: TextOverflow.visible,
- maxLines: 1,
- ),
- ],
- ),
- )
- ],
- ),
- ),
- InkWell(
- onTap: () {
- final ClipboardData data = ClipboardData(text: item.toString());
- Clipboard.setData(data);
- showDialog(
- context: context,
- barrierDismissible: true,
- builder: (context) {
- return const Center(
- child: Material(
- color: Colors.transparent,
- child: Text(
- "copy success!",
- style: TextStyle(color: Colors.white, fontSize: 30),
- ),
- ),
- );
- },
- );
- },
- child: Column(
- mainAxisAlignment: MainAxisAlignment.spaceEvenly,
- children: [
- Text(
- item.status.toString(),
- style: TextStyle(fontSize: 20, color: color),
- ),
- // if (item.showDetail)
- Visibility(
- visible: item.showDetail,
- child: const Text(
- "copy",
- style: TextStyle(fontSize: 16, color: Colors.blue),
- ),
- ),
- ],
- ),
- ),
- ],
- ),
- ),
- );
- }
-
- Color _getColor(int status) {
- if (status == 200 || status == 0) {
- return Colors.green;
- } else if (status < 200) {
- return Colors.blue;
- } else {
- return Colors.red;
- }
- }
-
- final List<String> _selectTypes = [_Net.all];
-
- Widget _buildTools() {
- final List<ChoiceChip> arr = [];
- _Net.types.forEach((f) {
- arr.add(
- ChoiceChip(
- label: Text(f, style: const TextStyle(fontSize: 14)),
- selectedColor: const Color(0xFFCBE2F6),
- selected: _selectTypes.contains(f),
- onSelected: (value) {
- _selectTypes.contains(f)
- ? _selectTypes.remove(f)
- : _selectTypes.add(f);
- setState(() {});
- },
- ),
- );
- });
- return Padding(
- padding: const EdgeInsets.fromLTRB(16, 5, 0, 5),
- child: AnimatedCrossFade(
- crossFadeState:
- _showSearch ? CrossFadeState.showSecond : CrossFadeState.showFirst,
- duration: const Duration(milliseconds: 300),
- firstChild: Row(
- children: [
- Expanded(
- child: Wrap(
- spacing: 5,
- children: arr,
- ),
- ),
- const IconButton(
- icon: Icon(Icons.clear),
- onPressed: _Net.clear,
- ),
- IconButton(
- icon: _keyword.isEmpty
- ? const Icon(Icons.search)
- : const Icon(Icons.filter_1),
- onPressed: () {
- _showSearch = true;
- setState(() {});
- _focusNode.requestFocus();
- },
- ),
- ],
- ),
- secondChild: Row(
- children: [
- Expanded(
- child: SizedBox(
- height: 36,
- child: TextField(
- decoration: const InputDecoration(
- border: OutlineInputBorder(),
- contentPadding: EdgeInsets.all(6),
- ),
- controller: _textController,
- focusNode: _focusNode,
- ),
- ),
- ),
- IconButton(
- icon: const Icon(Icons.search),
- onPressed: () {
- _showSearch = false;
- _keyword = _textController.text;
- setState(() {});
- },
- ),
- ],
- ),
- ),
- );
- }
- }
|