Hibok
Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 
 
 
 
 

166 righe
6.2 KiB

  1. import 'package:chat/data/UserData.dart';
  2. import 'package:chat/models/friends_info.dart';
  3. import 'package:flutter/material.dart';
  4. import 'package:chat/data/constants.dart';
  5. import 'package:chat/generated/i18n.dart';
  6. import 'package:chat/models/ref_name_provider.dart';
  7. import 'package:chat/utils/CustomUI.dart';
  8. import 'package:chat/utils/conversation_table.dart';
  9. import 'package:chat/utils/friend_list_mgr.dart';
  10. import 'package:flutter/services.dart';
  11. import 'package:provider/provider.dart';
  12. class AddressSearchPage extends StatefulWidget {
  13. @override
  14. _AddressSearchPageState createState() => _AddressSearchPageState();
  15. }
  16. class _AddressSearchPageState extends State<AddressSearchPage> {
  17. ScrollController _scrollController;
  18. TextEditingController _txtCtrl = new TextEditingController();
  19. bool _hasdeleteIcon = false;
  20. List<FriendModel> searchList = [];
  21. List<FriendModel> friendList = [];
  22. FocusNode focusNode;
  23. //var _contactsFuture;
  24. @override
  25. void initState() {
  26. super.initState();
  27. focusNode = new FocusNode();
  28. _scrollController = new ScrollController();
  29. getFriendList();
  30. }
  31. getFriendList() async {
  32. friendList = await FriendListMgr().getFriendList();
  33. if (mounted) {
  34. setState(() {});
  35. }
  36. }
  37. @override
  38. void dispose() {
  39. _scrollController.dispose();
  40. focusNode.dispose();
  41. super.dispose();
  42. }
  43. @override
  44. Widget build(BuildContext context) {
  45. final List<Widget> _body = [];
  46. _body.add(ListView.builder(
  47. controller: _scrollController,
  48. itemBuilder: (BuildContext context, int index) {
  49. FriendModel _contact = searchList[index];
  50. return FriendsInfo(
  51. userId: _contact.friendId,
  52. avatar: _contact.avatar,
  53. title: Provider.of<RefNameProvider>(context)
  54. .getRefName(_contact.friendId, _contact.name),
  55. isShowDivder: true,
  56. groupTitle: null);
  57. },
  58. itemCount: searchList.length,
  59. ));
  60. return Scaffold(
  61. resizeToAvoidBottomPadding: false,
  62. appBar: AppBar(
  63. backgroundColor: AppColors.NewAppbarBgColor,
  64. title: Text(I18n.of(context).search,
  65. textScaleFactor: 1.0, style: Constants.MainTitleStyle),
  66. centerTitle: true,
  67. leading: CustomUI.buildCustomLeading(context),
  68. elevation: 1,
  69. bottom: PreferredSize(
  70. preferredSize: Size.fromHeight(49),
  71. child: Container(
  72. alignment: Alignment.center,
  73. margin: EdgeInsets.only(bottom: 14, left: 12.5, right: 12.5),
  74. height: 35,
  75. decoration: BoxDecoration(
  76. color: const Color(0xFFEEEEEE),
  77. borderRadius: BorderRadius.all(Radius.circular(8))),
  78. child: TextField(
  79. keyboardType: TextInputType.text,
  80. textInputAction: TextInputAction.search,
  81. controller: _txtCtrl,
  82. focusNode: focusNode,
  83. cursorColor: Constants.BlueTextColor,
  84. maxLines: 1,
  85. style: TextStyle(
  86. textBaseline: TextBaseline.alphabetic, fontSize: 14.5),
  87. autofocus: true,
  88. inputFormatters: [
  89. LengthLimitingTextInputFormatter(50),
  90. ],
  91. decoration: InputDecoration(
  92. hintText: I18n.of(context).search,
  93. hintStyle: TextStyle(fontSize: 14.5),
  94. contentPadding: EdgeInsets.only(
  95. left: 20,
  96. top: (UserData().language == LanguageType.English ||
  97. UserData().language ==
  98. LanguageType.Vietnamese)
  99. ? 3
  100. : 10.5,
  101. bottom: 10.5),
  102. prefixIcon: Icon(
  103. IconData(
  104. 0xe664,
  105. fontFamily: Constants.IconFontFamily,
  106. ),
  107. color: const Color(0xFFA0A0A0),
  108. size: 18,
  109. ),
  110. suffixIcon: Padding(
  111. padding: EdgeInsetsDirectional.only(
  112. start: 2.0, end: _hasdeleteIcon ? 20.0 : 0),
  113. child: _hasdeleteIcon
  114. ? new InkWell(
  115. onTap: (() {
  116. setState(() {
  117. WidgetsBinding.instance
  118. .addPostFrameCallback(
  119. (_) => _txtCtrl.clear());
  120. _hasdeleteIcon = false;
  121. });
  122. }),
  123. child: Icon(
  124. Icons.clear,
  125. size: 18.0,
  126. color: Constants.BlackTextColor,
  127. ))
  128. : new Text('')),
  129. filled: true,
  130. fillColor: Colors.transparent,
  131. border: InputBorder.none,
  132. ),
  133. onChanged: (str) async {
  134. setState(() {
  135. if (str.isEmpty) {
  136. _hasdeleteIcon = false;
  137. } else {
  138. _hasdeleteIcon = true;
  139. searchList = CustomUI().getSearchResult(
  140. str, friendList == null ? [] : friendList);
  141. }
  142. });
  143. },
  144. onEditingComplete: () {
  145. FocusScope.of(context).requestFocus(FocusNode());
  146. }),
  147. )),
  148. ),
  149. body: Stack(
  150. children: _body,
  151. ));
  152. }
  153. }