Hibok
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

153 lines
4.9 KiB

  1. import 'package:cached_network_image/cached_network_image.dart';
  2. import 'package:chat/data/UserData.dart';
  3. import 'package:chat/data/WebData.dart';
  4. import 'package:chat/data/constants.dart';
  5. import 'package:chat/generated/i18n.dart';
  6. import 'package:chat/utils/CustomUI.dart';
  7. import 'package:chat/utils/HttpUtil.dart';
  8. import 'package:chat/utils/MessageMgr.dart';
  9. import 'package:chat/utils/TokenMgr.dart';
  10. import 'package:dio/dio.dart';
  11. import 'package:flutter/material.dart';
  12. class MoneyPicture extends StatefulWidget {
  13. @required
  14. final List imageList;
  15. MoneyPicture({Key key, this.imageList}) : super(key: key);
  16. _MoneyPictureState createState() => _MoneyPictureState();
  17. }
  18. class _MoneyPictureState extends State<MoneyPicture> {
  19. int selectId = 0;
  20. int originalMoneyId = 0;
  21. Widget _buildImg(data) {
  22. var width = (MediaQuery.of(context).size.width - 30) / 3;
  23. return InkWell(
  24. onTap: () {
  25. this.setState(() {
  26. if (selectId == data['Id']) {
  27. selectId = 0;
  28. } else {
  29. selectId = data['Id'];
  30. }
  31. });
  32. },
  33. child: Stack(children: <Widget>[
  34. Container(
  35. decoration: BoxDecoration(borderRadius: BorderRadius.circular(2.0)),
  36. width: width,
  37. height: width,
  38. padding: EdgeInsets.all(5),
  39. child: ClipRRect(
  40. borderRadius: BorderRadius.circular(10),
  41. child: CachedNetworkImage(
  42. imageUrl: data['ImgUrl'] == null ? "" : data['ImgUrl'],
  43. placeholder: CustomUI.buildImgLoding,
  44. fit: BoxFit.cover,
  45. ),
  46. )),
  47. Positioned(
  48. right: 0,
  49. child: Checkbox(
  50. value: data['Id'] == selectId,
  51. activeColor: Colors.blue,
  52. onChanged: (bool val) {
  53. // val 是布尔值
  54. this.setState(() {
  55. if (selectId == data['Id']) {
  56. selectId = 0;
  57. } else {
  58. selectId = data['Id'];
  59. }
  60. });
  61. },
  62. )),
  63. ]),
  64. );
  65. }
  66. @override
  67. void initState() {
  68. super.initState();
  69. for (int i = 0; i < widget.imageList.length; i++) {
  70. var element = widget.imageList[i];
  71. if (element['Type'] == PhotoType.money.index ||
  72. element['Type'] == PhotoType.destroyMoney.index) {
  73. selectId = element['Id'];
  74. originalMoneyId = selectId;
  75. }
  76. }
  77. }
  78. @override
  79. Widget build(BuildContext context) {
  80. var list = widget.imageList.map((data) {
  81. return _buildImg(data);
  82. }).toList();
  83. return Scaffold(
  84. appBar: AppBar(
  85. backgroundColor: AppColors.NewAppbarBgColor,
  86. leading: CustomUI.buildCustomLeading(context),
  87. title: Text(
  88. I18n.of(context).set_photo,
  89. style: TextStyle(color: AppColors.NewAppbarTextColor),
  90. textScaleFactor: 1.0,
  91. ),
  92. actions: <Widget>[
  93. Container(
  94. alignment: Alignment.center,
  95. child: new InkWell(
  96. child: new Padding(
  97. padding:
  98. EdgeInsets.only(right: 15, left: 15, top: 10, bottom: 10),
  99. child: new Text(I18n.of(context).determine,
  100. textScaleFactor: 1.0,
  101. style: Constants.AppBarActionTextStyle),
  102. ),
  103. onTap: () async {
  104. if (originalMoneyId == selectId) {
  105. Navigator.of(context).pop();
  106. return;
  107. }
  108. Map rdata = {
  109. "userId": UserData().basicInfo.userId,
  110. "Id": selectId,
  111. };
  112. rdata['sign'] = TokenMgr().getSign(rdata);
  113. Response res = await HttpUtil().post(
  114. 'user/setting/photosprice',
  115. data: rdata,
  116. isShowLoading: true);
  117. Map resData = res.data;
  118. if (resData['code'] == 0) {
  119. MessageMgr().emit('refresh_photo');
  120. Navigator.of(context).pop();
  121. }
  122. },
  123. ),
  124. )
  125. ],
  126. centerTitle: true,
  127. ),
  128. body: SafeArea(
  129. child: Container(
  130. padding: EdgeInsets.only(left: 10, top: 10, bottom: 10),
  131. height: MediaQuery.of(context).size.height,
  132. width: MediaQuery.of(context).size.width,
  133. //alignment: Alignment.center,
  134. child: SingleChildScrollView(
  135. child: Wrap(
  136. crossAxisAlignment: WrapCrossAlignment.start,
  137. children: list,
  138. ),
  139. )),
  140. ));
  141. }
  142. }