基础组件库
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.

team_recommend_widget.dart 13 KiB

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