agreement.dart 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. import 'package:eitc_erm_app/utils/Component.dart';
  2. import 'package:eitc_erm_app/utils/Constants.dart';
  3. import 'package:eitc_erm_app/utils/logger.dart';
  4. import 'package:flutter/material.dart';
  5. import 'package:html/parser.dart' as parser;
  6. import 'package:http/http.dart' as http;
  7. import 'bean/normal_response3.dart';
  8. void main() {
  9. WidgetsFlutterBinding.ensureInitialized();
  10. runApp(Agreement());
  11. }
  12. class Agreement extends StatefulWidget {
  13. @override
  14. State<StatefulWidget> createState() => AgreementState();
  15. }
  16. class AgreementState extends State<Agreement> {
  17. ValueNotifier<dynamic> result = ValueNotifier(null);
  18. late Future<NormalResponse3?> _future;
  19. String strHtml = "";
  20. String strHtml1 = "";
  21. String strHtml2 = "";
  22. String strHtml3 = "";
  23. String strHtml4 = "";
  24. String strHtml5 = "";
  25. @override
  26. void initState() {
  27. super.initState();
  28. _future = fetchData();
  29. }
  30. Future<NormalResponse3?> fetchData() async {
  31. Map<String, String> headers = {
  32. 'token': Global.token,
  33. };
  34. final response =
  35. await http.get(Uri.parse('${Global.BaseUrl}api/user-notice'));
  36. if (response.statusCode == 200) {
  37. final json = decodeBodyToJson(response.bodyBytes);
  38. logd(json);
  39. NormalResponse3 mNormalResponse3 = new NormalResponse3.fromJson(json);
  40. if (mNormalResponse3.code == Global.responseSuccessCode) {
  41. int i = 0;
  42. parser.parse(mNormalResponse3.data).body?.children.forEach((element) {
  43. if (i == 0) {
  44. strHtml = element.text;
  45. i++;
  46. } else if (i == 1) {
  47. strHtml1 = element.text;
  48. i++;
  49. } else if (i == 2) {
  50. strHtml2 = element.text;
  51. i++;
  52. } else if (i == 3) {
  53. strHtml3 = element.text;
  54. i++;
  55. } else if (i == 4) {
  56. strHtml4 = element.text;
  57. i++;
  58. } else if (i == 5) {
  59. strHtml5 = element.text;
  60. i++;
  61. }
  62. });
  63. setState(() {});
  64. return mNormalResponse3;
  65. } else {
  66. Component.toast(mNormalResponse3.msg.toString(), 0);
  67. }
  68. return null;
  69. } else {
  70. Component.toast("出错了,请稍后再试!", 0);
  71. return null;
  72. }
  73. }
  74. @override
  75. Widget build(BuildContext context) {
  76. return Scaffold(
  77. appBar: new AppBar(
  78. title: new Text('用户协议',
  79. style: TextStyle(
  80. color: Colors.white,
  81. )),
  82. centerTitle: true,
  83. elevation: 0.5,
  84. backgroundColor: Global.StatusBarColor,
  85. leading: new IconButton(
  86. tooltip: '返回上一页',
  87. icon: const Icon(
  88. Icons.arrow_back_ios,
  89. color: Colors.white,
  90. ),
  91. onPressed: () {
  92. Navigator.of(context).pop();
  93. //_nextPage(-1);
  94. },
  95. ),
  96. ),
  97. body: SingleChildScrollView(
  98. child: Center(
  99. child: Padding(
  100. padding: const EdgeInsets.all(20),
  101. child: Column(children: [
  102. Center(
  103. child: Text(
  104. strHtml,
  105. style: const TextStyle(
  106. fontSize: 18,
  107. color: Colors.black,
  108. ),
  109. ),
  110. ),
  111. Text(
  112. strHtml1 + strHtml2 + strHtml3 + strHtml4 + strHtml5,
  113. style: const TextStyle(
  114. fontSize: 13,
  115. color: Colors.grey,
  116. ),
  117. ),
  118. ]))),
  119. ),
  120. );
  121. }
  122. }