country_detail.dart 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. import 'dart:html';
  2. import 'package:flutter/material.dart';
  3. import 'package:flutter_screenutil/flutter_screenutil.dart';
  4. import 'package:fuwei/utils/dio_util.dart';
  5. import 'package:webviewx/webviewx.dart';
  6. import '../utils/common_util.dart';
  7. class CountryDetailWidget extends StatelessWidget {
  8. CountryDetailWidget(this.countryId, {super.key});
  9. final int countryId;
  10. var countryTitleTextSize = 0.0;
  11. var countryPicWidth = 0.0;
  12. var countryPicHeight = 0.0;
  13. var padding = 0.0;
  14. var height = 0.0;
  15. var textSize = 0.0;
  16. var textSize2 = 0.0;
  17. var textSize3 = 0.0;
  18. var itemHeight = 0.0;
  19. var topMarin = 0.0;
  20. var bottomMarin = 0.0;
  21. var htmlHeight = 0.0;
  22. @override
  23. Widget build(BuildContext context) {
  24. if (Util.isWeb()) {
  25. countryTitleTextSize = 20.sp;
  26. countryPicWidth = 210.w;
  27. countryPicHeight = 140.w;
  28. padding = 0.3.sw;
  29. height = 30.h;
  30. textSize = 24.sp;
  31. textSize2 = 24.sp;
  32. textSize3 = 24.sp;
  33. itemHeight = 50.h;
  34. topMarin = 30.r;
  35. bottomMarin = 10.r;
  36. htmlHeight = 100.r;
  37. } else {
  38. countryTitleTextSize = 72.sp;
  39. countryPicWidth = 600.w;
  40. countryPicHeight = 400.w;
  41. padding = 0.1.sw;
  42. height = 40.h;
  43. textSize = 72.sp;
  44. textSize2 = 72.sp;
  45. textSize3 = 72.sp;
  46. itemHeight = 80.h;
  47. topMarin = 60.r;
  48. bottomMarin = 30.r;
  49. htmlHeight = 100;
  50. }
  51. return FutureBuilder(
  52. future: NetworkUtil().getCountryDetail(countryId),
  53. builder: (context, snapshot) {
  54. if (snapshot.connectionState == ConnectionState.done) {
  55. if (snapshot.hasData) {
  56. return Padding(
  57. padding: EdgeInsets.only(left: padding, right: padding),
  58. child: Column(
  59. mainAxisAlignment: MainAxisAlignment.center,
  60. children: [
  61. Expanded(
  62. flex: 1,
  63. child: Column(
  64. children: [
  65. Container(
  66. margin: EdgeInsets.only(top: 100.r),
  67. child: Row(
  68. mainAxisAlignment: MainAxisAlignment.center,
  69. children: [
  70. Text(
  71. snapshot.data?.countryName ?? "",
  72. style: TextStyle(
  73. fontSize: countryTitleTextSize,
  74. fontWeight: FontWeight.bold,
  75. color: Colors.black),
  76. ),
  77. Padding(
  78. padding: EdgeInsets.only(left: 10),
  79. child: Image(
  80. fit: BoxFit.fill,
  81. image: NetworkImage(
  82. snapshot.data?.countryImgUrl ?? ""),
  83. width: countryPicWidth,
  84. height: countryPicHeight,
  85. ),
  86. )
  87. ],
  88. ),
  89. ),
  90. Container(
  91. alignment: Alignment.centerLeft,
  92. color: Colors.grey[200],
  93. height: height,
  94. margin: EdgeInsets.only(
  95. top: topMarin, bottom: bottomMarin),
  96. child: Text(
  97. "签证须知:",
  98. style: TextStyle(
  99. fontSize: textSize,
  100. color: Colors.red,
  101. fontWeight: FontWeight.bold),
  102. ),
  103. ),
  104. Container(
  105. width: 0.8.sw,
  106. child: WebViewX(
  107. width: 0.6.sw,
  108. height: htmlHeight,
  109. initialContent:
  110. snapshot.data?.countryContent ?? "",
  111. initialSourceType: SourceType.html,
  112. ),
  113. ),
  114. Expanded(
  115. flex: 1,
  116. child: ListView.builder(
  117. itemExtent: itemHeight,
  118. itemCount:
  119. snapshot.data?.countryVisitVisaUrl.length ??
  120. 0,
  121. itemBuilder: (context, index) {
  122. return ListTile(
  123. title: TextButton(
  124. onPressed: () {
  125. if (snapshot.data != null &&
  126. snapshot.data!.countryVisitVisaUrl
  127. .isNotEmpty) {
  128. downLoadFile(snapshot
  129. .data!
  130. .countryVisitVisaUrl[index]
  131. .fileUrl);
  132. }
  133. },
  134. child: Text(
  135. snapshot
  136. .data
  137. ?.countryVisitVisaUrl[index]
  138. .fileName ??
  139. "",
  140. style: TextStyle(
  141. fontSize: textSize3,
  142. color: Colors.red,
  143. fontWeight: FontWeight.bold)),
  144. ),
  145. );
  146. }),
  147. )
  148. ],
  149. ),
  150. ),
  151. ],
  152. ),
  153. );
  154. } else {
  155. return Text("Error:${snapshot.error}");
  156. }
  157. } else {
  158. return Container(
  159. alignment: Alignment.center,
  160. child: const CircularProgressIndicator(),
  161. );
  162. }
  163. });
  164. }
  165. ///调用浏览器的下载功能下载文件
  166. downLoadFile(url) {
  167. AnchorElement anchorElement = AnchorElement(href: url);
  168. anchorElement.download = "资料";
  169. anchorElement.click();
  170. }
  171. }