From 378dfe64124d0e58aedee46add0651c985c8e0c1 Mon Sep 17 00:00:00 2001 From: zhang <494089941@qq.com> Date: Wed, 27 Jan 2021 14:14:20 +0800 Subject: [PATCH] rewrite deto create page --- .../deto_create_page/deto_create_page.dart | 187 ++++++++++++------ .../widget/common_picker.dart | 2 +- .../deto_create_page/widget/common_radio.dart | 96 ++++----- .../widget/add_fixed_submit_page.dart | 39 ++-- lib/utils/headers.dart | 1 + 5 files changed, 201 insertions(+), 124 deletions(-) diff --git a/lib/pages/goods_deto_page/deto_create_page/deto_create_page.dart b/lib/pages/goods_deto_page/deto_create_page/deto_create_page.dart index 608dbf88..df0ffeb9 100644 --- a/lib/pages/goods_deto_page/deto_create_page/deto_create_page.dart +++ b/lib/pages/goods_deto_page/deto_create_page/deto_create_page.dart @@ -1,15 +1,22 @@ // Flutter imports: + +import 'dart:io'; + +import 'package:akuCommunity/base/base_style.dart'; +import 'package:akuCommunity/provider/user_provider.dart'; +import 'package:akuCommunity/widget/buttons/bottom_button.dart'; +import 'package:akuCommunity/widget/buttons/radio_button.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; // Project imports: -import 'package:akuCommunity/base/assets_image.dart'; import 'package:akuCommunity/utils/headers.dart'; import 'package:akuCommunity/widget/bee_scaffold.dart'; -import 'package:akuCommunity/widget/bottom_button.dart'; import 'package:akuCommunity/widget/picker/grid_image_picker.dart'; +import 'package:provider/provider.dart'; import 'widget/common_picker.dart'; import 'widget/common_radio.dart'; +import 'package:akuCommunity/const/resource.dart'; class DetoCreatePage extends StatefulWidget { DetoCreatePage({Key key}) : super(key: key); @@ -19,18 +26,27 @@ class DetoCreatePage extends StatefulWidget { } class _DetoCreatePageState extends State { - List> _listWeight = [ - {'title': '< 50kg', 'isCheck': true}, - {'title': '50kg-100kg', 'isCheck': false}, - {'title': '> 100kg', 'isCheck': false} - ]; + List _files = []; + UserProvider get userProvider => Provider.of(context); + String get firstEstateName { + return userProvider.userDetailModel.estateNames.isEmpty + ? '' + : userProvider.userDetailModel.estateNames[0]; + } - List> _listMode = [ - {'title': '自己搬运', 'isCheck': true}, - {'title': '搬家公司', 'isCheck': false}, + int _selectWeight; + List _listWeight = [ + '< 50kg', + '50kg-100kg', + '> 100kg', + ]; + int _selectApproach; + List _listMode = [ + '自己搬运', + '搬家公司', ]; - bool isCheck = false; + bool needMoveCompany = false; Widget _houseAddress(String title, subtitle) { return Container( @@ -60,7 +76,7 @@ class _DetoCreatePageState extends State { Container( margin: EdgeInsets.only(right: 42.w), child: Image.asset( - AssetsImage.HOUSEATTESTATION, + R.ASSETS_IMAGES_HOUSE_ATTESTATION_PNG, height: 59.w, width: 59.w, ), @@ -102,11 +118,11 @@ class _DetoCreatePageState extends State { mainAxisAlignment: MainAxisAlignment.start, children: [ Checkbox( - value: this.isCheck, + value: needMoveCompany, activeColor: Color(0xffffc40c), onChanged: (bool val) { this.setState(() { - this.isCheck = !this.isCheck; + needMoveCompany=!needMoveCompany; }); }, ), @@ -125,7 +141,7 @@ class _DetoCreatePageState extends State { ); } - Widget _checkCard(String title, List> list) { + Widget _getWeight() { return Container( height: 96.w, padding: EdgeInsets.symmetric(vertical: 28.w), @@ -138,21 +154,70 @@ class _DetoCreatePageState extends State { Container( margin: EdgeInsets.only(right: 30.w), child: Text( - title, + '物品重量', style: TextStyle(fontSize: 28.sp, color: Color(0xff333333)), ), ), - CommonRadio( - commonlist: list, - fun: (int index) { - setState(() { - list.forEach((item) { - item['isCheck'] = false; - }); - list[index]['isCheck'] = true; - }); - }, - ) + ...List.generate( + _listWeight.length, + (index) => GestureDetector( + onTap: () { + setState(() { + _selectWeight = index; + }); + }, + child: CommonRadio( + size: 30.w, + text: _listWeight[index] + .text + .color(ktextPrimary) + .size(28.sp) + .make(), + value: index, + groupValue: _selectWeight, + ), + )), + ], + ), + ); + } + + Widget _getApproach() { + return Container( + height: 96.w, + padding: EdgeInsets.symmetric(vertical: 28.w), + decoration: BoxDecoration( + border: + Border(bottom: BorderSide(color: Color(0xffeeeeee), width: 0.5)), + ), + child: Row( + children: [ + Container( + margin: EdgeInsets.only(right: 30.w), + child: Text( + '搬运方式', + style: TextStyle(fontSize: 28.sp, color: Color(0xff333333)), + ), + ), + ...List.generate( + _listMode.length, + (index) => GestureDetector( + onTap: () { + setState(() { + _selectApproach = index; + }); + }, + child: CommonRadio( + size: 30.w, + text: _listMode[index] + .text + .color(ktextPrimary) + .size(28.sp) + .make(), + value: index, + groupValue: _selectApproach, + ), + )), ], ), ); @@ -162,45 +227,41 @@ class _DetoCreatePageState extends State { Widget build(BuildContext context) { return BeeScaffold( title: '物品出户', - body: Container( - color: Colors.white, - child: Stack( - children: [ - Container( - padding: EdgeInsets.only( - left: 32.w, - right: 32.w, - top: 32.w, - ), - child: ListView( - children: [ - _houseAddress('宁波华茂悦峰', '1幢-1单元-702室'), - _checkCard('物品重量', _listWeight), - CommonPicker(title: '出户时间'), - CommonPicker(title: '物品名称'), - _checkCard('搬运方式', _listMode), - _inkWellCheckbox(), - Container( - margin: EdgeInsets.only(top: 54.w, bottom: 24.w), - child: Text( - '添加图片信息(0/9)', - style: TextStyle( - fontSize: 28.sp, - color: Color(0xff333333), - ), - ), - ), - GridImagePicker(onChange: (files) {}), - ], + body: ListView( + padding: EdgeInsets.all(32.w), + children: [ + _houseAddress(kEstateName, firstEstateName), + _getWeight(), + CommonPicker(title: '出户时间'), + CommonPicker(title: '物品名称'), + _getApproach(), + _selectApproach==0?SizedBox(): _inkWellCheckbox(), + Container( + margin: EdgeInsets.only(top: 54.w, bottom: 24.w), + child: Text( + '添加图片信息(${_files.length}/9)', + style: TextStyle( + fontSize: 28.sp, + color: Color(0xff333333), ), ), - Positioned( - bottom: 0, - child: BottomButton(title: '确认提交'), - ) - ], - ), + ), + GridImagePicker(onChange: (files) { + _files = files; + setState(() {}); + }), + ], + ), + bottomNavi: BottomButton( + child: '确认提交'.text.color(ktextPrimary).bold.make(), + onPressed: () {}, ), ); + // Positioned( + // bottom: 0, + // child: BottomButton(title: '确认提交'), + // ) + // ], + // ), } } diff --git a/lib/pages/goods_deto_page/deto_create_page/widget/common_picker.dart b/lib/pages/goods_deto_page/deto_create_page/widget/common_picker.dart index e9e51453..37272b63 100644 --- a/lib/pages/goods_deto_page/deto_create_page/widget/common_picker.dart +++ b/lib/pages/goods_deto_page/deto_create_page/widget/common_picker.dart @@ -10,7 +10,7 @@ import 'package:flutter_picker/flutter_picker.dart'; // Project imports: import 'package:akuCommunity/utils/headers.dart'; import 'package:akuCommunity/widget/picker/bee_date_picker.dart'; - +@Deprecated('s**t code should be remove') class CommonPicker extends StatefulWidget { final String title; CommonPicker({Key key, this.title}) : super(key: key); diff --git a/lib/pages/goods_deto_page/deto_create_page/widget/common_radio.dart b/lib/pages/goods_deto_page/deto_create_page/widget/common_radio.dart index 312fa61b..ca5d86fc 100644 --- a/lib/pages/goods_deto_page/deto_create_page/widget/common_radio.dart +++ b/lib/pages/goods_deto_page/deto_create_page/widget/common_radio.dart @@ -1,64 +1,64 @@ -// Flutter imports: -import 'package:flutter/cupertino.dart'; -import 'package:flutter/material.dart'; - -// Project imports: import 'package:akuCommunity/base/base_style.dart'; +import 'package:akuCommunity/widget/animated/animated_scale.dart'; +import 'package:flutter/material.dart'; import 'package:akuCommunity/utils/headers.dart'; -class CommonRadio extends StatefulWidget { - final List> commonlist; - final Function fun; - CommonRadio({Key key, this.commonlist, this.fun}) : super(key: key); +class CommonRadio extends StatefulWidget { + final T value; + final T groupValue; + final Widget text; + final double size; + CommonRadio({Key key, this.value, this.groupValue, this.text, this.size}) + : super(key: key); @override _CommonRadioState createState() => _CommonRadioState(); } class _CommonRadioState extends State { - InkWell _inkWellRadio(String title, bool isCheck,int index, Function fun) { - return InkWell( - onTap: () { - fun(index); - }, - child: Container( - margin: EdgeInsets.only(left: 20.w), - child: Row( - children: [ - Icon( - isCheck - ? Icons.radio_button_checked - : Icons.radio_button_unchecked, - size: 32.w, - color: isCheck ? BaseStyle.colorffc40c : BaseStyle.color979797, - ), - SizedBox(width: 10.w), - Text( - title, - style: TextStyle( - fontSize: BaseStyle.fontSize28, color: ktextPrimary), - ), - ], - ), - ), - ); + bool get _selected => widget.value == widget.groupValue; + double get smallSize { + return widget.size.isNull ? 24.w : (widget.size * 24 / 40); } @override Widget build(BuildContext context) { - return Container( - child: Row( - children: widget.commonlist - .asMap() - .keys - .map((index) => _inkWellRadio( - widget.commonlist[index]['title'], - widget.commonlist[index]['isCheck'], - index, - widget.fun - )) - .toList(), - ), + return Row( + children: [ + AnimatedContainer( + height: widget.size ?? 40.w, + width: widget.size ?? 40.w, + decoration: BoxDecoration( + border: Border.all( + color: _selected ? kPrimaryColor : Color(0xFF979797), + width: 3.w, + ), + borderRadius: BorderRadius.circular(20.w), + ), + duration: Duration(milliseconds: 300), + curve: Curves.easeInOutCubic, + alignment: Alignment.center, + child: AnimatedOpacity( + duration: Duration(milliseconds: 300), + curve: Curves.easeInOutCubic, + opacity: _selected ? 1 : 0, + child: AnimatedScale( + scale: _selected ? 1 : 0, + child: Container( + height: smallSize, + width: smallSize, + decoration: BoxDecoration( + color: kPrimaryColor, + borderRadius: BorderRadius.circular(12.w), + ), + ), + ), + ), + ), + 10.w.widthBox, + widget.text, + 10.w.widthBox, + ], ); } } diff --git a/lib/pages/things_page/widget/add_fixed_submit_page.dart b/lib/pages/things_page/widget/add_fixed_submit_page.dart index 99bb0ecc..aeb44e0b 100644 --- a/lib/pages/things_page/widget/add_fixed_submit_page.dart +++ b/lib/pages/things_page/widget/add_fixed_submit_page.dart @@ -38,7 +38,7 @@ class _AddFixedSubmitPageState extends State { String reportText; List _buttons = ['公区保修', '家庭维修']; int _selectType; - List _files=[]; + List _files = []; @override void initState() { super.initState(); @@ -182,16 +182,27 @@ class _AddFixedSubmitPageState extends State { child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ - '添加图片信息(${0}/9)'.text.black.size(28.sp).make(), + '添加图片信息(${_files.length}/9)'.text.black.size(28.sp).make(), 24.w.heightBox, GridImagePicker(onChange: (files) { _files = files; + setState(() {}); }) ], ), ); } + bool _canSubmit(int seletType, String text) { + if (seletType.isNull) { + return false; + } else if (text.isEmpty) { + return false; + } else { + return true; + } + } + @override Widget build(BuildContext context) { UserProvider userProvider = Provider.of(context); @@ -214,16 +225,20 @@ class _AddFixedSubmitPageState extends State { MaterialButton( minWidth: double.infinity, height: 98.w, - onPressed: () async { - List urls = - await NetUtil().uploadFiles(_files, API.upload.uploadRepair); - BaseModel baseModel = await ManagerFunc.reportRepairInsert( - _selectType + 1, _textEditingController.text, urls); - if (baseModel.status) { - FinishFixedSubmitPage().to(); - } else - BotToast.showText(text: baseModel.message); - }, + onPressed: _canSubmit(_selectType, _textEditingController.text) + ? () async { + List urls = await NetUtil() + .uploadFiles(_files, API.upload.uploadRepair); + BaseModel baseModel = await ManagerFunc.reportRepairInsert( + _selectType + 1, _textEditingController.text, urls); + if (baseModel.status) { + FinishFixedSubmitPage().to(); + } else + BotToast.showText(text: baseModel.message); + } + : () { + BotToast.showText(text: '请填写完整报修信息!'); + }, child: '确认提交'.text.black.bold.size(32.sp).make(), color: kPrimaryColor, elevation: 0, diff --git a/lib/utils/headers.dart b/lib/utils/headers.dart index 5a9390fb..df1f61bd 100644 --- a/lib/utils/headers.dart +++ b/lib/utils/headers.dart @@ -2,6 +2,7 @@ export 'package:flutter_screenutil/flutter_screenutil.dart'; export 'package:akuCommunity/extensions/page_router.dart'; export 'package:akuCommunity/extensions/num_ext.dart'; export 'package:akuCommunity/extensions/widget_list_ext.dart'; +export 'package:velocity_x/velocity_x.dart'; // class Screenutil { // static double length(double lengthNum) => ScreenUtil().setWidth(lengthNum);