country_detail.dart 6.6 KB

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