基础组件库
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

370 rivejä
13 KiB

  1. import 'package:flutter/material.dart';
  2. import 'package:zhiying_base_widget/pages/team_page/model/team_data_model.dart';
  3. import 'package:zhiying_base_widget/pages/team_page/model/team_style_model.dart';
  4. import 'package:zhiying_base_widget/widgets/team/recommend/bloc/team_recommend_bloc.dart';
  5. import 'package:zhiying_base_widget/widgets/team/recommend/bloc/team_recommend_repository.dart';
  6. import 'package:zhiying_comm/zhiying_comm.dart';
  7. import 'package:cached_network_image/cached_network_image.dart';
  8. import 'package:fluttertoast/fluttertoast.dart';
  9. import 'package:flutter_bloc/flutter_bloc.dart';
  10. ///
  11. /// 我的团队 - 我的推荐人
  12. ///
  13. class TeamRecommendWidget extends StatelessWidget {
  14. TeamStyleModel styleModel;
  15. TeamDataModel dataModel;
  16. TeamRecommendWidget(this.styleModel, this.dataModel);
  17. @override
  18. Widget build(BuildContext context) {
  19. return BlocProvider<TeamRecommendBloc>(
  20. create: (_) => TeamRecommendBloc(TeamRecommendRepository())..add(TeamRecommendInitEvent(dataModel: dataModel)),
  21. child: _TeamRecommendWidgetContainer(styleModel),
  22. );
  23. }
  24. }
  25. class _TeamRecommendWidgetContainer extends StatefulWidget {
  26. TeamStyleModel styleModel;
  27. // TeamDataModel dataModel;
  28. _TeamRecommendWidgetContainer(this.styleModel);
  29. @override
  30. _TeamRecommendWidgetState createState() => _TeamRecommendWidgetState();
  31. }
  32. class _TeamRecommendWidgetState extends State<_TeamRecommendWidgetContainer> {
  33. TextEditingController _textEditingController;
  34. FocusNode _focusNode;
  35. /// 按钮点击添加事件
  36. void _onClickListener() {
  37. String text = _textEditingController?.text?.toString()?.trim();
  38. if (!EmptyUtil.isEmpty(text)) {
  39. BlocProvider.of<TeamRecommendBloc>(context).add(TeamRecommendRelateEvent(text));
  40. } else {
  41. Fluttertoast.showToast(msg: '邀请码不能为空~');
  42. }
  43. }
  44. /// 拷贝
  45. void _copyText() {
  46. Fluttertoast.showToast(msg: '复制成功~');
  47. }
  48. @override
  49. void initState() {
  50. _textEditingController = TextEditingController();
  51. _focusNode = FocusNode();
  52. super.initState();
  53. }
  54. @override
  55. void dispose() {
  56. _focusNode?.unfocus();
  57. _focusNode?.dispose();
  58. _textEditingController?.dispose();
  59. super.dispose();
  60. }
  61. @override
  62. Widget build(BuildContext context) {
  63. return Container(
  64. margin: const EdgeInsets.only(left: 12.5, right: 12.5, top: 10.5),
  65. child: BlocConsumer<TeamRecommendBloc, TeamRecommendState>(
  66. listener: (context, state) {},
  67. buildWhen: (prove, current) {
  68. if (current is TeamRecommendErrorState) {
  69. return false;
  70. }
  71. return true;
  72. },
  73. builder: (context, state) {
  74. if (state is TeamRecommendLoadedState) {
  75. return _getMainWidget(state?.model);
  76. }
  77. return _getMainWidget(null);
  78. },
  79. ),
  80. );
  81. }
  82. /// 主体Widget
  83. Widget _getMainWidget(TeamDataModel dataModel) {
  84. return Container(
  85. padding: const EdgeInsets.only(left: 10, bottom: 12, right: 10),
  86. decoration: BoxDecoration(borderRadius: BorderRadius.circular(10), color: Colors.white),
  87. child: Column(
  88. crossAxisAlignment: CrossAxisAlignment.start,
  89. children: <Widget>[
  90. /// 左上角的Icon
  91. _getLeftTopWidget(),
  92. const SizedBox(height: 6),
  93. /// 数据视图
  94. Visibility(
  95. visible: !EmptyUtil.isEmpty(dataModel) && !EmptyUtil.isEmpty(dataModel?.referrer_invite_code) && !EmptyUtil.isEmpty(dataModel?.referrer_username),
  96. replacement: _getInputCombWidget(),
  97. child: Padding(padding: const EdgeInsets.only(left: 10), child: _getDataWidget(dataModel)),
  98. ),
  99. ],
  100. ),
  101. );
  102. }
  103. /// 我的推荐人IconWidget(左上角的ICON)
  104. Widget _getLeftTopWidget() {
  105. return Transform.translate(
  106. offset: Offset(0, -4.5),
  107. child: Container(
  108. padding: const EdgeInsets.only(left: 10.5, right: 8, top: 4, bottom: 4.5),
  109. decoration: BoxDecoration(
  110. borderRadius: BorderRadius.circular(4),
  111. gradient: LinearGradient(begin: Alignment.centerLeft, end: Alignment.centerRight, colors: [
  112. HexColor.fromHex(widget?.styleModel?.headerReferrerTitleBgColor ?? '#FF5E5E'),
  113. HexColor.fromHex(widget?.styleModel?.headerReferrerTitleBgColorT ?? '#FF5252'),
  114. ])),
  115. child: Text(
  116. widget?.styleModel?.headerReferrerTitle ?? '我的推荐人',
  117. style: TextStyle(
  118. color: HexColor.fromHex(widget?.styleModel?.headerReferrerTitleColor ?? '#FFFFFF'),
  119. fontSize: 11,
  120. ),
  121. ),
  122. ));
  123. }
  124. /// 没邀请人的Widget
  125. Widget _getInputCombWidget() {
  126. return Container(
  127. margin: const EdgeInsets.only(left: 2.5, right: 2.5),
  128. width: double.infinity,
  129. child: Column(
  130. mainAxisAlignment: MainAxisAlignment.center,
  131. // crossAxisAlignment: CrossAxisAlignment.center,
  132. children: <Widget>[
  133. /// 输入框
  134. Container(
  135. height: 30,
  136. width: double.infinity,
  137. decoration: BoxDecoration(
  138. borderRadius: BorderRadius.circular(30),
  139. color: HexColor.fromHex(widget?.styleModel?.headerNoReferrerInputBgColor ?? '#F7F7F7'),
  140. ),
  141. padding: const EdgeInsets.only(top: 3.5, bottom: 3.5, right: 3, left: 13),
  142. child: Row(
  143. children: <Widget>[
  144. Expanded(
  145. child: _getInputWidget(),
  146. ),
  147. /// 添加的按钮
  148. _getAddButtomWidget(),
  149. ],
  150. ),
  151. ),
  152. const SizedBox(height: 10.5),
  153. /// 文字提示
  154. Text(
  155. widget?.styleModel?.headerNoReferrerTipText ?? '还没有填写邀请人ID,填写后双方都可以获得奖励',
  156. style: TextStyle(color: HexColor.fromHex(widget?.styleModel.headerNoReferrerTipTextColor ?? '#909090'), fontSize: 11),
  157. ),
  158. ],
  159. ),
  160. );
  161. }
  162. /// 输入框的
  163. Widget _getInputWidget() {
  164. return TextField(
  165. controller: _textEditingController,
  166. focusNode: _focusNode,
  167. onSubmitted: (value) => _onClickListener(),
  168. style: TextStyle(color: HexColor.fromHex(widget?.styleModel?.headerNoReferrerInputColor ?? '#000000'), fontSize: 12, textBaseline: TextBaseline.alphabetic),
  169. decoration: InputDecoration(
  170. border: InputBorder.none,
  171. enabledBorder: InputBorder.none,
  172. disabledBorder: InputBorder.none,
  173. errorBorder: InputBorder.none,
  174. focusedErrorBorder: InputBorder.none,
  175. focusedBorder: InputBorder.none,
  176. hintText: widget?.styleModel?.headerNoReferrerIntputText ?? '输入邀请人ID',
  177. isDense: true,
  178. filled: true,
  179. fillColor: Colors.transparent,
  180. contentPadding: EdgeInsets.zero,
  181. hintStyle: TextStyle(color: HexColor.fromHex(widget?.styleModel?.headerNoReferrerIntputTextColor ?? '#909090'), fontSize: 12, textBaseline: TextBaseline.alphabetic),
  182. ),
  183. );
  184. }
  185. /// 添加的按钮
  186. Widget _getAddButtomWidget() {
  187. return Material(
  188. child: InkWell(
  189. onTap: _onClickListener,
  190. child: Container(
  191. padding: const EdgeInsets.only(left: 21, right: 21, top: 2.5, bottom: 2.5),
  192. decoration: BoxDecoration(borderRadius: BorderRadius.circular(30), color: HexColor.fromHex(widget?.styleModel?.headerNoReferrerBtnBgColor ?? '#F94B47')),
  193. child: Text(
  194. widget?.styleModel?.headerNoReferrerBtnText ?? '添加',
  195. style: TextStyle(
  196. fontSize: 13,
  197. color: HexColor.fromHex(widget?.styleModel?.headerNoReferrerBtnTextColor ?? '#FFFFFF'),
  198. ),
  199. ),
  200. ),
  201. ),
  202. );
  203. }
  204. /// 数据视图
  205. Widget _getDataWidget(TeamDataModel dataModel) {
  206. return Row(
  207. mainAxisAlignment: MainAxisAlignment.start,
  208. children: <Widget>[
  209. /// 头像widget
  210. _getAvatarWidget(dataModel),
  211. const SizedBox(width: 12),
  212. /// 数据
  213. _getDataRightWidget(dataModel),
  214. ],
  215. );
  216. }
  217. /// 头像widget
  218. Widget _getAvatarWidget(TeamDataModel dataModel) {
  219. return Container(
  220. width: 55,
  221. // height: 55,
  222. // color: Colors.red,
  223. child: CachedNetworkImage(
  224. imageUrl: dataModel?.referrerAvatar ?? '',
  225. ),
  226. );
  227. }
  228. /// 数据右边视图,头像右边的widget
  229. Widget _getDataRightWidget(TeamDataModel dataModel) {
  230. return SizedBox(
  231. height: 55,
  232. child: Column(
  233. crossAxisAlignment: CrossAxisAlignment.start,
  234. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  235. children: <Widget>[
  236. /// 昵称
  237. _getNickNameWidget(dataModel),
  238. /// 手机号
  239. _getPhoneNumberWidget(dataModel),
  240. /// 微信号
  241. _getWXWidget(dataModel)
  242. ],
  243. ),
  244. );
  245. }
  246. /// 昵称
  247. Widget _getNickNameWidget(TeamDataModel dataModel) {
  248. // return RichText(
  249. // text: TextSpan(text: '毛毛虫', style: TextStyle(fontSize: 14, color: HexColor.fromHex('#000000'), fontWeight: FontWeight.bold),
  250. // children: [
  251. // TextSpan(text: '邀请码:', style: TextStyle(fontSize: 11, color: HexColor.fromHex('#909090'), fontWeight: FontWeight.w400)),
  252. // TextSpan(text: '123456', style: TextStyle(fontSize: 11, color: HexColor.fromHex('#909090'), fontWeight: FontWeight.w400)),
  253. // ]
  254. // ),
  255. // );
  256. return Row(
  257. mainAxisAlignment: MainAxisAlignment.start,
  258. crossAxisAlignment: CrossAxisAlignment.center,
  259. children: <Widget>[
  260. /// 昵称
  261. Text(dataModel?.referrer_username ?? '',
  262. maxLines: 1,
  263. overflow: TextOverflow.ellipsis,
  264. style: TextStyle(
  265. fontSize: 14,
  266. color: HexColor.fromHex(widget?.styleModel?.headerReferrerUsernameColor ?? '#000000'),
  267. fontWeight: FontWeight.bold,
  268. )),
  269. const SizedBox(width: 6),
  270. Text(widget?.styleModel?.headerReferrerInvitecodeText ?? '邀请码:',
  271. style: TextStyle(fontSize: 11, color: HexColor.fromHex(widget?.styleModel?.headerReferrerInvitecodeColor ?? '#909090'))),
  272. Text(dataModel?.referrer_invite_code ?? '',
  273. style: TextStyle(
  274. fontSize: 11, color: HexColor.fromHex(widget?.styleModel?.headerReferrerInvitecodeColor ?? '#909090'), fontFamily: 'Din', package: 'zhiying_base_widget')),
  275. ],
  276. );
  277. }
  278. /// 手机号
  279. Widget _getPhoneNumberWidget(TeamDataModel dataModel) {
  280. return Row(
  281. children: <Widget>[
  282. Text(widget?.styleModel?.headerReferrerPhoneText ?? '手机号:',
  283. style: TextStyle(fontSize: 11, color: HexColor.fromHex(widget?.styleModel?.headerReferrerPhoneColor ?? '#AFAFAF'))),
  284. Text(dataModel?.referrer_phone ?? '',
  285. style: TextStyle(fontSize: 11, color: HexColor.fromHex(widget?.styleModel?.headerReferrerPhoneColor ?? '#AFAFAF'), fontFamily: 'Din', package: 'zhiying_base_widget')),
  286. const SizedBox(width: 6),
  287. /// 拷贝按钮
  288. _getCustomCopyWidget(),
  289. ],
  290. );
  291. }
  292. /// 微信号
  293. Widget _getWXWidget(TeamDataModel dataModel) {
  294. return Row(
  295. children: <Widget>[
  296. Text(widget?.styleModel?.headerReferrerWxText ?? '微信号:', style: TextStyle(fontSize: 11, color: HexColor.fromHex(widget?.styleModel?.headerReferrerWxColor ?? '#AFAFAF'))),
  297. Text(dataModel?.referrer_wechat ?? '',
  298. style: TextStyle(fontSize: 11, color: HexColor.fromHex(widget?.styleModel?.headerReferrerWxColor ?? '#AFAFAF'), fontFamily: 'Din', package: 'zhiying_base_widget')),
  299. const SizedBox(width: 6),
  300. /// 拷贝按钮
  301. _getCustomCopyWidget(),
  302. ],
  303. );
  304. }
  305. /// 自定义复制按钮的Widget
  306. Widget _getCustomCopyWidget() {
  307. return GestureDetector(
  308. behavior: HitTestBehavior.opaque,
  309. onTap: () => _copyText(),
  310. child: Container(
  311. padding: const EdgeInsets.only(left: 4, bottom: 2, top: 2, right: 6),
  312. decoration: BoxDecoration(
  313. color: HexColor.fromHex(widget?.styleModel?.headerReferrerCopyBtnBgColor ?? '#FFF2F2'),
  314. borderRadius: BorderRadius.circular(30),
  315. ),
  316. child: Row(
  317. crossAxisAlignment: CrossAxisAlignment.center,
  318. children: <Widget>[
  319. // Container(width: 11, child: CachedNetworkImage(),),
  320. CachedNetworkImage(
  321. imageUrl: widget?.styleModel?.headerReferrerCopyBtnIcon ?? '',
  322. width: 11,
  323. ),
  324. const SizedBox(width: 4.5),
  325. Text(widget?.styleModel?.headerReferrerCopyBtnText ?? '复制',
  326. style: TextStyle(fontSize: 8, color: HexColor.fromHex(widget?.styleModel?.headerReferrerCopyBtnTextColor ?? '#F94B47')))
  327. ],
  328. ),
  329. ),
  330. );
  331. }
  332. }