Commit e973968cec08d4a6828fff10767c6f6a880a91f7

Authored by wdn127929
1 parent 9e9f3f3c

null处理

@@ -38,6 +38,7 @@ class _ContantLeftPageState extends State<ContantLeftPage> { @@ -38,6 +38,7 @@ class _ContantLeftPageState extends State<ContantLeftPage> {
38 "sid": Provider.of<UserModel>(context, listen: false).user.sellerid, 38 "sid": Provider.of<UserModel>(context, listen: false).user.sellerid,
39 }; 39 };
40 await contantShowModel.getUserHistorys(context, params); 40 await contantShowModel.getUserHistorys(context, params);
  41 + await contantShowModel.searchData(contantShowModel.controller.text);
41 } 42 }
42 43
43 @override 44 @override
@@ -63,76 +63,98 @@ class _ContactListPageState extends State<ContactListPage> @@ -63,76 +63,98 @@ class _ContactListPageState extends State<ContactListPage>
63 vertical: ScreenUtil().setWidth(10)), 63 vertical: ScreenUtil().setWidth(10)),
64 height: ScreenUtil().setWidth(45 * 2), 64 height: ScreenUtil().setWidth(45 * 2),
65 // alignment: Alignment.center, 65 // alignment: Alignment.center,
66 - child: Container(  
67 - alignment: Alignment.center,  
68 - padding: EdgeInsets.symmetric(  
69 - horizontal: ScreenUtil().setWidth(20 * 2),  
70 - vertical: ScreenUtil().setWidth(14)),  
71 - decoration: BoxDecoration(  
72 - color: MyColours.color_F0F0F0,  
73 - borderRadius: BorderRadius.circular(  
74 - ScreenUtil().setWidth(24 * 2))),  
75 - child: TextField(  
76 - controller: contantShowModel.controller,  
77 - // focusNode: _focusNode,  
78 - // autofocus: true,  
79 -  
80 - style: TextStyle(  
81 - color: MyColours.color_333333,  
82 - fontSize: ScreenUtil().setSp(30),  
83 - textBaseline: TextBaseline.alphabetic),  
84 - textAlignVertical: TextAlignVertical.center,  
85 - decoration: InputDecoration(  
86 - hintText: "搜索联系人",  
87 - hintStyle: TextStyle(  
88 - color: MyColours.color_999999,  
89 - fontSize: ScreenUtil().setSp(30),  
90 - ),  
91 - isCollapsed:  
92 - true, //重点,相当于高度包裹的意思,必须设置为true,不然有默认奇妙的最小高度  
93 - border: InputBorder.none,  
94 - //左边图标设置  
95 - icon: Image.asset(  
96 - Utils.getImgPath('search'),  
97 - width: ScreenUtil().setWidth(30), 66 + child: Stack(
  67 + children: [
  68 + Container(
  69 + alignment: Alignment.center,
  70 + padding: EdgeInsets.symmetric(
  71 + horizontal: ScreenUtil().setWidth(20 * 2),
  72 + vertical: ScreenUtil().setWidth(14)),
  73 + decoration: BoxDecoration(
  74 + color: MyColours.color_F0F0F0,
  75 + borderRadius: BorderRadius.circular(
  76 + ScreenUtil().setWidth(24 * 2))),
  77 + child: TextField(
  78 + maxLines: 1,
  79 + controller: contantShowModel.controller,
  80 + // focusNode: _focusNode,
  81 + // autofocus: true,
  82 + style: TextStyle(
  83 + color: MyColours.color_333333,
  84 + fontSize: ScreenUtil().setSp(30)),
  85 + // textAlignVertical: TextAlignVertical.center,
  86 + decoration: InputDecoration(
  87 + contentPadding: EdgeInsets.only(
  88 + right: ScreenUtil().setWidth(70 * 2)),
  89 + hintText: "搜索联系人",
  90 + hintStyle: TextStyle(
  91 + color: MyColours.color_999999,
  92 + fontSize: ScreenUtil().setSp(30),
  93 + ),
  94 + isCollapsed:
  95 + true, //重点,相当于高度包裹的意思,必须设置为true,不然有默认奇妙的最小高度
  96 + border: InputBorder.none,
  97 + // 左边图标设置
  98 + icon: Image.asset(
  99 + Utils.getImgPath('search'),
  100 + width: ScreenUtil().setWidth(30),
  101 + ),
  102 + //右边图标设置
  103 + // suffixIcon:
98 ), 104 ),
99 - //右边图标设置  
100 - suffixIcon: contantShowModel  
101 - .controller.text ==  
102 - ''  
103 - ? Container()  
104 - : GestureDetector(  
105 - child: Container(  
106 - height: ScreenUtil().setWidth(30), 105 + keyboardType: TextInputType.text,
  106 + textInputAction: TextInputAction.done,
  107 +
  108 + onChanged: (value) {
  109 + // setState(() {});
  110 + // _searchSellerLocation();
  111 + contantShowModel.searchData(value);
  112 + },
  113 + onEditingComplete: () {
  114 + FocusScope.of(context).requestFocus(
  115 + FocusNode()); //点击空白处隐藏键盘
  116 + // contantShowModel.searchData(
  117 + // contantShowModel.controller.text);
  118 + // _searchSellerLocation();
  119 + // _focusNode.unfocus();
  120 + },
  121 + ),
  122 + ),
  123 + Positioned(
  124 + right: 0,
  125 + top: 0,
  126 + bottom: 0,
  127 + child: Offstage(
  128 + offstage:
  129 + contantShowModel.controller.text ==
  130 + '',
  131 + child: GestureDetector(
  132 + child: Container(
  133 + padding: EdgeInsets.only(
  134 + right: ScreenUtil()
  135 + .setWidth(20 * 2)),
  136 + // color: Colors.orange,
  137 + height:
  138 + ScreenUtil().setWidth(45 * 2),
  139 + width:
  140 + ScreenUtil().setWidth(100 * 2),
  141 + alignment: Alignment.centerRight,
  142 + child: Image.asset(
  143 + Utils.getImgPath('clear'),
107 width: ScreenUtil().setWidth(30), 144 width: ScreenUtil().setWidth(30),
108 - alignment: Alignment.centerRight,  
109 - child: Image.asset(  
110 - Utils.getImgPath('clear'),  
111 - width:  
112 - ScreenUtil().setWidth(30),  
113 - ), 145 + height: ScreenUtil().setWidth(30),
114 ), 146 ),
115 - onTap: () {  
116 - WidgetsBinding.instance  
117 - .addPostFrameCallback(((_) {  
118 - contantShowModel.controller  
119 - .clear();  
120 - contantShowModel.searchData('');  
121 - }));  
122 - },  
123 - )),  
124 - keyboardType: TextInputType.text,  
125 - textInputAction: TextInputAction.search,  
126 - onChanged: (value) {  
127 - setState(() {});  
128 - // _searchSellerLocation();  
129 - contantShowModel.searchData(value);  
130 - },  
131 - onEditingComplete: () {  
132 - // _searchSellerLocation();  
133 - // _focusNode.unfocus();  
134 - },  
135 - ), 147 + ),
  148 + onTap: () {
  149 + WidgetsBinding.instance
  150 + .addPostFrameCallback(((_) {
  151 + contantShowModel.controller
  152 + .clear();
  153 + contantShowModel.searchData('');
  154 + }));
  155 + },
  156 + )))
  157 + ],
136 )), 158 )),
137 Container( 159 Container(
138 padding: EdgeInsets.only( 160 padding: EdgeInsets.only(
@@ -119,6 +119,7 @@ class _ContantRightPageState extends State<ContantRightPage> { @@ -119,6 +119,7 @@ class _ContantRightPageState extends State<ContantRightPage> {
119 contantShowModel.pageStateRight = PageState.Empty; 119 contantShowModel.pageStateRight = PageState.Empty;
120 } 120 }
121 }); 121 });
  122 + await contantShowModel.searchData(contantShowModel.controller.text);
122 } 123 }
123 124
124 @override 125 @override
@@ -89,10 +89,10 @@ class ContantShowModel extends ChangeNotifier { @@ -89,10 +89,10 @@ class ContantShowModel extends ChangeNotifier {
89 // String pinyin = userHistorys[i].pinyin; 89 // String pinyin = userHistorys[i].pinyin;
90 String phone = userHistorys[i].phone; 90 String phone = userHistorys[i].phone;
91 List<String> pinyinList = userHistorys[i].pinyinList; 91 List<String> pinyinList = userHistorys[i].pinyinList;
92 - if (name.contains(key) ||  
93 - pinyinFirst.contains(key) ||  
94 - phone.contains(key) ||  
95 - pinyinList.contains(key)) { 92 + if ((name != null && name.contains(key)) ||
  93 + (pinyinFirst != null && pinyinFirst.contains(key)) ||
  94 + (phone != null && phone.contains(key)) ||
  95 + (pinyinList != null && pinyinList.contains(key))) {
96 userHistorysShow.add(userHistorys[i]); 96 userHistorysShow.add(userHistorys[i]);
97 } 97 }
98 } 98 }
@@ -102,10 +102,10 @@ class ContantShowModel extends ChangeNotifier { @@ -102,10 +102,10 @@ class ContantShowModel extends ChangeNotifier {
102 List<String> pinyinList = contacts[i].pinyinList; 102 List<String> pinyinList = contacts[i].pinyinList;
103 // String pinyin = contacts[i].pinyin; 103 // String pinyin = contacts[i].pinyin;
104 String phone = contacts[i].phone; 104 String phone = contacts[i].phone;
105 - if (name.contains(key) ||  
106 - pinyinFirst.contains(key) ||  
107 - phone.contains(key) ||  
108 - pinyinList.contains(key)) { 105 + if ((name != null && name.contains(key)) ||
  106 + (pinyinFirst != null && pinyinFirst.contains(key)) ||
  107 + (phone != null && phone.contains(key)) ||
  108 + (pinyinList != null && pinyinList.contains(key))) {
109 contactsShow.add(contacts[i]); 109 contactsShow.add(contacts[i]);
110 } 110 }
111 } 111 }
@@ -54,7 +54,7 @@ class NoteBookModel extends ChangeNotifier { @@ -54,7 +54,7 @@ class NoteBookModel extends ChangeNotifier {
54 return Notebook.fromJson(value); 54 return Notebook.fromJson(value);
55 }).toList(); 55 }).toList();
56 if (notebooks.isEmpty) { 56 if (notebooks.isEmpty) {
57 - pageState = PageState.Success; 57 + pageState = PageState.Empty;
58 } else { 58 } else {
59 pageState = PageState.Success; 59 pageState = PageState.Success;
60 } 60 }