edit_link.dart 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929
  1. import 'dart:convert';
  2. import 'dart:html';
  3. import 'dart:typed_data';
  4. import 'package:dio/dio.dart' as adio;
  5. import 'package:dio/dio.dart';
  6. import 'package:dotted_border/dotted_border.dart';
  7. import 'package:flutter/material.dart';
  8. import 'package:flutter/services.dart';
  9. import 'package:flutter_svg/svg.dart';
  10. import 'package:get/get.dart';
  11. import 'package:link/view/preview.dart';
  12. import 'package:web_smooth_scroll/web_smooth_scroll.dart';
  13. import '../constants.dart';
  14. import '../utils/api.dart';
  15. import '../utils/http_utils.dart';
  16. import '../utils/size_fit.dart';
  17. import '../utils/storage.dart';
  18. import 'component/link_btn.dart';
  19. import 'component/link_step.dart';
  20. import 'component/toast.dart';
  21. import 'component/top_container.dart';
  22. import 'component/upload_file.dart';
  23. import 'component/web_image.dart';
  24. class EditLink extends StatefulWidget {
  25. const EditLink({Key? key}) : super(key: key);
  26. @override
  27. State<EditLink> createState() => _EditLinkState();
  28. }
  29. class _EditLinkState extends State<EditLink> {
  30. TextEditingController controller = TextEditingController();
  31. TextEditingController titleController = TextEditingController();
  32. TextEditingController descController = TextEditingController();
  33. FileUploadInputElement uploadInput = FileUploadInputElement();
  34. bool isLink = true;
  35. bool showError = false;
  36. Uint8List? chooseImage;
  37. String strLink = '';
  38. String strTitle = '';
  39. String strDesc = '';
  40. String imgUrl = '';
  41. bool isFirstEnter = true;
  42. var social;
  43. late List types;
  44. late ScrollController scrollController;
  45. @override
  46. void initState() {
  47. // TODO: implement initState
  48. scrollController = ScrollController();
  49. Map<String, dynamic> data = Get.parameters;
  50. social = jsonDecode(data['social']);
  51. types = social['types'];
  52. if (types[0] == 'LINK') {
  53. isLink = true;
  54. } else {
  55. isLink = false;
  56. }
  57. getDetail();
  58. super.initState();
  59. }
  60. @override
  61. dispose(){
  62. controller.dispose();
  63. titleController.dispose();
  64. descController.dispose();
  65. scrollController.dispose();
  66. super.dispose();
  67. }
  68. chooseFile() async {
  69. uploadInput.accept = '.png,.jpg,.jpeg';
  70. uploadInput.multiple = false;
  71. uploadInput.click();
  72. uploadInput.onChange.listen((e) {
  73. final files = uploadInput.files;
  74. if (files?.length == 1) {
  75. FileReader reader = FileReader();
  76. reader.onLoadEnd.listen((event) {
  77. setState(() {
  78. chooseImage = reader.result as Uint8List;
  79. });
  80. });
  81. reader.readAsArrayBuffer(files![0]);
  82. }
  83. });
  84. }
  85. Future getDetail() async {
  86. String id = Get.parameters['id']!;
  87. var data = await HttpUtils.get(Api.userSocials + '/$id');
  88. setState(() {
  89. if (data['type'] == 'LINK') {
  90. isLink = true;
  91. controller.text = data['user_url'];
  92. strLink = data['user_url'];
  93. } else {
  94. isLink = false;
  95. }
  96. strTitle = data['user_nick'];
  97. titleController.text = data['user_nick'];
  98. strDesc = data['description'];
  99. descController.text = data['description'];
  100. });
  101. }
  102. intro() {
  103. Color tapColor = kBtnColor;
  104. if (isLink) {
  105. if (strLink.isNotEmpty) {
  106. tapColor = const Color(0xFFA5A5AD);
  107. }
  108. } else {
  109. if (chooseImage != null) {
  110. tapColor = const Color(0xFFA5A5AD);
  111. }
  112. }
  113. return Container(
  114. color: showError ? const Color(0xFF002FFF) : Colors.transparent,
  115. padding: EdgeInsets.only(
  116. left: 20.px,
  117. right: 20.px,
  118. top: showError ? 12.px : 0,
  119. bottom: showError ? 12.px : 0),
  120. child: Column(
  121. children: [
  122. Row(
  123. children: [
  124. Container(
  125. width: 12.px,
  126. height: 12.px,
  127. alignment: Alignment.center,
  128. decoration: BoxDecoration(
  129. borderRadius: BorderRadius.circular(6.px),
  130. border: Border.all(color: kThemeColor, width: 1.px)),
  131. child: Text(
  132. '1',
  133. style: TextStyle(
  134. color: kThemeColor,
  135. fontFamily: 'Link1',
  136. fontWeight: FontWeight.w800,
  137. fontSize: 8.px),
  138. ),
  139. ),
  140. SizedBox(
  141. width: 3.px,
  142. ),
  143. Text(
  144. '去『已选平台-我』找到「',
  145. style:
  146. TextStyle(color: const Color(0xFFA5A5AD), fontSize: 12.px),
  147. ),
  148. Text(
  149. isLink ? '分享-复制链接' : '我的二维码',
  150. style: TextStyle(
  151. color: const Color(0xFFA5A5AD),
  152. fontSize: 12.px,
  153. fontWeight: FontWeight.bold),
  154. ),
  155. Text(
  156. isLink ? '」' : '」保存',
  157. style:
  158. TextStyle(color: const Color(0xFFA5A5AD), fontSize: 12.px),
  159. ),
  160. ],
  161. ),
  162. SizedBox(
  163. height: 5.px,
  164. ),
  165. Row(
  166. children: [
  167. Container(
  168. width: 12.px,
  169. height: 12.px,
  170. alignment: Alignment.center,
  171. decoration: BoxDecoration(
  172. borderRadius: BorderRadius.circular(6.px),
  173. border: Border.all(color: kThemeColor, width: 1.px)),
  174. child: Text(
  175. '2',
  176. style: TextStyle(
  177. color: kThemeColor,
  178. fontFamily: 'Link1',
  179. fontWeight: FontWeight.w800,
  180. fontSize: 8.px),
  181. ),
  182. ),
  183. SizedBox(
  184. width: 3.px,
  185. ),
  186. Text(
  187. '回到此处',
  188. style:
  189. TextStyle(color: const Color(0xFFA5A5AD), fontSize: 12.px),
  190. ),
  191. SizedBox(
  192. width: 3.px,
  193. ),
  194. if (!isLink && chooseImage == null)
  195. UploadFile(
  196. child: Text(
  197. '上传二维码',
  198. style: TextStyle(
  199. color: tapColor,
  200. fontSize: 12.px,
  201. fontWeight: FontWeight.bold),
  202. ),
  203. callback: (Uint8List file) {
  204. setState(() {
  205. chooseImage = file;
  206. showError = false;
  207. });
  208. },
  209. ),
  210. if (isLink || (chooseImage != null))
  211. GestureDetector(
  212. onTap: () {
  213. if (isLink) {
  214. if (strLink.isEmpty) {
  215. getClipData();
  216. }
  217. } else {
  218. if (chooseImage == null) {
  219. chooseFile();
  220. }
  221. }
  222. },
  223. child: Text(
  224. isLink ? '粘贴链接' : '上传二维码',
  225. style: TextStyle(
  226. color: tapColor,
  227. fontSize: 12.px,
  228. fontWeight: FontWeight.bold),
  229. ),
  230. )
  231. ],
  232. ),
  233. ],
  234. ),
  235. );
  236. }
  237. switchWarn() {
  238. return Container(
  239. alignment: Alignment.center,
  240. padding: EdgeInsets.only(top: 32.px, bottom: 32.px),
  241. child: Column(
  242. children: [
  243. SvgPicture.asset(
  244. 'assets/icons/question.svg',
  245. width: 48.px,
  246. height: 48.px,
  247. ),
  248. SizedBox(
  249. height: 12.px,
  250. ),
  251. Text(
  252. isLink
  253. ? '切换选择「二维码」\n将使现有「链接」不被展示\n确定要切换吗?'
  254. : '切换选择「链接」\n将使现有「二维码」不被展示\n确定要切换吗?',
  255. textAlign: TextAlign.center,
  256. style: TextStyle(
  257. color: Colors.white,
  258. fontSize: 16.px,
  259. fontWeight: FontWeight.bold),
  260. ),
  261. SizedBox(
  262. height: 16.px,
  263. ),
  264. AlertButton(
  265. title: '确定',
  266. isCancel: false,
  267. width: 220.px,
  268. height: 40.px,
  269. callback: () {
  270. Toast().hideHud();
  271. setState(() {
  272. showError = false;
  273. if (isLink) {
  274. strLink = '';
  275. isLink = false;
  276. } else {
  277. chooseImage = null;
  278. isLink = true;
  279. }
  280. });
  281. }),
  282. SizedBox(
  283. height: 24.px,
  284. ),
  285. AlertButton(
  286. title: '再想想',
  287. isCancel: true,
  288. width: 220.px,
  289. height: 40.px,
  290. callback: () {
  291. Toast().hideHud();
  292. }),
  293. ],
  294. ),
  295. );
  296. }
  297. switchType() {
  298. if (isLink && strLink.isNotEmpty) {
  299. Toast().showCustomHud(switchWarn(), context: context);
  300. return;
  301. }
  302. if (!isLink && chooseImage != null) {
  303. Toast().showCustomHud(switchWarn(), context: context);
  304. return;
  305. }
  306. setState(() {
  307. showError = false;
  308. isLink = !isLink;
  309. });
  310. }
  311. preview() {
  312. Toast().showText('长按图片识别或保存', context: context);
  313. showDialog(
  314. context: context,
  315. barrierDismissible: false,
  316. barrierColor: Colors.transparent,
  317. useSafeArea: false,
  318. builder: (BuildContext context) {
  319. return Preview(
  320. memory: chooseImage,
  321. );
  322. });
  323. }
  324. Future getClipData() async {
  325. await Clipboard.getData(Clipboard.kTextPlain).then((value) {
  326. if (value != null && value.text != null) {
  327. setState(() {
  328. strLink = value.text!;
  329. controller.text = strLink;
  330. });
  331. }
  332. });
  333. }
  334. content() {
  335. return Column(
  336. children: [
  337. SizedBox(
  338. height: 32.px,
  339. ),
  340. Container(
  341. width: 343.px,
  342. padding: EdgeInsets.all(20.px),
  343. margin: EdgeInsets.only(bottom: 20.px),
  344. decoration: BoxDecoration(
  345. color: const Color(0xFF2C2C2E),
  346. borderRadius: BorderRadius.circular(24.px)),
  347. child: GestureDetector(
  348. onTap: () {
  349. Toast().showInfoText('已添加的链接不能更改平台\n建议重新添加新链接\n并删除原有错误的链接',
  350. context: context);
  351. },
  352. child: Row(
  353. children: [
  354. Expanded(
  355. child: Text(
  356. '已选平台',
  357. style: TextStyle(
  358. color: kThemeColor,
  359. fontSize: 16.px,
  360. fontWeight: FontWeight.bold),
  361. )),
  362. // ClipRRect(
  363. // borderRadius: BorderRadius.circular(6.px),
  364. // child: social['logo'].length == 0
  365. // ? SvgPicture.asset(
  366. // 'assets/icons/other_link.svg',
  367. // width: 24.px,
  368. // height: 24.px,
  369. // )
  370. // : WebImage(
  371. // url: social['logo'], width: 24.px, height: 24.px),
  372. // ),
  373. social['logo'].length == 0
  374. ? ClipRRect(
  375. borderRadius: BorderRadius.circular(6.px),
  376. child: SvgPicture.asset(
  377. 'assets/icons/other_link.svg',
  378. width: 24.px,
  379. height: 24.px,
  380. ))
  381. : WebImage(
  382. url: social['logo'],
  383. width: 24.px,
  384. height: 24.px,
  385. borderRadius: 6.px,
  386. ),
  387. SizedBox(
  388. width: 8.px,
  389. ),
  390. Text(
  391. social['name'],
  392. style: TextStyle(
  393. color: const Color(0xFFA5A5AD), fontSize: 14.px),
  394. ),
  395. Image.asset(
  396. 'assets/images/arrow_right.png',
  397. width: 20.px,
  398. height: 20.px,
  399. )
  400. // SvgPicture.asset(
  401. // 'assets/icons/arrow_right.svg',
  402. // width: 20.px,
  403. // height: 20.px,
  404. // color: const Color(0xFFA5A5AD),
  405. // )
  406. ],
  407. )),
  408. ),
  409. Container(
  410. width: 343.px,
  411. padding: EdgeInsets.only(top: 20.px, bottom: 20.px),
  412. margin: EdgeInsets.only(bottom: 20.px),
  413. decoration: BoxDecoration(
  414. color: const Color(0xFF2C2C2E),
  415. borderRadius: BorderRadius.circular(24.px)),
  416. child: Column(
  417. children: [
  418. Row(
  419. children: [
  420. SizedBox(
  421. width: 20.px,
  422. ),
  423. Expanded(
  424. child: Text(
  425. '链接方式',
  426. style: TextStyle(
  427. color: kThemeColor,
  428. fontSize: 16.px,
  429. fontWeight: FontWeight.bold),
  430. )),
  431. Container(
  432. height: 28.px,
  433. // width: 98.px,
  434. decoration: BoxDecoration(
  435. color: const Color(0xFF131314),
  436. borderRadius: BorderRadius.circular(14.px)),
  437. child: Row(
  438. children: [
  439. Container(
  440. padding: EdgeInsets.only(left: 10.px, right: 10.px),
  441. height: 28.px,
  442. decoration: BoxDecoration(
  443. color: kThemeColor,
  444. borderRadius: BorderRadius.circular(14.px)),
  445. child: Row(
  446. children: [
  447. SvgPicture.asset(
  448. isLink
  449. ? 'assets/icons/link.svg'
  450. : 'assets/icons/qrcode.svg',
  451. width: 16.px,
  452. height: 16.px,
  453. color: const Color(0xFF131314),
  454. ),
  455. SizedBox(
  456. width: 2.px,
  457. ),
  458. Text(
  459. isLink ? '链接' : '二维码',
  460. style: TextStyle(
  461. color: const Color(0xFF131314),
  462. fontSize: 12.px),
  463. )
  464. ],
  465. ),
  466. ),
  467. if (types.length > 1)
  468. GestureDetector(
  469. onTap: () {
  470. switchType();
  471. },
  472. child: Container(
  473. alignment: Alignment.center,
  474. width: 36.px,
  475. height: 28.px,
  476. child: SvgPicture.asset(
  477. isLink
  478. ? 'assets/icons/qrcode.svg'
  479. : 'assets/icons/link.svg',
  480. width: 16.px,
  481. height: 16.px,
  482. color: const Color(0xFF74747A),
  483. ),
  484. ),
  485. )
  486. ],
  487. ),
  488. ),
  489. SizedBox(
  490. width: 20.px,
  491. )
  492. ],
  493. ),
  494. SizedBox(
  495. height: 8.px,
  496. ),
  497. intro(),
  498. // SizedBox(
  499. // height: 28.px,
  500. // ),
  501. SizedBox(
  502. height: 16.px,
  503. ),
  504. if (isLink)
  505. Row(
  506. children: [
  507. SizedBox(
  508. width: 20.px,
  509. ),
  510. Expanded(
  511. child: TextField(
  512. controller: controller,
  513. cursorColor: kBtnColor,
  514. onChanged: (value) {
  515. setState(() {
  516. strLink = value;
  517. showError = false;
  518. // keyword = value;
  519. });
  520. },
  521. style: TextStyle(
  522. color: Colors.white,
  523. fontSize: 14.px,
  524. fontFamily: 'Link1'),
  525. decoration: InputDecoration(
  526. border: InputBorder.none,
  527. hintText: '请输入链接',
  528. hintStyle: TextStyle(
  529. fontSize: 14.px, color: const Color(0xFF444447)),
  530. counterText: "",
  531. ),
  532. ),
  533. ),
  534. if (strLink.isEmpty)
  535. GestureDetector(
  536. onTap: () {
  537. getClipData();
  538. },
  539. child: SvgPicture.asset(
  540. 'assets/icons/copy_link.svg',
  541. width: 24.px,
  542. height: 24.px,
  543. color: kBtnColor,
  544. ),
  545. ),
  546. SizedBox(
  547. width: 20.px,
  548. ),
  549. ],
  550. ),
  551. if (!isLink)
  552. Stack(
  553. children: [
  554. DottedBorder(
  555. color: const Color(0xFF444447),
  556. borderType: BorderType.RRect,
  557. radius: Radius.circular(16.px),
  558. child: ClipRRect(
  559. borderRadius: BorderRadius.circular(16.px),
  560. child: Container(
  561. width: 303.px,
  562. alignment: Alignment.center,
  563. padding: EdgeInsets.only(top: 12.px, bottom: 12.px),
  564. child: chooseImage != null
  565. ? GestureDetector(
  566. onTap: () {
  567. preview();
  568. },
  569. child: Image.memory(
  570. chooseImage!,
  571. height: 120.px,
  572. ),
  573. )
  574. : UploadFile(
  575. // width: 120.px,
  576. // height: 120.px,
  577. child: SvgPicture.asset(
  578. 'assets/icons/upload_qrcode.svg',
  579. width: 120.px,
  580. height: 120.px,
  581. ),
  582. callback: (Uint8List file) {
  583. setState(() {
  584. chooseImage = file;
  585. showError = false;
  586. });
  587. },
  588. ),
  589. ),
  590. )),
  591. if (chooseImage != null)
  592. Positioned(
  593. right: 12.px,
  594. top: 12.px,
  595. child: UploadFile(
  596. // width: 68.px,
  597. // height: 28.px,
  598. child: Container(
  599. width: 68.px,
  600. height: 28.px,
  601. alignment: Alignment.center,
  602. decoration: BoxDecoration(
  603. borderRadius: BorderRadius.circular(14.px),
  604. color: const Color(0xBF131314)),
  605. child: Text(
  606. '重新上传',
  607. style: TextStyle(
  608. color: kBtnColor, fontSize: 12.px),
  609. )),
  610. callback: (Uint8List file) {
  611. setState(() {
  612. chooseImage = file;
  613. showError = false;
  614. });
  615. },
  616. ))
  617. // GestureDetector(
  618. // onTap: () {
  619. // chooseFile();
  620. // },
  621. // child: Container(
  622. // width: 68.px,
  623. // height: 28.px,
  624. // alignment: Alignment.center,
  625. // decoration: BoxDecoration(
  626. // borderRadius: BorderRadius.circular(14.px),
  627. // color: const Color(0xBF131314)),
  628. // child: Text(
  629. // '重新上传',
  630. // style: TextStyle(
  631. // color: kBtnColor, fontSize: 12.px),
  632. // )),
  633. // ))
  634. ],
  635. ),
  636. ],
  637. ),
  638. ),
  639. if ((isLink && strLink.isNotEmpty) || (!isLink && chooseImage != null))
  640. Container(
  641. width: 343.px,
  642. padding: EdgeInsets.all(20.px),
  643. margin: EdgeInsets.only(bottom: 20.px),
  644. decoration: BoxDecoration(
  645. color: const Color(0xFF2C2C2E),
  646. borderRadius: BorderRadius.circular(24.px)),
  647. child: Column(
  648. mainAxisAlignment: MainAxisAlignment.start,
  649. crossAxisAlignment: CrossAxisAlignment.start,
  650. children: [
  651. Text(
  652. '标题',
  653. style: TextStyle(
  654. color: kThemeColor,
  655. fontWeight: FontWeight.bold,
  656. fontSize: 16.px,
  657. height: 1.75),
  658. ),
  659. SizedBox(
  660. height: 8.px,
  661. ),
  662. SelectableText(
  663. '填写在我该平台上的用户名,不填将展示平台名称,如:',
  664. style: TextStyle(
  665. color: const Color(0xFFA5A5AD),
  666. fontSize: 12.px,
  667. height: 1.5),
  668. ),
  669. SizedBox(
  670. height: 16.px,
  671. ),
  672. TextField(
  673. cursorColor: kBtnColor,
  674. controller: titleController,
  675. onChanged: (value) {
  676. setState(() {
  677. // keyword = value;
  678. strTitle = value;
  679. });
  680. },
  681. style: TextStyle(color: Colors.white, fontSize: 14.px),
  682. decoration: InputDecoration(
  683. border: InputBorder.none,
  684. hintText: social['url_example'],
  685. hintStyle: TextStyle(
  686. fontSize: 14.px, color: const Color(0xFF444447)),
  687. counterText: "",
  688. ),
  689. ),
  690. Container(
  691. height: 1.px,
  692. color: const Color(0xFF444447),
  693. margin: EdgeInsets.only(top: 18.px, bottom: 18.px),
  694. ),
  695. Text(
  696. '描述',
  697. style: TextStyle(
  698. color: kThemeColor,
  699. fontWeight: FontWeight.bold,
  700. fontSize: 16.px,
  701. height: 1.75),
  702. ),
  703. SizedBox(
  704. height: 8.px,
  705. ),
  706. Text(
  707. '对以上内容的补充描述,如:',
  708. style: TextStyle(
  709. color: const Color(0xFFA5A5AD),
  710. fontSize: 12.px,
  711. height: 1.5),
  712. ),
  713. SizedBox(
  714. height: 16.px,
  715. ),
  716. TextField(
  717. cursorColor: kBtnColor,
  718. controller: descController,
  719. onChanged: (value) {
  720. setState(() {
  721. strDesc = value;
  722. // keyword = value;
  723. });
  724. },
  725. style: TextStyle(color: Colors.white, fontSize: 14.px),
  726. decoration: InputDecoration(
  727. border: InputBorder.none,
  728. hintText: social['description_example'],
  729. hintStyle: TextStyle(
  730. fontSize: 14.px, color: const Color(0xFF444447)),
  731. counterText: "",
  732. ),
  733. ),
  734. ],
  735. )),
  736. SizedBox(
  737. height: 162.px,
  738. )
  739. ],
  740. );
  741. }
  742. Future del() async {
  743. String id = Get.parameters['id']!;
  744. await HttpUtils.delete(Api.userSocials + '/$id');
  745. Get.back();
  746. }
  747. Future commit() async {
  748. String id = Get.parameters['id']!;
  749. if (isLink && strLink.isEmpty) {
  750. Toast().showInfoText('请粘贴链接地址后再提交\n或选择“稍后添加”', context: context);
  751. setState(() {
  752. showError = true;
  753. });
  754. return;
  755. }
  756. if (!isLink && chooseImage == null && imgUrl.isEmpty) {
  757. Toast().showInfoText('请上传二维码后再提交\n或选择“稍后添加”', context: context);
  758. setState(() {
  759. showError = true;
  760. });
  761. return;
  762. }
  763. Toast().showHud(context: context);
  764. if (isLink) {
  765. var data2 = await HttpUtils.put(Api.userSocials + '/$id', data: {
  766. 'user_url': strLink,
  767. 'description': strDesc,
  768. 'social_id': social['id'],
  769. 'social_name': social['id'].length == 0 ? social['name'] : '',
  770. 'type': 'LINK',
  771. 'user_nick': strTitle
  772. });
  773. } else {
  774. Map<String, dynamic> data = await HttpUtils.get(Api.ossFormUpload,
  775. params: {'type': 'AVATAR', 'file_ext': 'png'});
  776. Dio dio = Dio();
  777. Map<String, dynamic> map = data['fields'];
  778. map['file'] = await adio.MultipartFile.fromBytes(chooseImage!,
  779. filename: 'avatar.png');
  780. adio.FormData formData = adio.FormData.fromMap(map);
  781. adio.Response response =
  782. await dio.post(data['upload_url'], data: formData);
  783. var data2 = await HttpUtils.put(Api.userSocials + '/$id', data: {
  784. 'user_url': data['view_url'],
  785. 'description': strDesc,
  786. 'social_id': social['id'],
  787. 'social_name': social['id'].length == 0 ? social['name'] : '',
  788. 'type': 'QR',
  789. 'user_nick': strTitle
  790. });
  791. }
  792. Toast().hideHud();
  793. Get.back();
  794. }
  795. tapDelete() {
  796. Toast().showCustomHud(
  797. Container(
  798. alignment: Alignment.center,
  799. padding: EdgeInsets.only(top: 32.px, bottom: 32.px),
  800. child: Column(
  801. children: [
  802. Text(
  803. '删除此链接后,将无法恢复,\n确定要删除吗?',
  804. style: TextStyle(
  805. color: Colors.white,
  806. fontSize: 16.px,
  807. fontWeight: FontWeight.bold),
  808. ),
  809. SizedBox(
  810. height: 16.px,
  811. ),
  812. AlertButton(
  813. title: '确定,立即删除',
  814. isCancel: false,
  815. width: 220.px,
  816. height: 40.px,
  817. callback: () {
  818. Toast().hideHud();
  819. del();
  820. }),
  821. SizedBox(
  822. height: 24.px,
  823. ),
  824. AlertButton(
  825. title: '取消,再想想',
  826. isCancel: true,
  827. width: 220.px,
  828. height: 40.px,
  829. callback: () {
  830. Toast().hideHud();
  831. }),
  832. ],
  833. ),
  834. ),
  835. context: context);
  836. }
  837. @override
  838. Widget build(BuildContext context) {
  839. SizeFit.initialize(context);
  840. return Material(
  841. color: kBgColor,
  842. child: TopContainer(
  843. child: Stack(children: [
  844. Positioned(
  845. left: 0,
  846. top: 0,
  847. right: 0,
  848. height: MediaQuery.of(context).size.height,
  849. // bottom: 0,
  850. child: WebSmoothScroll(
  851. controller: scrollController,
  852. child: SingleChildScrollView(
  853. // physics: const NeverScrollableScrollPhysics(),
  854. controller: scrollController,
  855. child: content(),
  856. ))),
  857. Positioned(
  858. left: 0,
  859. right: 0,
  860. bottom: 0,
  861. child: Container(
  862. height: isFirstEnter ? 162.px : 140.px,
  863. decoration: const BoxDecoration(
  864. gradient: LinearGradient(
  865. begin: Alignment.topCenter,
  866. end: Alignment.bottomCenter,
  867. colors: [
  868. Color(0x00131314),
  869. Color(0xFF131314),
  870. Color(0xFF131314),
  871. ])),
  872. child: Column(
  873. children: [
  874. SizedBox(
  875. height: 36.px,
  876. ),
  877. LinkButton(
  878. title: '保存修改',
  879. disable: false,
  880. isBlack: false,
  881. callback: () {
  882. commit();
  883. }),
  884. SizedBox(
  885. height: 30.px,
  886. ),
  887. GestureDetector(
  888. onTap: () {
  889. tapDelete();
  890. },
  891. child: Text(
  892. '删除已选账号',
  893. style: TextStyle(
  894. color: const Color(0xFF74747A), fontSize: 14.px),
  895. ),
  896. )
  897. ],
  898. ),
  899. ))
  900. ])));
  901. }
  902. }