test_network.dart 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. import 'dart:convert';
  2. import 'dart:io';
  3. import 'package:dio/dio.dart';
  4. import 'package:flutter/material.dart';
  5. import 'package:get_it/get_it.dart';
  6. import 'package:sport/bean/login.dart';
  7. import 'package:sport/services/api/login_api.dart';
  8. import 'package:webview_flutter/webview_flutter.dart';
  9. class TestNetworkPage extends StatelessWidget{
  10. _test1 () async{
  11. var dio = Dio();
  12. var response = await dio.get("https://www.baidu.com");
  13. return response.data;
  14. }
  15. _test2() async{
  16. var dio = Dio();
  17. var response = await dio.get("https://shoes-api.funfet.com");
  18. return response.data;
  19. }
  20. _test3 () async{
  21. HttpClient _client = HttpClient();
  22. var request = await _client.getUrl(Uri.parse("https://www.baidu.com"));
  23. var response = await request.close();
  24. return response.transform(utf8.decoder).join();
  25. }
  26. _test4 () async{
  27. HttpClient _client = HttpClient();
  28. var request = await _client.getUrl(Uri.parse("https://shoes-api.funfet.com"));
  29. var response = await request.close();
  30. return response.transform(utf8.decoder).join();
  31. }
  32. _test6() async{
  33. var dio = GetIt.I<Dio>();
  34. var response = await dio.get("https://shoes-api.funfet.com");
  35. return response.data;
  36. }
  37. Future<LoginInfo> _test5() async{
  38. var api = GetIt.I<LoginApi>();
  39. var response = await api.getLoginInfo("18502088330", password: "123456");
  40. print("1111111111111111122222222222222 ${response}");
  41. return response;
  42. }
  43. @override
  44. Widget build(BuildContext context) {
  45. return Scaffold(body: SingleChildScrollView(child: Column(children: [
  46. Container(
  47. height: 150,
  48. child: WebView(initialUrl: "https://www.baidu.com",),),
  49. const Divider(color: Colors.red,),
  50. Container(
  51. height: 50,
  52. child: WebView(initialUrl: "https://shoes-api.funfet.com",),),
  53. const Divider(color: Colors.red,),
  54. Container(
  55. height: 50,
  56. child: FutureBuilder(
  57. future: _test1(),
  58. builder: (_, snapshot){
  59. return Text("百度dio:${snapshot.data}");
  60. }),
  61. ),
  62. const Divider(color: Colors.red,),
  63. Container(
  64. height: 50,
  65. child: FutureBuilder(
  66. future: _test3(),
  67. builder: (_, snapshot){
  68. return Text("百度http:${snapshot.data}");
  69. }),
  70. ),
  71. const Divider(color: Colors.red,),
  72. Container(
  73. height: 50,
  74. child: FutureBuilder(
  75. future: _test2(),builder: (_, snapshot){
  76. return Text("趣动dio:${snapshot.data}");
  77. }),
  78. ),
  79. const Divider(color: Colors.red,),
  80. Container(
  81. height: 50,
  82. child: FutureBuilder(
  83. future: _test4(),builder: (_, snapshot){
  84. return Text("趣动http:${snapshot.data}");
  85. }),
  86. ),const Divider(color: Colors.red,),
  87. Container(
  88. height: 50,
  89. child: FutureBuilder(
  90. future: _test6(),builder: (_, snapshot){
  91. return Text("趣动get dio:${snapshot.data}");
  92. }),
  93. ),
  94. const Divider(color: Colors.red,),
  95. Container(
  96. height: 50,
  97. child: FutureBuilder<LoginInfo>(
  98. future: _test5(),builder: (_, snapshot){
  99. return Text("趣动get api:${snapshot.data?.code} ${snapshot.data?.msg}");
  100. }),
  101. ),
  102. ],),),);
  103. }
  104. }