country_detail.dart 6.7 KB

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