Browse Source

首页 加入 筛选

lailin 4 years ago
parent
commit
91026fab05
1 changed files with 48 additions and 35 deletions
  1. 48 35
      taskservice/lib/src/home/home.dart

+ 48 - 35
taskservice/lib/src/home/home.dart

@@ -23,8 +23,8 @@ class _MyHomePageState extends State<MyHomePage> {
   String _searchText;
 
   /*tableView*/
-  List<JXMemberModel> _datasource = List();
-  List<JXMemberModel> _basesource = List();
+  List<Widget> _cells = [];
+  List<JXMemberModel> _basesource = [];
 
   @override
   void initState() {
@@ -48,7 +48,10 @@ class _MyHomePageState extends State<MyHomePage> {
         ..tel = '186'
         ..addr = '广州12',
     ];
-    _datasource = List.from(_basesource);
+
+    for(JXMemberModel model in _basesource) {
+      _cells.add(theCellBuilder(context, model));
+    }
   }
 
   /*筛选列表数据*/
@@ -56,7 +59,7 @@ class _MyHomePageState extends State<MyHomePage> {
     String text = _searchText;
 
     List tmpItems = [];
-    _datasource.clear();
+    _cells.clear();
     print('筛选:$_searchText');
     if (text.isEmpty) {
       tmpItems.addAll(_basesource);
@@ -74,19 +77,17 @@ class _MyHomePageState extends State<MyHomePage> {
         }
       }
     }
-    _datasource = tmpItems;
+    for (JXMemberModel model in tmpItems) {
+      _cells.add(theCellBuilder(context, model));
+    }
     setState(() {});
   }
 
   /*cell*/
-  Widget theCellBuilder(BuildContext context, int row) {
-    if (row >= _datasource.length) {
-      return null;
-    }
-    JXMemberModel model = _datasource[row];
+  Widget theCellBuilder(BuildContext context, JXMemberModel model) {
     return GestureDetector(
         onTap: () {
-          print('click cell, row:$row');
+          print('click cell, name:${model.name}');
         },
         child: Container(
           height: 92.0,
@@ -119,17 +120,18 @@ class _MyHomePageState extends State<MyHomePage> {
                       ),
                     ),
                     Expanded(
-                        child: Container(
-                          padding: EdgeInsets.only(top: 12.0, right: 12.0),
-                          child: Text(
-                            model.tel,
-                            textAlign: TextAlign.right,
-                            style: TextStyle(
-                              fontSize: 16,
-                              color: JXColors.k2E3032,
-                            ),
+                      child: Container(
+                        padding: EdgeInsets.only(top: 12.0, right: 12.0),
+                        child: Text(
+                          model.tel,
+                          textAlign: TextAlign.right,
+                          style: TextStyle(
+                            fontSize: 16,
+                            color: JXColors.k2E3032,
                           ),
-                        ))
+                        ),
+                      ),
+                    )
                   ],
                 ),
                 Row(
@@ -219,17 +221,18 @@ class _MyHomePageState extends State<MyHomePage> {
                   ),
                 ),
                 Expanded(
-                    child: Container(
-                      color: JXColors.kF0F0F0,
-                      child: ListView.builder(
-                        padding: EdgeInsets.only(left: 12.0, right: 12.0),
-                        itemCount: _datasource.length,
-                        itemExtent: 92.0,
-                        itemBuilder: (BuildContext context, int row) {
-                          return theCellBuilder(context, row);
-                        },
-                      ),
-                    )),
+                  child: Container(
+                    color: JXColors.kF0F0F0,
+                    child: ListView.builder(
+                      padding: EdgeInsets.only(left: 12.0, right: 12.0),
+                      itemCount: _cells.length,
+                      itemExtent: 92.0,
+                      itemBuilder: (BuildContext context, int row) {
+                        return _cells[row];
+                      },
+                    ),
+                  ),
+                ),
                 Row(
                   mainAxisAlignment: MainAxisAlignment.start,
                   children: <Widget>[
@@ -241,7 +244,13 @@ class _MyHomePageState extends State<MyHomePage> {
                         padding: EdgeInsets.all(0),
                         color: JXColors.kFFFFFF,
                         borderRadius: BorderRadius.all(Radius.circular(0)),
-                        child: Text('新建会员', style: TextStyle(fontSize: 14, color: JXColors.k101E40)),
+                        child: Text(
+                          '新建会员',
+                          style: TextStyle(
+                            fontSize: 14,
+                            color: JXColors.k101E40,
+                          ),
+                        ),
                       ),
                     ),
                     Expanded(
@@ -252,7 +261,11 @@ class _MyHomePageState extends State<MyHomePage> {
                         padding: EdgeInsets.all(0),
                         color: JXColors.k1F2529,
                         borderRadius: BorderRadius.all(Radius.circular(0)),
-                        child: Text('会员列表', style: TextStyle(fontSize: 14, color: JXColors.kFFFFFF)),
+                        child: Text('会员列表',
+                            style: TextStyle(
+                              fontSize: 14,
+                              color: JXColors.kFFFFFF,
+                            )),
                       ),
                     ),
                   ],
@@ -262,4 +275,4 @@ class _MyHomePageState extends State<MyHomePage> {
           ),
         ));
   }
-}
+}