diff --git a/lib/ui/sub_pages/visitor_manager/visitor_manager_page.dart b/lib/ui/sub_pages/visitor_manager/visitor_manager_page.dart index 1dc0cef..d4d90fa 100644 --- a/lib/ui/sub_pages/visitor_manager/visitor_manager_page.dart +++ b/lib/ui/sub_pages/visitor_manager/visitor_manager_page.dart @@ -5,7 +5,7 @@ import 'package:aku_community_manager/ui/widgets/inner/aku_tab_bar.dart'; import 'package:flutter/material.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; -enum VisitorStatus{ +enum VisitorStatus { NOT_VISIT, VISIT_DONE, OUTDATE, @@ -17,7 +17,8 @@ class VisitorCardsModel { String plate; String time; VisitorStatus status; - VisitorCardsModel(this.adress,this.name, this.status,{this.plate,this.time}); + VisitorCardsModel(this.adress, this.name, this.status, + {this.plate, this.time}); } class VisitorManagerPage extends StatefulWidget { @@ -30,12 +31,18 @@ class VisitorManagerPage extends StatefulWidget { class _VisitorManagerPageState extends State with TickerProviderStateMixin { - List tabs = ['全部', '未到访', '已到访', '已过期']; + List _tabs = ['全部', '未到访', '已到访', '已过期']; - List cards=[ - VisitorCardsModel('深圳华悦茂峰1幢1单元702', '马泽城',VisitorStatus.VISIT_DONE, plate:'浙BA9899',time:'2020-10-24 12:00',), - VisitorCardsModel('深圳华悦茂峰2幢2单元702', '刘揪心',VisitorStatus.NOT_VISIT), - VisitorCardsModel('深圳华悦茂峰3幢3单元602', '刘揪心',VisitorStatus.OUTDATE), + List _cards = [ + VisitorCardsModel( + '深圳华悦茂峰1幢1单元702', + '马泽城', + VisitorStatus.VISIT_DONE, + plate: '浙BA9899', + time: '2020-10-24 12:00', + ), + VisitorCardsModel('深圳华悦茂峰2幢2单元702', '刘揪心', VisitorStatus.NOT_VISIT), + VisitorCardsModel('深圳华悦茂峰3幢3单元602', '刘揪心', VisitorStatus.OUTDATE), ]; TabController _tabController; @@ -46,22 +53,85 @@ class _VisitorManagerPageState extends State TabController(length: 4, vsync: this, initialIndex: widget.initIndex); } + @override + void dispose() { + _tabController?.dispose(); + super.dispose(); + } + @override Widget build(BuildContext context) { return AkuScaffold( - title: '访客管理', - appBarBottom: PreferredSize( - child: AkuTabBar( - tabs: tabs, - controller: _tabController, - ), - preferredSize: Size.fromHeight(88.w)), - body: ListView( - padding: EdgeInsets.only(left:32.w,right:32.w), - children: [ - ...cards.map((e) => VisitorManagerCard(adress: e.adress,name: e.name,plate: e.plate,time: e.time,)).toList(), - ], - ), + title: '访客管理', + appBarBottom: PreferredSize( + child: AkuTabBar( + tabs: _tabs, + controller: _tabController, + ), + preferredSize: Size.fromHeight(88.w)), + body: TabBarView( + controller: _tabController, + // children: _tabs.map((e) => _buildTabView(_tabs.indexOf(e))).toList(),) + // children: [ + // ListView( + // padding: EdgeInsets.only(left: 32.w, right: 32.w), + // children: _cards + // .map((e) => VisitorManagerCard( + // adress: e.adress, + // name: e.name, + // plate: e.plate, + // time: e.time, + // )) + // .toList(), + // ), + // ListView( + // padding: EdgeInsets.only(left: 32.w, right: 32.w), + // children: _cards + // .where((element) => element.status == VisitorStatus.NOT_VISIT) + // .map((e) => VisitorManagerCard( + // adress: e.adress, + // name: e.name, + // plate: e.plate, + // time: e.time, + // )) + // .toList(), + // ), + // ListView(), + // ListView(), + // ], + children: _tabs.map((e) => _buildListView(_tabs.indexOf(e))).toList(), + )); + } + + Widget _buildListView(int index) { + List _selectCards; + switch (index) { + case 0: + _selectCards = _cards; + break; + case 1: + _selectCards = _cards + .where((element) => element.status == VisitorStatus.NOT_VISIT).toList(); + break; + case 2: + _selectCards = _cards + .where((element) => element.status == VisitorStatus.VISIT_DONE).toList(); + break; + case 3: + _selectCards = + _cards.where((element) => element.status == VisitorStatus.OUTDATE).toList(); + break; + } + return ListView( + padding: EdgeInsets.only(left: 32.w, right: 32.w), + children: _selectCards + .map((e) => VisitorManagerCard( + adress: e.adress, + name: e.name, + plate: e.plate, + time: e.time, + )) + .toList(), ); } }