From dd1b166dc56d5bdadcb1f5445dc7e378aaf9d7fc Mon Sep 17 00:00:00 2001 From: zhang <494089941@qq.com> Date: Fri, 5 Feb 2021 11:31:21 +0800 Subject: [PATCH] add single check widget dock interface:voteDetail --- .../event_activity/voting_detail_page.dart | 151 ++++++++++++------ lib/pages/manager_func.dart | 5 +- lib/widget/buttons/bee_single_check.dart | 44 +++++ 3 files changed, 147 insertions(+), 53 deletions(-) create mode 100644 lib/widget/buttons/bee_single_check.dart diff --git a/lib/pages/event_activity/voting_detail_page.dart b/lib/pages/event_activity/voting_detail_page.dart index ff950e30..2fd7da2f 100644 --- a/lib/pages/event_activity/voting_detail_page.dart +++ b/lib/pages/event_activity/voting_detail_page.dart @@ -1,8 +1,10 @@ import 'package:akuCommunity/constants/api.dart'; import 'package:akuCommunity/model/manager/voting_detail_model.dart'; import 'package:akuCommunity/pages/manager_func.dart'; +import 'package:akuCommunity/widget/bee_divider.dart'; import 'package:akuCommunity/widget/bee_scaffold.dart'; import 'package:akuCommunity/widget/buttons/bee_check_box.dart'; +import 'package:akuCommunity/widget/buttons/bee_single_check.dart'; import 'package:flutter/material.dart'; import 'package:akuCommunity/utils/headers.dart'; import 'package:flutter_easyrefresh/easy_refresh.dart'; @@ -18,6 +20,9 @@ class VotingDetailPage extends StatefulWidget { class _VotingDetailPageState extends State { VotingDetailModel _model; EasyRefreshController _refreshController; + bool _isOnload = true; + // List _select = []; + int _selectId; @override void initState() { super.initState(); @@ -33,17 +38,40 @@ class _VotingDetailPageState extends State { Widget _buildVoteCard(AppVoteCandidateVos model) { return Container( padding: EdgeInsets.symmetric(vertical: 40.w), + constraints: BoxConstraints(maxHeight: 230.w), child: Row( children: [ - GestureDetector( - onTap: () {}, - child: Material( - color: Colors.transparent, - child: SizedBox( - width: 88.w, - height: 150.w, - child: BeeCheckBox(isRound: true)), - ), + Container( + alignment: Alignment.center, + width: 88.w, + height: 150.w, + //多选 + // child: BeeCheckBox( + // isRound: true, + // size: 30.w, + // onChange: (value) { + // if (value) { + // if (!_select.contains(model.id)) { + // _select.add(model.id); + // } + // } else { + // _select.remove(model.id); + // } + // }, + // ), +// + // + //暂时用单选 + child: GestureDetector( + onTap: () { + _selectId = model.id; + setState(() {}); + }, + child: BeeSingleCheck( + value: model.id, + groupValue: _selectId, + ), + ).material(color: Colors.transparent), ), ClipRRect( borderRadius: BorderRadius.circular(4.w), @@ -55,60 +83,81 @@ class _VotingDetailPageState extends State { Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ - '测试'.text.black.size(32.sp).make(), - 10.w.heightBox, + // '测试'.text.black.size(32.sp).make(), + // 10.w.heightBox, model.name.text.black.size(32.sp).make() ], ), - Spacer() + Spacer(), ], ), ); } + Widget _emptyWidget() { + return Container(); + } + @override Widget build(BuildContext context) { return BeeScaffold( title: '活动详情', - body: ListView( - padding: EdgeInsets.symmetric( - horizontal: 32.w, - vertical: 26.w, - ), - children: [ - _model.title.text.black.size(32.sp).bold.maxLines(2).make(), - 44.w.heightBox, - SizedBox( - width: double.infinity, - height: 228.w, - child: ClipRRect( - borderRadius: BorderRadius.circular(8.w), - child: FadeInImage.assetNetwork( - placeholder: R.ASSETS_IMAGES_LOGO_PNG, - image: API.image(_model.imgUrls.first.url)), - ), - ), - 44.w.heightBox, - _model.content.text.black.size(28.sp).make(), - 44.w.heightBox, - Container( - padding: EdgeInsets.fromLTRB(32.w, 50.w, 32.w, 0), - decoration: BoxDecoration( - color: Color(0xFFD9D9D9), - borderRadius: BorderRadius.circular(8.w), - ), - child: Column( - children: [ - '测试标题' - .text - .color(Color(0xFF999999)) - .size(32.sp) - .make(), //TODO:缺少字段; - 26.w.heightBox, - ], - ), - ) - ], + body: EasyRefresh( + firstRefresh: true, + controller: _refreshController, + onRefresh: () async { + await ManagerFunc.voteDetail(widget.id) + .then((value) => _model = value); + _isOnload = false; + }, + header: MaterialHeader(), + child: _isOnload + ? _emptyWidget() + : ListView( + padding: EdgeInsets.symmetric( + horizontal: 32.w, + vertical: 26.w, + ), + children: [ + _model.title.text.black.size(32.sp).bold.maxLines(2).make(), + 44.w.heightBox, + SizedBox( + width: double.infinity, + height: 228.w, + child: ClipRRect( + borderRadius: BorderRadius.circular(8.w), + child: FadeInImage.assetNetwork( + placeholder: R.ASSETS_IMAGES_LOGO_PNG, + image: API.image(_model.imgUrls.first.url)), + ), + ), + 44.w.heightBox, + _model.content.text.black.size(28.sp).make(), + 44.w.heightBox, + Container( + padding: EdgeInsets.fromLTRB(32.w, 50.w, 32.w, 0), + decoration: BoxDecoration( + color: Color(0xFFD9D9D9), + borderRadius: BorderRadius.circular(8.w), + ), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + // '测试标题' + // .text + // .color(Color(0xFF999999)) + // .size(32.sp) + // .make(), //TODO:缺少字段; + // 26.w.heightBox, + ..._model.appVoteCandidateVos + .map((e) => _buildVoteCard(e)) + .toList() + .sepWidget(separate: BeeDivider.horizontal()), + ], + ), + ) + ], + ), ), ); } diff --git a/lib/pages/manager_func.dart b/lib/pages/manager_func.dart index a81fc613..78011ce3 100644 --- a/lib/pages/manager_func.dart +++ b/lib/pages/manager_func.dart @@ -1,6 +1,7 @@ // Package imports: import 'package:akuCommunity/model/manager/article_QR_code_model.dart'; import 'package:akuCommunity/model/manager/moving_company_model.dart'; +import 'package:akuCommunity/model/manager/voting_detail_model.dart'; import 'package:dio/dio.dart'; import 'package:flustars/flustars.dart'; @@ -165,12 +166,12 @@ class ManagerFunc { return baseModel.data; } - static Future voteDetail(int id) async { + static Future voteDetail(int id) async { BaseModel baseModel = await NetUtil().get(API.manager.voteDetail, params: { 'voteId': 1, }, showMessage: false); - return baseModel.data; + return VotingDetailModel.fromJson(baseModel.data); } } diff --git a/lib/widget/buttons/bee_single_check.dart b/lib/widget/buttons/bee_single_check.dart new file mode 100644 index 00000000..ba99ba9e --- /dev/null +++ b/lib/widget/buttons/bee_single_check.dart @@ -0,0 +1,44 @@ +import 'package:akuCommunity/base/base_style.dart'; +import 'package:flutter/cupertino.dart'; +import 'package:flutter/material.dart'; +import 'package:akuCommunity/utils/headers.dart'; + +class BeeSingleCheck extends StatefulWidget { + final T value; + final T groupValue; + BeeSingleCheck({Key key, this.value, this.groupValue}) : super(key: key); + + @override + _BeeSingleCheckState createState() => _BeeSingleCheckState(); +} + +class _BeeSingleCheckState extends State { + bool get _selected => widget.value == widget.groupValue; + @override + Widget build(BuildContext context) { + return AnimatedContainer( + height: 40.w, + width: 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: Icon( + CupertinoIcons.chevron_up, + color: Colors.white, + size: 24.w, + ), + ), + ); + } +}