From 0ea1f6cee50a78d7d37584c18f1da1abed722e3c Mon Sep 17 00:00:00 2001 From: laiiihz Date: Thu, 25 Mar 2021 18:54:10 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=88=91=E7=9A=84=E6=88=BF?= =?UTF-8?q?=E5=B1=8B=E9=A1=B5=E9=9D=A2=E6=B7=BB=E5=8A=A0=E6=97=B6=E9=97=B4?= =?UTF-8?q?=E9=80=89=E6=8B=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/ui/profile/house/add_house_page.dart | 53 +++++++++++++++++++++++- 1 file changed, 51 insertions(+), 2 deletions(-) diff --git a/lib/ui/profile/house/add_house_page.dart b/lib/ui/profile/house/add_house_page.dart index 26c7c7d7..9bcac100 100644 --- a/lib/ui/profile/house/add_house_page.dart +++ b/lib/ui/profile/house/add_house_page.dart @@ -1,6 +1,5 @@ import 'package:akuCommunity/ui/profile/house/house_item.dart'; import 'package:akuCommunity/ui/profile/house/pick_building_page.dart'; -import 'package:akuCommunity/ui/profile/house/pick_plot_page.dart'; import 'package:akuCommunity/ui/profile/house/pick_role_page.dart'; import 'package:akuCommunity/widget/bee_scaffold.dart'; import 'package:flustars/flustars.dart'; @@ -23,6 +22,8 @@ class _AddHousePageState extends State { GlobalKey _formKey = GlobalKey(); HouseItem _item; int _roleType; + DateTimeRange _range; + TextStyle get _hintStyle => TextStyle( fontSize: 36.sp, fontWeight: FontWeight.bold, @@ -30,9 +31,16 @@ class _AddHousePageState extends State { ); TextStyle get _textStyle => _hintStyle.copyWith(color: Color(0xFF333333)); + // 仅在租客身份下检查租期是否填写 + bool get _rentCheck => _roleType != 3 ? true : _range != null; + /// 检查按钮是否可点击 bool get _buttonCanTap => - _nameController.text.isNotEmpty && _idController.text.isNotEmpty; + _nameController.text.isNotEmpty && + _idController.text.isNotEmpty && + _item != null && + _roleType != null && + _rentCheck; _renderTile({ String title, Widget item, @@ -101,6 +109,41 @@ class _AddHousePageState extends State { ); } + _renderDatePicker() { + String start = DateUtil.formatDate(_range?.start, format: 'yyyy-MM-dd'); + String end = DateUtil.formatDate(_range?.end, format: 'yyyy-MM-dd'); + bool emptyDate = _range == null; + String startValue = emptyDate ? '请选择开始时间' : start; + String endValue = emptyDate ? '请选择结束时间' : end; + return MaterialButton( + padding: EdgeInsets.symmetric(horizontal: 32.w, vertical: 30.w), + onPressed: () async { + DateTimeRange range = await showDateRangePicker( + context: context, + builder: (context, child) { + return Theme( + data: ThemeData(primarySwatch: Colors.yellow), + child: child, + ); + }, + firstDate: DateTime.now().subtract(Duration(days: 30)), + lastDate: DateTime.now().add(Duration(days: 365 * 10)), + ); + if (range != null) _range = range; + setState(() {}); + }, + child: Row( + children: [ + Text(startValue, style: emptyDate ? _hintStyle : _textStyle), + Expanded( + child: Icon(Icons.arrow_forward, color: Color(0xFF999999)), + ), + Text(endValue, style: emptyDate ? _hintStyle : _textStyle), + ], + ), + ); + } + @override void dispose() { _nameController?.dispose(); @@ -177,6 +220,12 @@ class _AddHousePageState extends State { }, ), ), + if (_roleType == 3) + _renderTile( + title: '租期', + item: _renderDatePicker(), + ), + SizedBox(), ].sepWidget( separate: Divider( indent: 32.w,