user_friend_page.dart 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832
  1. import 'package:azlistview/azlistview.dart';
  2. import 'package:cached_network_image/cached_network_image.dart';
  3. import 'package:extended_nested_scroll_view/extended_nested_scroll_view.dart' as extended;
  4. import 'package:flutter/cupertino.dart';
  5. import 'package:flutter/material.dart' hide NestedScrollView;
  6. import 'package:flutter_easyrefresh/easy_refresh.dart';
  7. import 'package:sport/bean/login.dart';
  8. import 'package:sport/bean/post_user.dart';
  9. import 'package:sport/bean/user_friend.dart';
  10. import 'package:sport/bean/user_info.dart';
  11. import 'package:sport/pages/social/chat_page.dart';
  12. import 'package:sport/pages/social/user_detail_page.dart';
  13. import 'package:sport/pages/social/user_friend_add_page.dart';
  14. import 'package:sport/provider/lib/provider_widget.dart';
  15. import 'package:sport/provider/lib/view_state_lifecycle.dart';
  16. import 'package:sport/provider/user_friend_model.dart';
  17. import 'package:sport/router/navigator_util.dart';
  18. import 'package:sport/utils/DateFormat.dart';
  19. import 'package:sport/utils/toast.dart';
  20. import 'package:sport/widgets/appbar.dart';
  21. import 'package:sport/widgets/dialog/alert_dialog.dart';
  22. import 'package:sport/widgets/dialog/request_dialog.dart';
  23. import 'package:sport/widgets/error.dart';
  24. import 'package:sport/widgets/image.dart';
  25. import 'package:sport/widgets/loading.dart';
  26. import 'package:sport/widgets/misc.dart';
  27. import 'package:sport/widgets/persistent_header.dart';
  28. import 'package:sport/widgets/space.dart';
  29. class UserFriendPage extends StatefulWidget {
  30. @override
  31. State<StatefulWidget> createState() => _PageState();
  32. }
  33. class _PageState extends State<UserFriendPage> {
  34. PageController _controller;
  35. bool _refresh = false;
  36. int _page = 0;
  37. @override
  38. void initState() {
  39. super.initState();
  40. }
  41. @override
  42. void dispose() {
  43. super.dispose();
  44. _controller?.dispose();
  45. }
  46. @override
  47. Widget build(BuildContext context) {
  48. final double tabHeader = 60;
  49. final double statusBarHeight = MediaQuery.of(context).padding.top;
  50. final double pinnedHeaderHeight =
  51. //statusBar height
  52. statusBarHeight +
  53. //pinned SliverAppBar height in header
  54. kToolbarHeight +
  55. tabHeader;
  56. return DefaultTabController(
  57. length: 3,
  58. child: Scaffold(
  59. backgroundColor: Colors.white,
  60. body: extended.NestedScrollView(
  61. pinnedHeaderSliverHeightBuilder: () {
  62. return pinnedHeaderHeight;
  63. },
  64. innerScrollPositionKeyBuilder: () {
  65. TabController tabController = DefaultTabController.of(context);
  66. String index = 'Tab${tabController.index}';
  67. return Key(index);
  68. },
  69. headerSliverBuilder: (context, innerBoxIsScrolled) {
  70. return <Widget>[
  71. buildSliverAppBar(context, "好友列表",
  72. innerBoxIsScrolled: innerBoxIsScrolled,
  73. actions: <Widget>[
  74. IconButton(
  75. icon: Image.asset(
  76. "lib/assets/img/bbs_icon_addmore.png",
  77. width: 22.0,
  78. height: 22.0,
  79. ),
  80. // icon: Text(
  81. // "添加",
  82. // style: TextStyle(fontSize: 15, color: Theme.of(context).accentColor),
  83. // ),
  84. onPressed: () async {
  85. await NavigatorUtil.goPage(
  86. context, (context) => UserFriendAddPage());
  87. setState(() {
  88. _refresh = true;
  89. });
  90. await Future.delayed(Duration(seconds: 1));
  91. setState(() {
  92. _refresh = false;
  93. });
  94. },
  95. )
  96. ]),
  97. SliverPersistentHeader(
  98. delegate: PersistentHeader(
  99. min: tabHeader,
  100. max: tabHeader,
  101. child: Container(
  102. color: Colors.white,
  103. child: Column(
  104. children: <Widget>[
  105. Expanded(
  106. child: Center(
  107. child: Container(
  108. height: 35,
  109. child: TabBar(
  110. isScrollable: true,
  111. labelPadding:
  112. EdgeInsets.symmetric(horizontal: 32),
  113. indicatorWeight: 3,
  114. indicatorPadding:
  115. EdgeInsets.symmetric(horizontal: 6),
  116. tabs: <Widget>[
  117. Tab(text: '好友'),
  118. Tab(text: '我关注'),
  119. Tab(text: '关注我')
  120. ],
  121. onTap: (index) {
  122. _controller?.jumpToPage(index);
  123. },
  124. ),
  125. ),
  126. ),
  127. ),
  128. ],
  129. ),
  130. )),
  131. pinned: true,
  132. ),
  133. ];
  134. },
  135. body: _refresh
  136. ? RequestLoadingWidget()
  137. : PageView.builder(
  138. controller: _controller = PageController(initialPage: _page)
  139. ..addListener(() {
  140. _page = _controller.page.toInt();
  141. }),
  142. physics: NeverScrollableScrollPhysics(),
  143. itemCount: 3,
  144. itemBuilder: (_, index) => _PageDetailPage(index)),
  145. ),
  146. ),
  147. );
  148. }
  149. }
  150. class _PageDetailPage extends StatefulWidget {
  151. final int type;
  152. _PageDetailPage(this.type);
  153. @override
  154. State<StatefulWidget> createState() => _PageDetailState(type);
  155. }
  156. class _PageDetailState
  157. extends ViewStateLifecycle<_PageDetailPage, UserFriendModel>
  158. with ChangeNotifier {
  159. TextEditingController _controller;
  160. FocusNode _focusNode;
  161. ValueNotifier<String> _searchValue = ValueNotifier<String>("");
  162. bool isSeach = false;
  163. _PageDetailState(int type);
  164. @override
  165. void initState() {
  166. super.initState();
  167. _focusNode = FocusNode();
  168. _controller = new TextEditingController(text: '');
  169. // 监听 ...
  170. _controller.addListener(() {
  171. if (_controller.value.text != "") {
  172. if (widget.type == 0) {
  173. model.items = model.originItems
  174. .where(
  175. (element) => element.user.name.indexOf(_controller.text) > -1)
  176. .toList();
  177. setState(() {
  178. isSeach = true;
  179. });
  180. } else {
  181. model.list = model.originList
  182. .where((element) => element.name.indexOf(_controller.text) > -1)
  183. .toList();
  184. }
  185. notifyListeners();
  186. } else {
  187. if (widget.type == 0) {
  188. setState(() {
  189. isSeach = false;
  190. });
  191. }
  192. model.items = model.originItems;
  193. model.list = model.originList;
  194. notifyListeners();
  195. }
  196. });
  197. }
  198. @override
  199. void dispose() {
  200. super.dispose();
  201. _focusNode?.dispose();
  202. _controller?.dispose();
  203. }
  204. @override
  205. Widget build(BuildContext context) {
  206. return ProviderWidget<UserFriendModel>(
  207. model: model,
  208. onModelReady: (model) => model.initData(),
  209. builder: (_, model, __) {
  210. return widget.type == 0
  211. ? Column(
  212. children: <Widget>[
  213. _searchWidget(context),
  214. if (!isSeach)
  215. Space(
  216. height: 16.0,
  217. ),
  218. isSeach
  219. ? model.items.length > 0
  220. ? Expanded(
  221. child:
  222. ListView.builder(
  223. padding: EdgeInsets.zero,
  224. itemBuilder: (context, index) => Column(
  225. children: <Widget>[
  226. ListTile(
  227. leading: InkWell(
  228. child: CircleAvatar(
  229. backgroundImage: userAvatarProvider(model.items[index].user.avatar),
  230. radius: 22,
  231. ),
  232. onTap: () {
  233. NavigatorUtil.goPage(
  234. context,
  235. (context) => UserDetailPage(
  236. PostUser.fromJson({
  237. "id":
  238. "${model.items[index].user.uid}"
  239. })));
  240. },
  241. ),
  242. title:
  243. Text("${model.items[index].user.name}"),
  244. onTap: () {
  245. NavigatorUtil.goPage(
  246. context,
  247. (context) => ChatPage(
  248. UserInfo.fromJson(model
  249. .items[index].user
  250. .toJson())));
  251. },
  252. ),
  253. Divider()
  254. ],
  255. ),
  256. itemCount: model.items.length,
  257. ),
  258. )
  259. : _searchNothings()
  260. : Expanded(
  261. child: AzListView(
  262. data: model.items,
  263. susItemHeight: 200,
  264. itemCount: model.items.length,
  265. indexBarData:
  266. model.tags.map((e) => "$e").toList(),
  267. itemBuilder: (BuildContext context, int index) {
  268. return ListTile(
  269. leading: InkWell(
  270. child: CircleAvatar(
  271. backgroundImage: userAvatarProvider(model.items[index].user.avatar),
  272. radius: 22,
  273. ),
  274. onTap: () {
  275. NavigatorUtil.goPage(
  276. context,
  277. (context) => UserDetailPage(
  278. PostUser.fromJson({
  279. "id":
  280. "${model.items[index].user.uid}"
  281. })));
  282. },
  283. ),
  284. title:
  285. Text("${model.items[index].user.name}"),
  286. onTap: () {
  287. NavigatorUtil.goPage(
  288. context,
  289. (context) => ChatPage(UserInfo.fromJson(
  290. model.items[index].user.toJson())));
  291. },
  292. );
  293. },
  294. physics: BouncingScrollPhysics(),
  295. padding: EdgeInsets.zero,
  296. susItemBuilder:
  297. (BuildContext context, int index) {
  298. return Column(
  299. children: <Widget>[
  300. Container(
  301. // height: 40,
  302. width: MediaQuery.of(context).size.width,
  303. padding: EdgeInsets.only(left: 16.0),
  304. // color: Color(0xFFF3F4F5),
  305. alignment: Alignment.centerLeft,
  306. child: Text(
  307. '${model.items[index].getSuspensionTag()}',
  308. softWrap: false,
  309. style: TextStyle(
  310. fontSize: 14.0,
  311. color: Color(0xff9999999),
  312. ),
  313. ),
  314. ),
  315. Divider(
  316. indent: 12.0,
  317. endIndent: 12.0,
  318. ),
  319. ],
  320. );
  321. },
  322. indexBarOptions: IndexBarOptions(
  323. needRebuild: true,
  324. ignoreDragCancel: true,
  325. textStyle: TextStyle(
  326. color: Color(0xff999999), fontSize: 12.0),
  327. selectTextStyle: TextStyle(
  328. fontSize: 20,
  329. color: Theme.of(context).accentColor),
  330. // downTextStyle: TextStyle(fontSize: 12, color: Theme.of(context).accentColor),
  331. // selectItemDecoration: BoxDecoration(color: Colors.green),
  332. // downItemDecoration:
  333. // BoxDecoration(color: Colors.green),
  334. indexHintWidth: 33,
  335. indexHintHeight: 33,
  336. indexHintDecoration: BoxDecoration(
  337. image: DecorationImage(
  338. image: AssetImage(
  339. "lib/assets/img/friendlist_bg_letter.png"),
  340. fit: BoxFit.contain,
  341. ),
  342. ),
  343. indexHintTextStyle: TextStyle(
  344. fontSize: 18.0, color: Colors.white),
  345. indexHintAlignment: Alignment.centerRight,
  346. indexHintChildAlignment: Alignment(-0.25, 0.0),
  347. indexHintOffset: Offset(0, 0),
  348. ),
  349. ),
  350. ),
  351. ],
  352. )
  353. : EasyRefresh.custom(
  354. firstRefresh: false,
  355. onRefresh: () => model.refresh(),
  356. onLoad: () => model.loadMore(),
  357. enableControlFinishRefresh: true,
  358. controller: model.refreshController,
  359. header: buildClassicalHeader(),
  360. footer: buildClassicalFooter(),
  361. slivers: <Widget>[
  362. SliverToBoxAdapter(
  363. child: _searchWidget(context),
  364. ),
  365. if (model.isBusy)
  366. SliverToBoxAdapter(
  367. child: RequestLoadingWidget(),
  368. ),
  369. if (model.list.length > 0)
  370. SliverList(
  371. delegate: SliverChildBuilderDelegate(
  372. (context, index) {
  373. return _buildItem(model.list[index]);
  374. },
  375. childCount: model.list.length,
  376. ),
  377. ),
  378. if (model.list.length <= 0)
  379. SliverToBoxAdapter(
  380. child: _searchNothings(),
  381. ),
  382. if (model.isError)
  383. SliverToBoxAdapter(
  384. child: RequestErrorWidget(
  385. () {
  386. model.initData();
  387. },
  388. msg: widget.type == 0
  389. ? "暂无好友~"
  390. : widget.type == 1 ? "暂无关注~" : "暂无关注我的~",
  391. assets: "emptypage-image-nomotion.png",
  392. ),
  393. ),
  394. ],
  395. );
  396. });
  397. }
  398. Widget _buildItem(UserFriend user) {
  399. var _padding = EdgeInsets.symmetric(horizontal: 4.0);
  400. Widget child;
  401. if (widget.type == 2) {
  402. child = Row(
  403. children: <Widget>[
  404. CircleAvatar(
  405. backgroundImage: userAvatarProvider(user?.socialInfo?.avatar),
  406. radius: 22,
  407. ),
  408. SizedBox(
  409. width: 8,
  410. ),
  411. Expanded(
  412. child: Column(
  413. crossAxisAlignment: CrossAxisAlignment.start,
  414. children: <Widget>[
  415. Text(
  416. "${user?.socialInfo?.name}",
  417. style: Theme.of(context)
  418. .textTheme
  419. .headline3
  420. .copyWith(fontWeight: FontWeight.normal),
  421. ),
  422. SizedBox(
  423. height: 5,
  424. ),
  425. RichText(
  426. text: TextSpan(
  427. style: Theme.of(context).textTheme.subtitle2,
  428. children: <InlineSpan>[
  429. TextSpan(
  430. text: '${DateFormat.formatCreateAt(user?.createdAt)}',
  431. style: Theme.of(context).textTheme.bodyText1,
  432. ),
  433. user.makeFrom == 'follow'
  434. ? TextSpan(
  435. text: '通过线上',
  436. style: Theme.of(context)
  437. .textTheme
  438. .bodyText1
  439. .copyWith(
  440. color: Theme.of(context).accentColor),
  441. )
  442. : TextSpan(
  443. text: '通过扫码',
  444. style: Theme.of(context)
  445. .textTheme
  446. .bodyText1
  447. .copyWith(
  448. color: Theme.of(context).accentColor),
  449. ),
  450. TextSpan(
  451. text: "关注了你",
  452. style: Theme.of(context).textTheme.bodyText1,
  453. )
  454. ]),
  455. ),
  456. // TextSpan(
  457. // "${DateFormat.formatCreateAt(user?.createdAt)}通过${user.makeFrom}关注了你",
  458. //
  459. // ),
  460. ],
  461. ),
  462. ),
  463. // if (user?.isFriends == "0")
  464. // user?.isIgnore == 0
  465. // ? GestureDetector(
  466. // child: Container(
  467. // width: 64,
  468. // height: 30,
  469. // alignment: Alignment.center,
  470. // margin: _padding,
  471. // child: Text(
  472. // "关注",
  473. // strutStyle: fixedLine,
  474. // style: Theme.of(context).textTheme.bodyText2,
  475. // ),
  476. // decoration: BoxDecoration(
  477. // borderRadius: BorderRadius.circular(20),
  478. // border: Border.all(
  479. // color: Color(0xff999999),
  480. // width: .5,
  481. // ),
  482. // ),
  483. // ),
  484. // onTap: () async {
  485. // await request(context, () async {
  486. // var resp = await model.api
  487. // .userIgnoreFollow(uid: user?.socialInfo?.id)
  488. // .catchError((onError) {});
  489. // if (resp?.code == 0) {
  490. // setState(() {
  491. // user.isIgnore = 1;
  492. // });
  493. // }
  494. // });
  495. // },
  496. // )
  497. // : Container(
  498. // width: 64,
  499. // height: 30,
  500. // margin: _padding,
  501. // alignment: Alignment.center,
  502. // child: Text(
  503. // "已忽略",
  504. // strutStyle: fixedLine,
  505. // style: Theme.of(context).textTheme.bodyText2,
  506. // ),
  507. // ),
  508. if (user?.isIgnore == 0)
  509. user.isFriends == "1"
  510. ? Container(
  511. width: 64,
  512. height: 30,
  513. // margin: _padding,
  514. alignment: Alignment.center,
  515. child: Text("已关注",
  516. strutStyle: fixedLine,
  517. style: Theme.of(context).textTheme.bodyText2),
  518. )
  519. : GestureDetector(
  520. child: Container(
  521. width: 64,
  522. height: 30,
  523. margin: _padding,
  524. alignment: Alignment.center,
  525. child: Text(
  526. "关注",
  527. strutStyle: fixedLine,
  528. style: Theme.of(context)
  529. .textTheme
  530. .bodyText2
  531. .copyWith(color: Theme.of(context).accentColor),
  532. ),
  533. decoration: BoxDecoration(
  534. borderRadius: BorderRadius.circular(20),
  535. border: Border.all(
  536. color: Theme.of(context).accentColor,
  537. width: .5,
  538. ),
  539. ),
  540. ),
  541. onTap: () async {
  542. if (user.isFriends == "1") return;
  543. await request(context, () async {
  544. var resp = await model.api
  545. .userFollow(uid: user?.socialInfo?.id)
  546. .catchError((onError) {});
  547. if (resp?.code == 0) {
  548. ToastUtil.show("关注成功");
  549. setState(() {
  550. user.isFriends = "1";
  551. });
  552. }
  553. });
  554. },
  555. )
  556. ],
  557. );
  558. } else if (widget.type == 1) {
  559. child = Row(
  560. children: <Widget>[
  561. CircleAvatar(
  562. backgroundImage: userAvatarProvider(user?.socialInfo?.avatar),
  563. radius: 22,
  564. ),
  565. SizedBox(
  566. width: 8,
  567. ),
  568. Expanded(
  569. child: Text(
  570. "${user?.socialInfo?.name}",
  571. style: Theme.of(context)
  572. .textTheme
  573. .headline3
  574. .copyWith(fontWeight: FontWeight.normal),
  575. ),
  576. ),
  577. GestureDetector(
  578. child: user.isFriends == "1"
  579. ? Row(
  580. children: <Widget>[
  581. Text("互关好友",
  582. style: TextStyle(
  583. fontSize: 14.0, color: Color(0xff999999)))
  584. ],
  585. )
  586. : user.isFriends == "0"
  587. ? Text("已关注",
  588. style:
  589. TextStyle(fontSize: 14.0, color: Color(0xff999999)))
  590. : Container(
  591. width: 64,
  592. height: 30,
  593. margin: _padding,
  594. alignment: Alignment.center,
  595. child: Text(
  596. "关注",
  597. strutStyle: fixedLine,
  598. style: Theme.of(context)
  599. .textTheme
  600. .bodyText2
  601. .copyWith(color: Theme.of(context).accentColor),
  602. ),
  603. decoration: BoxDecoration(
  604. borderRadius: BorderRadius.circular(20),
  605. border: Border.all(
  606. color: Theme.of(context).accentColor,
  607. width: .5,
  608. ),
  609. ),
  610. ),
  611. // Container(
  612. // width: 82,
  613. // height: 30,
  614. // alignment: Alignment.center,
  615. // child:
  616. // decoration: BoxDecoration(
  617. // borderRadius: BorderRadius.circular(20),
  618. // border: Border.all(
  619. // color: Color(0xffDCDCDC),
  620. // width: .5,
  621. // ),
  622. // ),
  623. // ),
  624. onTap: () async {
  625. bool flag;
  626. if (user.isFriends == "1") {
  627. flag = await showDialog(
  628. context: context,
  629. builder: (context) => CustomAlertDialog(
  630. title: '是否取消关注,解除好友关系',
  631. ok: () {
  632. Navigator.of(context).pop(true);
  633. },
  634. ));
  635. } else if (user.isFriends == "0") {
  636. flag = true;
  637. }
  638. if (flag == true) {
  639. await request(context, () async {
  640. var resp = await model.api
  641. .userUnFollow(uid: user?.socialInfo?.id)
  642. .catchError((onError) {});
  643. setState(() {
  644. user.isFriends = "2";
  645. // text = "233";
  646. });
  647. // if (resp?.code == 0) {
  648. // ToastUtil.show("取关成功");
  649. // setState(() {
  650. // model.list?.remove(user);
  651. // if (model.list?.isEmpty == true) {
  652. // model.initData();
  653. // }
  654. // });
  655. // }
  656. });
  657. } else if (flag == null) {
  658. await request(context, () async {
  659. var resp = await model.api
  660. .userFollow(uid: user?.socialInfo?.id)
  661. .catchError((onError) {});
  662. if (resp?.code == 0) {
  663. ToastUtil.show("关注成功");
  664. setState(() {
  665. user.isFriends = "0";
  666. });
  667. }
  668. });
  669. }
  670. },
  671. )
  672. ],
  673. );
  674. } else if (widget.type == 4) {
  675. // child = ListView.separated(itemBuilder: ()=>, itemCount: );
  676. }
  677. // return Column(
  678. // children: <Widget>[
  679. // Padding(
  680. // padding: const EdgeInsets.symmetric(horizontal: 12.0, vertical: 12.0),
  681. // child: InkWell(
  682. // onTap: () async {
  683. //// if(widget.type == 0) await NavigatorUtil.goPage(context, (context) => ChatPage(user?.socialInfo));
  684. //// else
  685. // await NavigatorUtil.goPage(
  686. // context,
  687. // (context) => UserDetailPage(
  688. // PostUser(
  689. // id: "${user?.socialInfo?.id}",
  690. // name: user?.socialInfo?.name,
  691. // avatar: user?.socialInfo?.avatar),
  692. // userFriends: model.list));
  693. // setState(() {});
  694. // },
  695. // child: child),
  696. // ),
  697. // Divider(
  698. // indent: 12.0,
  699. // height: 1,
  700. // endIndent: 12.0,
  701. // )
  702. // ],
  703. // );
  704. return Column(
  705. children: <Widget>[
  706. Padding(
  707. padding: const EdgeInsets.all(12.0),
  708. child: InkWell(
  709. onTap: () async {
  710. await NavigatorUtil.goPage(
  711. context,
  712. (context) => UserDetailPage(
  713. PostUser(
  714. id: "${user?.socialInfo?.id}",
  715. name: user?.socialInfo?.name,
  716. avatar: user?.socialInfo?.avatar),
  717. userFriends: model.list));
  718. setState(() {});
  719. },
  720. child: child),
  721. ),
  722. Divider(
  723. height: 1,
  724. )
  725. ],
  726. );
  727. }
  728. Widget _searchWidget(BuildContext context) {
  729. return Container(
  730. margin: EdgeInsets.fromLTRB(12.0, 0, 12.0, 0),
  731. height: 35,
  732. // padding: EdgeInsets.symmetric(horizontal: 12.0),
  733. // padding: EdgeInsets.fromLTRB(12.0, 0, 12.0, 0),
  734. decoration: BoxDecoration(
  735. color: Color(0xffF1F1F1),
  736. shape: BoxShape.rectangle,
  737. borderRadius: BorderRadius.all(Radius.circular(50)),
  738. ),
  739. child: Row(
  740. children: <Widget>[
  741. SizedBox(
  742. width: 12.0,
  743. ),
  744. Image.asset("lib/assets/img/searchbar_icon_search.png"),
  745. SizedBox(
  746. width: 6,
  747. ),
  748. Expanded(
  749. child: TextField(
  750. controller: _controller,
  751. maxLines: 1,
  752. focusNode: _focusNode,
  753. strutStyle: StrutStyle(forceStrutHeight: true),
  754. decoration: InputDecoration(
  755. hintText: '输入账号/用户昵称',
  756. border: InputBorder.none,
  757. contentPadding: EdgeInsets.symmetric(
  758. vertical: 11.5,
  759. ),
  760. hintStyle: TextStyle(
  761. color: Color(0xff999999),
  762. ),
  763. ),
  764. onChanged: (value) {
  765. _searchValue.value = value;
  766. setState(() {});
  767. },
  768. onSubmitted: (value) {
  769. model.submitValue(value);
  770. // _searchModel.setKeyword(value);
  771. // Provider.of<SearchModel>(context, listen: false).queryValue(value);
  772. },
  773. style: TextStyle(
  774. color: Color(0xff333333),
  775. ),
  776. ),
  777. ),
  778. Visibility(
  779. visible: _searchValue.value?.isNotEmpty == true,
  780. child: GestureDetector(
  781. onTap: () {
  782. model.submitValue(null);
  783. _controller.clear();
  784. },
  785. child: Padding(
  786. padding: const EdgeInsets.all(8.0),
  787. child: Image.asset("lib/assets/img/searchbar_btn_no.png"),
  788. ),
  789. ))
  790. ],
  791. ),
  792. );
  793. }
  794. Widget _searchNothings() {
  795. return Column(
  796. mainAxisSize: MainAxisSize.min,
  797. children: <Widget>[
  798. Padding(
  799. padding: const EdgeInsets.fromLTRB(0, 50, 0, 0),
  800. child: Image.asset("lib/assets/img/emptypage-image-nonetwork.png"),
  801. ),
  802. Padding(
  803. padding: const EdgeInsets.fromLTRB(0, 12, 0, 12),
  804. child: Text(
  805. "搜索无果",
  806. style: Theme.of(context).textTheme.bodyText2,
  807. ),
  808. ),
  809. SizedBox(
  810. height: 100,
  811. )
  812. ],
  813. );
  814. }
  815. @override
  816. UserFriendModel createModel() => UserFriendModel(widget.type);
  817. }