基础组件库

team_recommend_widget.dart 12 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366
  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(),
  211. const SizedBox(width: 12),
  212. /// 数据
  213. _getDataRightWidget(dataModel),
  214. ],
  215. );
  216. }
  217. /// 头像widget
  218. Widget _getAvatarWidget() {
  219. return Container(
  220. width: 55,
  221. height: 55,
  222. color: Colors.red,
  223. );
  224. }
  225. /// 数据右边视图,头像右边的widget
  226. Widget _getDataRightWidget(TeamDataModel dataModel) {
  227. return SizedBox(
  228. height: 55,
  229. child: Column(
  230. crossAxisAlignment: CrossAxisAlignment.start,
  231. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  232. children: <Widget>[
  233. /// 昵称
  234. _getNickNameWidget(dataModel),
  235. /// 手机号
  236. _getPhoneNumberWidget(dataModel),
  237. /// 微信号
  238. _getWXWidget(dataModel)
  239. ],
  240. ),
  241. );
  242. }
  243. /// 昵称
  244. Widget _getNickNameWidget(TeamDataModel dataModel) {
  245. // return RichText(
  246. // text: TextSpan(text: '毛毛虫', style: TextStyle(fontSize: 14, color: HexColor.fromHex('#000000'), fontWeight: FontWeight.bold),
  247. // children: [
  248. // TextSpan(text: '邀请码:', style: TextStyle(fontSize: 11, color: HexColor.fromHex('#909090'), fontWeight: FontWeight.w400)),
  249. // TextSpan(text: '123456', style: TextStyle(fontSize: 11, color: HexColor.fromHex('#909090'), fontWeight: FontWeight.w400)),
  250. // ]
  251. // ),
  252. // );
  253. return Row(
  254. mainAxisAlignment: MainAxisAlignment.start,
  255. crossAxisAlignment: CrossAxisAlignment.center,
  256. children: <Widget>[
  257. /// 昵称
  258. Text(dataModel?.referrer_username ?? '',
  259. maxLines: 1,
  260. overflow: TextOverflow.ellipsis,
  261. style: TextStyle(
  262. fontSize: 14,
  263. color: HexColor.fromHex(widget?.styleModel?.headerReferrerUsernameColor ?? '#000000'),
  264. fontWeight: FontWeight.bold,
  265. )),
  266. const SizedBox(width: 6),
  267. Text(widget?.styleModel?.headerReferrerInvitecodeText ?? '邀请码:',
  268. style: TextStyle(fontSize: 11, color: HexColor.fromHex(widget?.styleModel?.headerReferrerInvitecodeColor ?? '#909090'))),
  269. Text(dataModel?.referrer_invite_code ?? '',
  270. style: TextStyle(
  271. fontSize: 11, color: HexColor.fromHex(widget?.styleModel?.headerReferrerInvitecodeColor ?? '#909090'), fontFamily: 'Din', package: 'zhiying_base_widget')),
  272. ],
  273. );
  274. }
  275. /// 手机号
  276. Widget _getPhoneNumberWidget(TeamDataModel dataModel) {
  277. return Row(
  278. children: <Widget>[
  279. Text(widget?.styleModel?.headerReferrerPhoneText ?? '手机号:',
  280. style: TextStyle(fontSize: 11, color: HexColor.fromHex(widget?.styleModel?.headerReferrerPhoneColor ?? '#AFAFAF'))),
  281. Text(dataModel?.referrer_phone ?? '',
  282. style: TextStyle(fontSize: 11, color: HexColor.fromHex(widget?.styleModel?.headerReferrerPhoneColor ?? '#AFAFAF'), fontFamily: 'Din', package: 'zhiying_base_widget')),
  283. const SizedBox(width: 6),
  284. /// 拷贝按钮
  285. _getCustomCopyWidget(),
  286. ],
  287. );
  288. }
  289. /// 微信号
  290. Widget _getWXWidget(TeamDataModel dataModel) {
  291. return Row(
  292. children: <Widget>[
  293. Text(widget?.styleModel?.headerReferrerWxText ?? '微信号:', style: TextStyle(fontSize: 11, color: HexColor.fromHex(widget?.styleModel?.headerReferrerWxColor ?? '#AFAFAF'))),
  294. Text(dataModel?.referrer_wechat ?? '',
  295. style: TextStyle(fontSize: 11, color: HexColor.fromHex(widget?.styleModel?.headerReferrerWxColor ?? '#AFAFAF'), fontFamily: 'Din', package: 'zhiying_base_widget')),
  296. const SizedBox(width: 6),
  297. /// 拷贝按钮
  298. _getCustomCopyWidget(),
  299. ],
  300. );
  301. }
  302. /// 自定义复制按钮的Widget
  303. Widget _getCustomCopyWidget() {
  304. return GestureDetector(
  305. behavior: HitTestBehavior.opaque,
  306. onTap: () => _copyText(),
  307. child: Container(
  308. padding: const EdgeInsets.only(left: 4, bottom: 2, top: 2, right: 6),
  309. decoration: BoxDecoration(
  310. color: HexColor.fromHex(widget?.styleModel?.headerReferrerCopyBtnBgColor ?? '#FFF2F2'),
  311. borderRadius: BorderRadius.circular(30),
  312. ),
  313. child: Row(
  314. crossAxisAlignment: CrossAxisAlignment.center,
  315. children: <Widget>[
  316. // Container(width: 11, child: CachedNetworkImage(),),
  317. CachedNetworkImage(
  318. imageUrl: widget?.styleModel?.headerReferrerCopyBtnIcon ?? '',
  319. width: 11,
  320. ),
  321. const SizedBox(width: 4.5),
  322. Text(widget?.styleModel?.headerReferrerCopyBtnText ?? '复制',
  323. style: TextStyle(fontSize: 8, color: HexColor.fromHex(widget?.styleModel?.headerReferrerCopyBtnTextColor ?? '#F94B47')))
  324. ],
  325. ),
  326. ),
  327. );
  328. }
  329. }