begin_add_link.dart 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  1. import 'dart:async';
  2. import 'dart:convert';
  3. import 'package:flutter/material.dart';
  4. import 'package:get/get.dart';
  5. import 'package:link/utils/storage.dart';
  6. import 'package:link/view/component/button.dart';
  7. import 'package:link/view/component/link_btn.dart';
  8. import 'package:link/view/component/marquee.dart';
  9. import 'package:link/view/component/toast.dart';
  10. import '../constants.dart';
  11. import '../utils/api.dart';
  12. import '../utils/http_utils.dart';
  13. import '../utils/size_fit.dart';
  14. import 'component/link_step.dart';
  15. import 'component/top_container.dart';
  16. import 'component/web_image.dart';
  17. import 'package:image_network/image_network.dart';
  18. class BeginAddLink extends StatefulWidget {
  19. const BeginAddLink({Key? key}) : super(key: key);
  20. @override
  21. State<BeginAddLink> createState() => _BeginAddLinkState();
  22. }
  23. class _BeginAddLinkState extends State<BeginAddLink> {
  24. List socials = [];
  25. List socials0 = [],socials1 = [],socials2 = [];
  26. bool isFirstEnter = true;
  27. @override
  28. void initState() {
  29. // TODO: implement initState
  30. Map<String, dynamic> data = Get.parameters;
  31. if (data.isNotEmpty) {
  32. isFirstEnter = data['add_more'] != '1';
  33. }
  34. getLinks();
  35. if (isFirstEnter) {
  36. StorageUtil().setJSON('tempGuideLink0', {});
  37. }
  38. super.initState();
  39. }
  40. Future getLinks() async {
  41. var data = await HttpUtils.get(Api.topSocials);
  42. if (data is List) {
  43. socials = data;
  44. for (int i = 0;i<socials.length;i++){
  45. if (i%3==0){
  46. socials0.add(socials[i]);
  47. }
  48. if (i%3==1){
  49. socials1.add(socials[i]);
  50. }
  51. if (i%3==2){
  52. socials2.add(socials[i]);
  53. }
  54. }
  55. setState(() {
  56. });
  57. // setState(() {
  58. // socials = data;
  59. // });
  60. }
  61. }
  62. addLink(var social) {
  63. Get.toNamed('/add_link', parameters: {
  64. 'social': jsonEncode(social),
  65. 'add_more': isFirstEnter ? '0' : '1'
  66. });
  67. StorageUtil().remove('tempGuideLink0');
  68. }
  69. detail() {
  70. return Column(
  71. children: [
  72. SizedBox(
  73. height: 32.px,
  74. ),
  75. if (isFirstEnter)
  76. Row(mainAxisAlignment: MainAxisAlignment.center, children: [
  77. LinkStep(step: -1, content: '', hasShadow: false),
  78. Container(
  79. width: 60.px,
  80. height: 8.px,
  81. transform: Matrix4.translationValues(-1, 0, 0),
  82. decoration: const BoxDecoration(
  83. gradient: LinearGradient(
  84. begin: Alignment.centerLeft,
  85. end: Alignment.centerRight,
  86. colors: [
  87. Color(0xFF74747A),
  88. Color(0xFF74747A),
  89. kThemeColor
  90. ])),
  91. ),
  92. Container(
  93. transform: Matrix4.translationValues(-2, 0, 0),
  94. child: LinkStep(step: 2, content: '添加我的第 1 个链接', hasShadow: true),
  95. )
  96. ]),
  97. if (isFirstEnter)
  98. SizedBox(
  99. height: 36.px,
  100. ),
  101. Container(
  102. width: 343.px,
  103. height: 408.px,
  104. decoration: BoxDecoration(
  105. color: const Color(0xFF2C2C2E),
  106. borderRadius: BorderRadius.circular(24.px)),
  107. child: Column(
  108. mainAxisAlignment: MainAxisAlignment.start,
  109. crossAxisAlignment: CrossAxisAlignment.start,
  110. children: [
  111. Container(
  112. margin: EdgeInsets.only(top: 22.px, left: 20.px),
  113. child: Text(
  114. '选择要添加的平台',
  115. style: TextStyle(
  116. color: kThemeColor,
  117. fontSize: 20.px,
  118. fontWeight: FontWeight.bold),
  119. ),
  120. ),
  121. Container(
  122. margin: EdgeInsets.only(top: 8.px, left: 20.px),
  123. child: Text(
  124. '点击添加后,该平台将展示在我的主页',
  125. style: TextStyle(
  126. color: const Color(0xFFA5A5AD), fontSize: 12.px),
  127. ),
  128. ),
  129. if (socials0.isNotEmpty)
  130. Container(
  131. margin: EdgeInsets.only(top: 16.px),
  132. height: 72.px,
  133. child: Marquee(
  134. offset: 0.0,
  135. child: Row(
  136. children: [
  137. ...List<Widget>.generate(socials0.length, (i) {
  138. return Container(
  139. margin: EdgeInsets.only(right: 12.px),
  140. child: Button(
  141. child:
  142. // WebImage(
  143. // url: socials[i]['logo'],
  144. // width: 72.px,
  145. // height: 72.px,
  146. // borderRadius: 18.px,
  147. // ),
  148. ClipRRect(
  149. borderRadius: BorderRadius.circular(18.px),
  150. child: Image.network(
  151. socials0[i]['logo'],
  152. width: 72.px,
  153. height: 72.px,
  154. fit: BoxFit.cover,
  155. ),
  156. ),
  157. callback: () {
  158. addLink(socials0[i]);
  159. }),
  160. );
  161. }),
  162. ],
  163. )),
  164. ),
  165. if (socials1.isNotEmpty)
  166. Container(
  167. margin: EdgeInsets.only(top: 16.px),
  168. height: 72.px,
  169. child: Marquee(
  170. offset: 36.px,
  171. child: Row(
  172. children: [
  173. ...List<Widget>.generate(socials1.length, (i) {
  174. return Container(
  175. margin: EdgeInsets.only(right: 12.px),
  176. child: Button(
  177. child:
  178. // WebImage(
  179. // url: socials[i]['logo'],
  180. // width: 72.px,
  181. // height: 72.px,
  182. // borderRadius: 18.px,
  183. // ),
  184. ClipRRect(
  185. borderRadius: BorderRadius.circular(18.px),
  186. child: Image.network(
  187. socials1[i]['logo'],
  188. width: 72.px,
  189. height: 72.px,
  190. fit: BoxFit.cover,
  191. ),
  192. ),
  193. callback: () {
  194. addLink(socials1[i]);
  195. }),
  196. );
  197. }),
  198. ],
  199. )),
  200. ),
  201. if (socials2.isNotEmpty)
  202. Container(
  203. margin: EdgeInsets.only(top: 16.px, bottom: 10.px),
  204. height: 72.px,
  205. child: Marquee(
  206. offset: 0.0,
  207. child: Row(
  208. children: [
  209. ...List<Widget>.generate(socials2.length, (i) {
  210. return Container(
  211. margin: EdgeInsets.only(right: 12.px),
  212. child: Button(
  213. child:
  214. // WebImage(
  215. // url: socials[i]['logo'],
  216. // width: 72.px,
  217. // height: 72.px,
  218. // borderRadius: 18.px,
  219. // ),
  220. ClipRRect(
  221. borderRadius: BorderRadius.circular(18.px),
  222. child: Image.network(
  223. socials2[i]['logo'],
  224. width: 72.px,
  225. height: 72.px,
  226. fit: BoxFit.cover,
  227. ),
  228. ),
  229. callback: () {
  230. addLink(socials2[i]);
  231. }),
  232. );
  233. }),
  234. ],
  235. )),
  236. ),
  237. GestureDetector(
  238. onTap: () {
  239. Get.toNamed('/choose_social',
  240. parameters: {'add_more': isFirstEnter ? '0' : '1'});
  241. },
  242. child: Container(
  243. width: 343.px,
  244. height: 52.px,
  245. alignment: Alignment.center,
  246. child: Text(
  247. '搜索更多',
  248. textAlign: TextAlign.center,
  249. style: TextStyle(color: kBtnColor, fontSize: 14.px),
  250. )),
  251. )
  252. ],
  253. ),
  254. ),
  255. SizedBox(
  256. height: 45.px,
  257. ),
  258. if (!isFirstEnter) Expanded(child: Container()),
  259. LinkButton(
  260. title: '下一步',
  261. disable: false,
  262. isBlack: false,
  263. callback: () {
  264. Toast().showInfoText('请选择平台并添加链接和标题', context: context);
  265. }),
  266. SizedBox(
  267. height: 40.px,
  268. ),
  269. if (isFirstEnter)
  270. GestureDetector(
  271. onTap: () {
  272. var user = StorageUtil().getJSON('userInfo');
  273. // Get.toNamed('/', parameters: {'u': user['id']});
  274. Get.offAllNamed('/', parameters: {'u': user['id']});
  275. StorageUtil().remove('tempGuideLink0');
  276. },
  277. child: Text(
  278. '稍后添加',
  279. style: TextStyle(color: const Color(0xFF74747A), fontSize: 14.px),
  280. ),
  281. ),
  282. if (isFirstEnter)
  283. SizedBox(
  284. height: 40.px,
  285. )
  286. ],
  287. );
  288. }
  289. @override
  290. Widget build(BuildContext context) {
  291. SizeFit.initialize(context);
  292. return Material(
  293. color: kBgColor,
  294. child: TopContainer(
  295. child: Stack(children: [
  296. if (isFirstEnter)
  297. SingleChildScrollView(
  298. child: detail(),
  299. ),
  300. if (!isFirstEnter) detail()
  301. ])));
  302. }
  303. }