From dcd8b77c6b872ca0ec7c0e117890b68f5e9564a0 Mon Sep 17 00:00:00 2001 From: zhangmeng <494089941@qq.com> Date: Mon, 12 Apr 2021 11:06:27 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20=E5=BE=85=E5=8A=9E?= =?UTF-8?q?=E4=BA=8B=E9=A1=B9=E4=B8=8D=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/models/todo_bussiness/todo_model.dart | 4 +- lib/ui/home/business/business_page.dart | 18 +++--- lib/ui/home/business/business_view.dart | 79 ++++++++++++++++------- lib/ui/home/business/bussiness_func.dart | 13 ---- 4 files changed, 67 insertions(+), 47 deletions(-) delete mode 100644 lib/ui/home/business/bussiness_func.dart diff --git a/lib/models/todo_bussiness/todo_model.dart b/lib/models/todo_bussiness/todo_model.dart index 0d271f9..b760095 100644 --- a/lib/models/todo_bussiness/todo_model.dart +++ b/lib/models/todo_bussiness/todo_model.dart @@ -21,9 +21,7 @@ class ToDoModel { : null; break; default: - dynamicModel = json['dataList'] != null - ? [] - : null; + dynamicModel = []; } } diff --git a/lib/ui/home/business/business_page.dart b/lib/ui/home/business/business_page.dart index 1fb6ea8..a2807c4 100644 --- a/lib/ui/home/business/business_page.dart +++ b/lib/ui/home/business/business_page.dart @@ -56,17 +56,17 @@ class _BusinessPageState extends State ), body: TabBarView( controller: _tabController, - children: [ - _buildTabPage(AllModel(context).waitThings), - _buildTabPage(AllModel(context).processingThings), - _buildTabPage(AllModel(context).doneThings), - _buildTabPage(AllModel(context).allThings), - ], + children: List.generate( + _tabs.length, + (index) => BussinessView( + backlogStatus: index + 1, + ), + ), ), ); } - Widget _buildTabPage(List list) { + Widget _buildTabPage(int status) { // return ListView.builder( // padding: EdgeInsets.symmetric(horizontal: 32.w), // itemBuilder: (context, index) { @@ -80,6 +80,8 @@ class _BusinessPageState extends State // }, // itemCount: list.length, // ); - return BussinessView(); + return BussinessView( + backlogStatus: status, + ); } } diff --git a/lib/ui/home/business/business_view.dart b/lib/ui/home/business/business_view.dart index da82f19..54ae3e8 100644 --- a/lib/ui/home/business/business_view.dart +++ b/lib/ui/home/business/business_view.dart @@ -2,14 +2,12 @@ import 'package:aku_community_manager/const/api.dart'; import 'package:aku_community_manager/models/manager/bussiness_and_fix/bussiness_and_fix_model.dart'; import 'package:aku_community_manager/models/todo_bussiness/todo_model.dart'; import 'package:aku_community_manager/models/todo_bussiness/todo_outdoor_model.dart'; -import 'package:aku_community_manager/ui/home/business/bussiness_func.dart'; import 'package:aku_community_manager/ui/home/business/todo_outdoor_card.dart'; import 'package:aku_community_manager/ui/sub_pages/business_and_fix/business_fix_card.dart'; import 'package:aku_community_manager/utils/network/net_util.dart'; import 'package:dio/dio.dart'; import 'package:flutter/material.dart'; import 'package:flutter_easyrefresh/easy_refresh.dart'; -import 'package:velocity_x/velocity_x.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; class BussinessView extends StatefulWidget { @@ -20,30 +18,65 @@ class BussinessView extends StatefulWidget { _BussinessViewState createState() => _BussinessViewState(); } -class _BussinessViewState extends State { +class _BussinessViewState extends State + with AutomaticKeepAliveClientMixin { List _modelList; + EasyRefreshController _refreshController; + @override + void initState() { + super.initState(); + _refreshController = EasyRefreshController(); + } + + @override + void dispose() { + _refreshController?.dispose(); + super.dispose(); + } + @override Widget build(BuildContext context) { + super.build(context); return EasyRefresh( - firstRefresh: true, - header: MaterialHeader(), - onRefresh: () async { - List dataList = - await BussinessFunc.getBussinessModelList(widget.backlogStatus); - _modelList = dataList.map((e) => ToDoModel.fromJson(e)).toList(); - }, - child: ListView( - children: [ - ..._modelList.map((e) { - if (e.runtimeType == BussinessAndFixModel) { - BusinessFixCard(model: e); - } else if (e.runtimeType == ToDoOutDoorModel) { - ToDoOutDoorCard( - model: e, - ); - } - }).toList() - ], - )); + firstRefresh: true, + controller: _refreshController, + header: MaterialHeader(), + onRefresh: () async { + var dataList = await getBussinessModelList(widget.backlogStatus); + _modelList = dataList.map((e) => ToDoModel.fromJson(e)).toList(); + setState(() {}); + }, + child: _modelList == null + ? _emptyWidget() + : ListView( + padding: EdgeInsets.symmetric(horizontal: 10.w, vertical: 10.w), + children: [ + ..._modelList.map((e) { + if (e.dynamicModel.runtimeType == BussinessAndFixModel) { + return BusinessFixCard(model: e.dynamicModel); + } else if (e.dynamicModel.runtimeType == ToDoOutDoorModel) { + return ToDoOutDoorCard( + model: e.dynamicModel, + ); + } + }).toList() + ], + ), + ); } + + Widget _emptyWidget() { + return SizedBox(); + } + + Future getBussinessModelList(int backlogStatus) async { + Response response = + await NetUtil().dio.get(API.manage.backlogList, queryParameters: { + "backlogStatus": backlogStatus, + }); + return response.data['data'] as List; + } + + @override + bool get wantKeepAlive => true; } diff --git a/lib/ui/home/business/bussiness_func.dart b/lib/ui/home/business/bussiness_func.dart deleted file mode 100644 index 43d80f0..0000000 --- a/lib/ui/home/business/bussiness_func.dart +++ /dev/null @@ -1,13 +0,0 @@ -import 'package:aku_community_manager/const/api.dart'; -import 'package:aku_community_manager/utils/network/net_util.dart'; -import 'package:dio/dio.dart'; - -class BussinessFunc { - static Future getBussinessModelList(int backlogStatus) async { - Response response = - await NetUtil().dio.get(API.manage.backlogList, queryParameters: { - "backlogStatus": backlogStatus, - }); - return response.data as List; - } -}