diff --git a/lib/constants/application_objects.dart b/lib/constants/application_objects.dart index 23bab3ef..b091f17d 100644 --- a/lib/constants/application_objects.dart +++ b/lib/constants/application_objects.dart @@ -113,7 +113,7 @@ List appObjects = [ AO('住房说明', Assets.newIcon.icRwsm.path, () => Get.to(() => HouseIntroducePage())), AO('智慧养老', Assets.home.icZhyl.path, - () => Get.to(() => OldAgeSupportPageSimple())), + () => Get.to(() => OldAgeSupportListPage())), AO('周边服务', Assets.home.icZbfw.path, null), AO('任务发布', Assets.home.icRwfb.path, () => Get.to(() => TaskPage())), AO('自营商城', Assets.icons.shoppingMall.path, null), diff --git a/lib/pages/services/old_age/add_equipment_page.dart b/lib/pages/services/old_age/add_equipment_page.dart index 988917ed..c880bd6e 100644 --- a/lib/pages/services/old_age/add_equipment_page.dart +++ b/lib/pages/services/old_age/add_equipment_page.dart @@ -142,8 +142,8 @@ class _AddEquipmentPageState extends State { physics: NeverScrollableScrollPhysics(), children: [ GestureDetector( - onTap: () { - Get.to(() => SubmitEquipmentCodePage()); + onTap: () async{ + await Get.to(() => SubmitEquipmentCodePage()); }, child: Material( color: Colors.transparent, diff --git a/lib/pages/services/old_age/old_age_show_data_page.dart b/lib/pages/services/old_age/old_age_show_data_page.dart index 0b08715e..0e0d103c 100644 --- a/lib/pages/services/old_age/old_age_show_data_page.dart +++ b/lib/pages/services/old_age/old_age_show_data_page.dart @@ -8,15 +8,14 @@ import 'package:aku_new_community/utils/network/base_model.dart'; import 'package:aku_new_community/utils/network/net_util.dart'; import 'package:aku_new_community/widget/bee_divider.dart'; import 'package:aku_new_community/widget/bee_scaffold.dart'; +import 'package:aku_new_community/widget/others/user_tool.dart'; import 'package:bot_toast/bot_toast.dart'; import 'package:common_utils/common_utils.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; class OldAgeShowDataPage extends StatefulWidget { - final String imei; - - const OldAgeShowDataPage({Key? key, required this.imei}) : super(key: key); + const OldAgeShowDataPage({Key? key,}) : super(key: key); @override _OldAgeShowDataPageState createState() => _OldAgeShowDataPageState(); @@ -42,7 +41,7 @@ class _OldAgeShowDataPageState extends State { Future getData() async { BaseModel base = await NetUtil().get(SAASAPI.bracelet.data, params: { - 'imei': widget.imei, + 'imei': UserTool.oldAgeProvider.bracelet?.imei, }); if (base.data != null) { _model = BraceletModel.fromJson(base.data); diff --git a/lib/pages/services/old_age/old_age_support_list_page.dart b/lib/pages/services/old_age/old_age_support_list_page.dart index 5b7251b3..e5c7151a 100644 --- a/lib/pages/services/old_age/old_age_support_list_page.dart +++ b/lib/pages/services/old_age/old_age_support_list_page.dart @@ -18,17 +18,16 @@ import 'package:aku_new_community/utils/network/net_util.dart'; import 'package:aku_new_community/widget/bee_divider.dart'; import 'package:aku_new_community/widget/bee_scaffold.dart'; -class OldAgeSupportPageSimple extends StatefulWidget { - const OldAgeSupportPageSimple({Key? key}) : super(key: key); +class OldAgeSupportListPage extends StatefulWidget { + const OldAgeSupportListPage({Key? key}) : super(key: key); @override - _OldAgeSupportPageSimpleState createState() => - _OldAgeSupportPageSimpleState(); + _OldAgeSupportListPageState createState() => _OldAgeSupportListPageState(); } -class _OldAgeSupportPageSimpleState extends State { - BraceletListModel? _currentBracelet; +class _OldAgeSupportListPageState extends State { List _bracelets = []; + EasyRefreshController _refreshController = EasyRefreshController(); @override void initState() { @@ -37,6 +36,7 @@ class _OldAgeSupportPageSimpleState extends State { @override void dispose() { + _refreshController.dispose(); super.dispose(); } @@ -74,10 +74,13 @@ class _OldAgeSupportPageSimpleState extends State { .bold .make(), 24.w.heightBox, - if (_currentBracelet != null) - _braceletWidget(e: _currentBracelet!, bgColor: Color(0xFF6395D7),onTap: ()async{ - Get.to(OldAgeShowDataPage(imei: _currentBracelet!.imei,)); - }) + if (UserTool.oldAgeProvider.bracelet != null) + _braceletWidget( + e: UserTool.oldAgeProvider.bracelet!, + select: true, + onTap: () async { + Get.to(OldAgeShowDataPage()); + }), ], ), ); @@ -96,8 +99,9 @@ class _OldAgeSupportPageSimpleState extends State { ..._bracelets .map((e) => _braceletWidget( e: e, + select: false, onTap: () { - _currentBracelet = e; + UserTool.oldAgeProvider.changeImei(e); setState(() {}); })) .toList() @@ -108,24 +112,25 @@ class _OldAgeSupportPageSimpleState extends State { ), ); return BeeScaffold( - title: '设备列表', - bodyColor: Colors.white, - body: SafeArea( - child: EasyRefresh( - firstRefresh: true, - header: MaterialHeader(), - onRefresh: () async { - var base = await NetUtil().get(SAASAPI.bracelet.list); - if (base.success) { - _bracelets = (base.data as List) - .map((e) => BraceletListModel.fromJson(e)) - .toList(); - setState(() {}); - } - }, - child: _bracelets.isEmpty - ? _emptyWidgt() - : ListView( + title: '设备列表', + bodyColor: Colors.white, + body: SafeArea( + child: EasyRefresh( + controller: _refreshController, + firstRefresh: true, + header: MaterialHeader(), + onRefresh: () async { + var base = await NetUtil().get(SAASAPI.bracelet.list); + if (base.success) { + _bracelets = (base.data as List) + .map((e) => BraceletListModel.fromJson(e)) + .toList(); + setState(() {}); + } + }, + child: _bracelets.isEmpty + ? _emptyWidgt() + : ListView( padding: EdgeInsets.all(24.w), children: [ // user, @@ -137,35 +142,38 @@ class _OldAgeSupportPageSimpleState extends State { // 24.w.heightBox, ], ), - ), - ), - bottomNavi: Padding( - padding: EdgeInsets.symmetric(horizontal: 32.w, vertical: 24.w), - child: MaterialButton( - onPressed: () { - Get.to(() => AddEquipmentPage()); - }, - color: Color(0xFF5096F1), - padding: EdgeInsets.symmetric(vertical: 24.w), - minWidth: 686.w, - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.circular(8.w), - ), - child: '添加设备'.text.size(28.sp).white.make(), - ), - ), - ); + ), + ), + bottomNavi: Padding( + padding: EdgeInsets.symmetric(horizontal: 32.w, vertical: 24.w), + child: MaterialButton( + onPressed: () async { + await Get.to(() => AddEquipmentPage()); + _refreshController.callRefresh(); + }, + color: Color(0xFF5096F1), + padding: EdgeInsets.symmetric(vertical: 24.w), + minWidth: 686.w, + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(8.w), + ), + child: '添加设备'.text.size(28.sp).white.make(), + ), + ), + ); } Widget _braceletWidget( - {required BraceletListModel e, VoidCallback? onTap, Color? bgColor}) { + {required BraceletListModel e, + VoidCallback? onTap, + required bool select}) { return GestureDetector( onTap: onTap, child: Container( width: double.infinity, padding: EdgeInsets.all(24.w), decoration: BoxDecoration( - color: bgColor ?? Colors.black.withOpacity(0.06), + color: select ? Color(0xFF6395D7) : Colors.black.withOpacity(0.06), borderRadius: BorderRadius.circular(16.w)), child: Row( children: [ @@ -182,30 +190,32 @@ class _OldAgeSupportPageSimpleState extends State { '${e.deviceType} ${e.braceletBrand.name}' .text .size(24.sp) - .color(Colors.black.withOpacity(0.65)) + .color( + select ? Colors.white : Colors.black.withOpacity(0.65)) .make(), 16.w.heightBox, '设备码:${e.imei}' .text .size(24.sp) - .color(Colors.black.withOpacity(0.65)) + .color( + select ? Colors.white : Colors.black.withOpacity(0.65)) .make(), - ], + ], ), Spacer(), Container( width: 15.w, height: 16.w, decoration: BoxDecoration( - color: Colors.black.withOpacity(0.25), + color:select ? Colors.white : Colors.black.withOpacity(0.25), borderRadius: BorderRadius.circular(16.w), ), ), 24.w.widthBox, - '${UserTool.oldAgeProvider.imei == e.imei ? '已连接' : '未开启'}' + '${select ? '已连接' : '未开启'}' .text .size(24.sp) - .color(Colors.black.withOpacity(0.65)) + .color(select ? Colors.white : Colors.black.withOpacity(0.65)) .make(), ], ), diff --git a/lib/pages/services/old_age/submit_equipment_code_page.dart b/lib/pages/services/old_age/submit_equipment_code_page.dart index 7347b7ce..3f453e15 100644 --- a/lib/pages/services/old_age/submit_equipment_code_page.dart +++ b/lib/pages/services/old_age/submit_equipment_code_page.dart @@ -84,9 +84,6 @@ class _SubmitEquipmentCodePageState extends State { if (base.success) { Get.back(); Get.back(); - if (UserTool.oldAgeProvider.imei.isEmpty) { - UserTool.oldAgeProvider.changeImei(_editingController.text); - } } else { BotToast.showText(text: base.msg); } diff --git a/lib/provider/old_age_provider.dart b/lib/provider/old_age_provider.dart index dc7a9213..ab374ff8 100644 --- a/lib/provider/old_age_provider.dart +++ b/lib/provider/old_age_provider.dart @@ -1,12 +1,13 @@ +import 'package:aku_new_community/models/bracelet/bracelet_list_model.dart'; import 'package:flutter/material.dart'; class OldAgeProvider extends ChangeNotifier { - String _imei=''; + BraceletListModel? _bracelet; - String get imei => _imei; + BraceletListModel? get bracelet => _bracelet ; - void changeImei(String value) { - _imei = value; + void changeImei(BraceletListModel value) { + _bracelet = value; notifyListeners(); } } diff --git a/lib/utils/application_utils.dart b/lib/utils/application_utils.dart index 34e90665..0d24e9a5 100644 --- a/lib/utils/application_utils.dart +++ b/lib/utils/application_utils.dart @@ -190,7 +190,7 @@ class ApplicationUtil { title: '智慧养老', imgPath: Assets.home.icZhyl.path, onTap: () { - Get.to(() => OldAgeSupportPageSimple()); + Get.to(() => OldAgeSupportListPage()); }), AppElement( title: '周边服务',