diff --git a/lib/constants/api.dart b/lib/constants/api.dart index f6d25e02..9b66826e 100644 --- a/lib/constants/api.dart +++ b/lib/constants/api.dart @@ -308,4 +308,8 @@ class _Facility { ///设施预约:结束使用 String get stop => '/user/facilitiesAppointment/useStop'; + + ///设施预约:根据设施分类主键id查询设施信息 + String get detailType => + '/user/facilitiesAppointment/findFacilitiesByCategoryId'; } diff --git a/lib/generated_plugin_registrant.dart b/lib/generated_plugin_registrant.dart index 8e0b1cb0..222a4e7a 100644 --- a/lib/generated_plugin_registrant.dart +++ b/lib/generated_plugin_registrant.dart @@ -6,12 +6,13 @@ import 'package:device_info_plus_web/device_info_plus_web.dart'; import 'package:firebase_core_web/firebase_core_web.dart'; -import 'package:flutter_web_plugins/flutter_web_plugins.dart'; import 'package:image_picker_for_web/image_picker_for_web.dart'; import 'package:package_info_plus_web/package_info_plus_web.dart'; import 'package:shared_preferences_web/shared_preferences_web.dart'; import 'package:url_launcher_web/url_launcher_web.dart'; +import 'package:flutter_web_plugins/flutter_web_plugins.dart'; + // ignore: public_member_api_docs void registerPlugins(Registrar registrar) { DeviceInfoPlusPlugin.registerWith(registrar); diff --git a/lib/models/facility/facility_type_detail_model.dart b/lib/models/facility/facility_type_detail_model.dart new file mode 100644 index 00000000..fd246302 --- /dev/null +++ b/lib/models/facility/facility_type_detail_model.dart @@ -0,0 +1,19 @@ +import 'package:equatable/equatable.dart'; +import 'package:json_annotation/json_annotation.dart'; +part 'facility_type_detail_model.g.dart'; + +@JsonSerializable() +class FacilityTypeDetailModel extends Equatable { + final int id; + final String name; + FacilityTypeDetailModel({ + required this.id, + required this.name, + }); + + factory FacilityTypeDetailModel.fromJson(Map json) => + _$FacilityTypeDetailModelFromJson(json); + + @override + List get props => [id]; +} diff --git a/lib/models/facility/facility_type_detail_model.g.dart b/lib/models/facility/facility_type_detail_model.g.dart new file mode 100644 index 00000000..0b36cc15 --- /dev/null +++ b/lib/models/facility/facility_type_detail_model.g.dart @@ -0,0 +1,15 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'facility_type_detail_model.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +FacilityTypeDetailModel _$FacilityTypeDetailModelFromJson( + Map json) { + return FacilityTypeDetailModel( + id: json['id'] as int, + name: json['name'] as String, + ); +} diff --git a/lib/ui/community/facility/facility_appointment_page.dart b/lib/ui/community/facility/facility_appointment_page.dart index bd39a379..df4f79e0 100644 --- a/lib/ui/community/facility/facility_appointment_page.dart +++ b/lib/ui/community/facility/facility_appointment_page.dart @@ -1,10 +1,10 @@ +import 'package:aku_community/ui/community/facility/pick_facility_page.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:get/get.dart'; import 'package:aku_community/ui/community/facility/facility_appointment_view.dart'; -import 'package:aku_community/ui/community/facility/facility_preview_page.dart'; import 'package:aku_community/widget/bee_scaffold.dart'; import 'package:aku_community/widget/tab_bar/bee_tab_bar.dart'; @@ -38,7 +38,7 @@ class _FacilityAppointmentPageState extends State actions: [ IconButton( icon: Icon(CupertinoIcons.add_circled), - onPressed: () => Get.to(() => FacilityPreorderPage()), + onPressed: () => Get.to(() => PickFacilityPage()), ), ], appBarBottom: BeeTabBar( diff --git a/lib/ui/community/facility/facility_preview_page.dart b/lib/ui/community/facility/facility_preorder_page.dart similarity index 93% rename from lib/ui/community/facility/facility_preview_page.dart rename to lib/ui/community/facility/facility_preorder_page.dart index 04dd1056..ee977764 100644 --- a/lib/ui/community/facility/facility_preview_page.dart +++ b/lib/ui/community/facility/facility_preorder_page.dart @@ -1,3 +1,5 @@ +import 'package:aku_community/models/facility/facility_type_detail_model.dart'; +import 'package:aku_community/ui/community/facility/facility_type_detail_page.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; @@ -9,9 +11,7 @@ import 'package:provider/provider.dart'; import 'package:aku_community/base/base_style.dart'; import 'package:aku_community/constants/api.dart'; import 'package:aku_community/constants/app_theme.dart'; -import 'package:aku_community/models/facility/facility_type_model.dart'; import 'package:aku_community/provider/app_provider.dart'; -import 'package:aku_community/ui/community/facility/pick_facility_page.dart'; import 'package:aku_community/ui/profile/house/pick_my_house_page.dart'; import 'package:aku_community/utils/headers.dart'; import 'package:aku_community/utils/network/net_util.dart'; @@ -21,14 +21,15 @@ import 'package:aku_community/widget/buttons/bottom_button.dart'; import 'package:aku_community/widget/picker/bee_date_picker.dart'; class FacilityPreorderPage extends StatefulWidget { - FacilityPreorderPage({Key? key}) : super(key: key); + final int id; + FacilityPreorderPage({Key? key, required this.id}) : super(key: key); @override _FacilityPreorderPageState createState() => _FacilityPreorderPageState(); } class _FacilityPreorderPageState extends State { - FacilityTypeModel? typeModel; + FacilityTypeDetailModel? typeModel; DateTime? startDate; DateTime? endDate; @@ -68,7 +69,8 @@ class _FacilityPreorderPageState extends State { width: 60.w, ), onTap: () async { - FacilityTypeModel? model = await Get.to(() => PickFacilityPage()); + FacilityTypeDetailModel? model = + await Get.to(() => FacilityTypeDetailPage(model: typeModel, id: widget.id)); if (model != null) typeModel = model; setState(() {}); }, diff --git a/lib/ui/community/facility/facility_type_card.dart b/lib/ui/community/facility/facility_type_card.dart index e95f5476..99f3c309 100644 --- a/lib/ui/community/facility/facility_type_card.dart +++ b/lib/ui/community/facility/facility_type_card.dart @@ -1,3 +1,4 @@ +import 'package:aku_community/ui/community/facility/facility_preorder_page.dart'; import 'package:flutter/material.dart'; import 'package:get/get.dart'; @@ -74,7 +75,9 @@ class FacilityTypeCard extends StatelessWidget { 24.hb, ], ), - onPressed: () => Get.back(result: model), + onPressed: () { + Get.off(() => FacilityPreorderPage(id: model.id)); + }, ); } } diff --git a/lib/ui/community/facility/facility_type_detail_page.dart b/lib/ui/community/facility/facility_type_detail_page.dart new file mode 100644 index 00000000..f6f0a463 --- /dev/null +++ b/lib/ui/community/facility/facility_type_detail_page.dart @@ -0,0 +1,68 @@ +import 'package:aku_community/constants/api.dart'; +import 'package:aku_community/models/facility/facility_type_detail_model.dart'; +import 'package:aku_community/utils/network/base_model.dart'; +import 'package:aku_community/utils/network/net_util.dart'; +import 'package:aku_community/widget/bee_divider.dart'; +import 'package:aku_community/widget/bee_scaffold.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_easyrefresh/easy_refresh.dart'; +import 'package:get/get.dart'; + +class FacilityTypeDetailPage extends StatefulWidget { + final int id; + final FacilityTypeDetailModel? model; + FacilityTypeDetailPage({ + Key? key, + required this.model, + required this.id, + }) : super(key: key); + + @override + _FacilityTypeDetailPageState createState() => _FacilityTypeDetailPageState(); +} + +class _FacilityTypeDetailPageState extends State { + List _models = []; + @override + Widget build(BuildContext context) { + return BeeScaffold( + title: '选择设施', + body: EasyRefresh( + firstRefresh: true, + header: MaterialHeader(), + onRefresh: () async { + BaseModel model = await NetUtil().get( + API.manager.facility.detailType, + params: {'categoryId': widget.id}, + ); + _models = (model.data as List) + .map((e) => FacilityTypeDetailModel.fromJson(e)) + .toList(); + setState(() {}); + }, + child: ListView.separated( + itemBuilder: (context, index) { + final item = _models[index]; + return ListTile( + onTap: () => selectModel(item), + leading: Radio( + value: item, + groupValue: widget.model, + onChanged: (_) { + selectModel(item); + }, + ), + title: Text(item.name), + ); + }, + separatorBuilder: (_, __) => BeeDivider.horizontal(), + itemCount: _models.length, + ), + ), + ); + } + + void selectModel(FacilityTypeDetailModel model) { + Get.back(result: model); + } +} diff --git a/pubspec.lock b/pubspec.lock index 006f4b97..1b02dbad 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -302,6 +302,13 @@ packages: url: "https://pub.flutter-io.cn" source: hosted version: "4.0.0" + equatable: + dependency: "direct main" + description: + name: equatable + url: "https://pub.flutter-io.cn" + source: hosted + version: "2.0.0" extended_list_library: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 1b1742fd..c3fcdbc7 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -68,6 +68,7 @@ dependencies: json_annotation: ^4.0.1 waterfall_flow: ^3.0.1 qr_code_scanner: ^0.4.0 + equatable: ^2.0.0 dev_dependencies: flutter_test: diff --git a/tool/_project_manage.dart b/tool/_project_manage.dart index bc04b0ed..19bf399d 100644 --- a/tool/_project_manage.dart +++ b/tool/_project_manage.dart @@ -33,3 +33,11 @@ void gitPush() { arguments: ['push'], ); } + +@Task('build runner') +void gen() async { + await Pub.runAsync( + 'build_runner', + arguments: ['build'], + ); +}