Forráskód Böngészése

加入 清楚筛选 功能

lailin 4 éve
szülő
commit
95303378bd
1 módosított fájl, 69 hozzáadás és 51 törlés
  1. 69 51
      taskservice/lib/src/home/home.dart

+ 69 - 51
taskservice/lib/src/home/home.dart

@@ -21,7 +21,7 @@ class _MyHomePageState extends State<MyHomePage> {
   FocusNode blankNode = FocusNode();
 
   /*搜索值*/
-  String _searchText;
+  static final TextEditingController _searchController = TextEditingController();
 
   /*tableView*/
   List<Widget> _cells = [];
@@ -57,11 +57,11 @@ class _MyHomePageState extends State<MyHomePage> {
 
   /*筛选列表数据*/
   void filterMember() {
-    String text = _searchText;
+    String text = _searchController.text;
+    print('筛选:$text');
 
     List tmpItems = [];
     _cells.clear();
-    print('筛选:$_searchText');
     if (text.isEmpty) {
       tmpItems.addAll(_basesource);
     } else {
@@ -84,6 +84,71 @@ class _MyHomePageState extends State<MyHomePage> {
     setState(() {});
   }
 
+  /*筛选空间*/
+  Widget theFilterBar() {
+    return Container(
+      color: JXColors.kF0F0F0,
+      padding: EdgeInsets.fromLTRB(12.0, 8, 12.0, 8),
+      child: Container(
+        alignment: Alignment.center,
+        decoration: BoxDecoration(
+          color: JXColors.kE6E6E6,
+          borderRadius: BorderRadius.circular(12.0),
+          border: Border.all(color: JXColors.kE6E6E6, width: 1),
+        ),
+        height: 44.0,
+        child: Row(children: <Widget>[
+          SizedBox(
+            width: 12,
+          ),
+          Icon(
+            Icons.search,
+            size: 24.0,
+          ),
+          SizedBox(
+            width: 6,
+          ),
+          Expanded(
+            child: TextField(
+              controller: _searchController,
+              maxLines: 1,
+              focusNode: blankNode,
+              obscureText: false,
+              cursorColor: JXColors.k1F2529,
+              decoration: InputDecoration(
+                border: InputBorder.none,
+                hintText: '快速筛选',
+                labelStyle: TextStyle(
+                  color: JXColors.k2E3032,
+                  fontSize: 24.0,
+                ),
+              ),
+              onChanged: (value) {
+                filterMember();
+              },
+            ),
+          ),
+          SizedBox(width: 6,),
+          CupertinoButton(
+            onPressed: (){
+              /*清空输入框*/
+              setState(() {
+                _searchController.clear();
+                filterMember();
+              });
+            },
+            padding: EdgeInsets.all(0),
+            child: Icon(
+              Icons.cancel,
+              color: JXColors.kE6E6E6,
+              size: 24.0,
+            ),
+          ),
+        ]),
+      ),
+    );
+  }
+
   /*cell*/
   Widget theCellBuilder(BuildContext context, JXMemberModel model) {
     return GestureDetector(
@@ -173,54 +238,7 @@ class _MyHomePageState extends State<MyHomePage> {
             child: Column(
               mainAxisAlignment: MainAxisAlignment.start,
               children: <Widget>[
-                Container(
-                  color: JXColors.kF0F0F0,
-                  padding: EdgeInsets.fromLTRB(12.0, 8, 12.0, 8),
-                  child: Container(
-                    alignment: Alignment.center,
-                    decoration: BoxDecoration(
-                      color: JXColors.kE6E6E6,
-                      borderRadius: BorderRadius.circular(12.0),
-                      border: Border.all(color: JXColors.kE6E6E6, width: 1),
-                    ),
-                    height: 44.0,
-                    child: Row(children: <Widget>[
-                      SizedBox(
-                        width: 12,
-                      ),
-                      Icon(
-                        Icons.search,
-                        size: 24.0,
-                      ),
-                      SizedBox(
-                        width: 6,
-                      ),
-                      Expanded(
-                        child: TextField(
-                          maxLines: 1,
-                          focusNode: blankNode,
-                          obscureText: false,
-                          cursorColor: JXColors.k1F2529,
-                          decoration: InputDecoration(
-                            border: InputBorder.none,
-                            hintText: '快速筛选',
-                            labelStyle: TextStyle(
-                              color: JXColors.k2E3032,
-                              fontSize: 24.0,
-                            ),
-                          ),
-                          onChanged: (value) {
-                            _searchText = value;
-                            filterMember();
-                          },
-                        ),
-                      ),
-                      SizedBox(
-                        width: 12,
-                      ),
-                    ]),
-                  ),
-                ),
+                theFilterBar(),
                 Expanded(
                   child: Container(
                     color: JXColors.kF0F0F0,