|
@@ -0,0 +1,194 @@
|
|
|
|
+import 'package:flutter/cupertino.dart';
|
|
|
|
+import 'package:flutter/material.dart';
|
|
|
|
+import 'package:taskservice/Common/JXColors.dart';
|
|
|
|
+import 'package:taskservice/Model/JXServiceModel.dart';
|
|
|
|
+import '../custom_widgets.dart';
|
|
|
|
+
|
|
|
|
+class CreateServiceList extends StatefulWidget {
|
|
|
|
+ @override
|
|
|
|
+ _CreateServiceList createState() => _CreateServiceList();
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+class _CreateServiceList extends State<CreateServiceList> {
|
|
|
|
+ /*搜索栏*/
|
|
|
|
+ TextEditingController _searchBar = TextEditingController();
|
|
|
|
+
|
|
|
|
+ /*服务数组*/
|
|
|
|
+ List <JXServiceModel> _baseServices = [];
|
|
|
|
+ /*cells*/
|
|
|
|
+ List <JXServiceModel> _displayItems = [];
|
|
|
|
+
|
|
|
|
+ @override
|
|
|
|
+ void initState() {
|
|
|
|
+ // TODO: implement initState
|
|
|
|
+ super.initState();
|
|
|
|
+ _baseServices = [
|
|
|
|
+ JXServiceModel()
|
|
|
|
+ ..kind = '清洗'
|
|
|
|
+ ..cycle = 2
|
|
|
|
+ ..cycleUnit = '月'
|
|
|
|
+ ..remark = '带清洁工具',
|
|
|
|
+ JXServiceModel()
|
|
|
|
+ ..kind = '除胶'
|
|
|
|
+ ..cycle = 1
|
|
|
|
+ ..cycleUnit = '月'
|
|
|
|
+ ..remark = '带清洁工具',
|
|
|
|
+ JXServiceModel()
|
|
|
|
+ ..kind = '换水'
|
|
|
|
+ ..cycle = 1
|
|
|
|
+ ..cycleUnit = '月'
|
|
|
|
+ ..remark = '带清洁工具',
|
|
|
|
+ JXServiceModel()
|
|
|
|
+ ..kind = '换滤芯'
|
|
|
|
+ ..cycle = 4
|
|
|
|
+ ..cycleUnit = '月'
|
|
|
|
+ ..remark = '带清洁工具',
|
|
|
|
+ JXServiceModel()
|
|
|
|
+ ..kind = '换电机'
|
|
|
|
+ ..cycle = 5
|
|
|
|
+ ..cycleUnit = '月'
|
|
|
|
+ ..remark = '带清洁工具',
|
|
|
|
+ ];
|
|
|
|
+ filterSevice();
|
|
|
|
+ }
|
|
|
|
+ @override
|
|
|
|
+ Widget build(BuildContext context) {
|
|
|
|
+ // TODO: implement build
|
|
|
|
+ return MyScaffold(
|
|
|
|
+ title: '服务列表',
|
|
|
|
+ actions: <Widget>[
|
|
|
|
+ IconButton(
|
|
|
|
+ icon: Icon(Icons.add),
|
|
|
|
+ iconSize: 34.0,
|
|
|
|
+ tooltip: 'Add',
|
|
|
|
+ onPressed: addBtnClickAction,
|
|
|
|
+ ),
|
|
|
|
+ ],
|
|
|
|
+ body: Column(
|
|
|
|
+ children: <Widget>[
|
|
|
|
+ SearchBar(
|
|
|
|
+ onTextChanged: (value){
|
|
|
|
+ filterSevice();
|
|
|
|
+ },
|
|
|
|
+ hint: '输入服务类型',
|
|
|
|
+ onBtnClear: (){
|
|
|
|
+ setState(() {
|
|
|
|
+ _searchBar.clear();
|
|
|
|
+ filterSevice();
|
|
|
|
+ });
|
|
|
|
+ },
|
|
|
|
+ searchController: _searchBar,
|
|
|
|
+ ),
|
|
|
|
+ Expanded(
|
|
|
|
+ child: CustomScrollView(
|
|
|
|
+ physics: BouncingScrollPhysics(),
|
|
|
|
+ slivers: <Widget>[
|
|
|
|
+ SliverList(
|
|
|
|
+ delegate: SliverChildBuilderDelegate((BuildContext context, int index) {
|
|
|
|
+ if (index < _displayItems.length) {
|
|
|
|
+ var service = _displayItems[index];
|
|
|
|
+ return theCellBuilder(service);
|
|
|
|
+ } else {
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+ }),
|
|
|
|
+ ),
|
|
|
|
+ ],
|
|
|
|
+ ),
|
|
|
|
+ ),
|
|
|
|
+ Container(
|
|
|
|
+ padding: EdgeInsets.all(0),
|
|
|
|
+ width: MediaQuery.of(context).size.width,
|
|
|
|
+ height: 44.0,
|
|
|
|
+ child: CupertinoButton(
|
|
|
|
+ onPressed: saveBtnClickAction,
|
|
|
|
+ color: JXColors.k101E40,
|
|
|
|
+ borderRadius: BorderRadius.all(Radius.circular(0)),
|
|
|
|
+ child: Text(
|
|
|
|
+ '保存',
|
|
|
|
+ style: TextStyle(
|
|
|
|
+ fontSize: 14,
|
|
|
|
+ color: JXColors.kFFFFFF,
|
|
|
|
+ ),
|
|
|
|
+ ),
|
|
|
|
+ ),
|
|
|
|
+ ),
|
|
|
|
+ ],
|
|
|
|
+ ),
|
|
|
|
+ );
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /*cell*/
|
|
|
|
+ Widget theCellBuilder(JXServiceModel service) {
|
|
|
|
+ return GestureDetector(
|
|
|
|
+ onTap: (){
|
|
|
|
+ print('click cell, name:${service.kind}');
|
|
|
|
+ },
|
|
|
|
+ child: Container(
|
|
|
|
+ padding: EdgeInsets.symmetric(horizontal: 16),
|
|
|
|
+ color: JXColors.kFFFFFF,
|
|
|
|
+ alignment: Alignment.topCenter,
|
|
|
|
+ child: Column(
|
|
|
|
+ children: <Widget>[
|
|
|
|
+ SizedBox(height: 8,),
|
|
|
|
+ Row(
|
|
|
|
+ mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
|
|
+ children: <Widget>[
|
|
|
|
+ Text('类型: ${service.kind}'),
|
|
|
|
+ Text('周期: ${service.cycle}${service.cycleUnit}'),
|
|
|
|
+ ],
|
|
|
|
+ ),
|
|
|
|
+ SizedBox(height: 20,),
|
|
|
|
+ Row(
|
|
|
|
+ children: <Widget>[
|
|
|
|
+ Text('备注 ${service.remark}'),
|
|
|
|
+ ],
|
|
|
|
+ ),
|
|
|
|
+ SizedBox(height: 8,),
|
|
|
|
+ Divider(
|
|
|
|
+ height: 2,
|
|
|
|
+ thickness: 2,
|
|
|
|
+ ),
|
|
|
|
+ ],
|
|
|
|
+ ),
|
|
|
|
+ ),
|
|
|
|
+ );
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /*筛选服务*/
|
|
|
|
+ void filterSevice() {
|
|
|
|
+ String text = _searchBar.text;
|
|
|
|
+ print('筛选:$text');
|
|
|
|
+
|
|
|
|
+ _displayItems.clear();
|
|
|
|
+ if (text.isEmpty) {
|
|
|
|
+ _displayItems.addAll(_baseServices);
|
|
|
|
+ } else {
|
|
|
|
+ for (JXServiceModel service in _baseServices) {
|
|
|
|
+ bool has = false;
|
|
|
|
+ /*filter kind*/
|
|
|
|
+ if (service.kind.toLowerCase().contains(text.toLowerCase())) {
|
|
|
|
+ _displayItems.add(service);
|
|
|
|
+ has = true;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ setState(() {});
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /*保存*/
|
|
|
|
+ void saveBtnClickAction() {
|
|
|
|
+ print('保存');
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /*添加信息的服务*/
|
|
|
|
+ void addBtnClickAction() {
|
|
|
|
+ print('添加服务');
|
|
|
|
+ _baseServices.add(JXServiceModel()
|
|
|
|
+ ..kind = ''
|
|
|
|
+ ..cycle = 2
|
|
|
|
+ ..cycleUnit = '日'
|
|
|
|
+ ..remark = '测试');
|
|
|
|
+ filterSevice();
|
|
|
|
+ }
|
|
|
|
+}
|