agreement.dart 3.8 KB

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