diff --git a/lib/constants/api.dart b/lib/constants/api.dart index 5e545454..10fcbc7e 100644 --- a/lib/constants/api.dart +++ b/lib/constants/api.dart @@ -228,5 +228,6 @@ class _Upload { } class _Message { + ///消息中心:消息中心 获取系统通知未读数量和标题 String get center => '/user/message/messageCenter'; } diff --git a/lib/pages/home/home_page.dart b/lib/pages/home/home_page.dart index e6def9e9..829caccf 100644 --- a/lib/pages/home/home_page.dart +++ b/lib/pages/home/home_page.dart @@ -1,14 +1,14 @@ // Dart imports: -import 'dart:async'; -import 'dart:convert'; // Flutter imports: +import 'package:akuCommunity/provider/app_provider.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; // Package imports: import 'package:flutter_easyrefresh/easy_refresh.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; +import 'package:provider/provider.dart'; import 'package:velocity_x/velocity_x.dart'; // Project imports: @@ -19,7 +19,6 @@ import 'package:akuCommunity/model/community/activity_item_model.dart'; import 'package:akuCommunity/model/community/board_model.dart'; import 'package:akuCommunity/pages/home/widget/animate_app_bar.dart'; import 'package:akuCommunity/pages/message_center_page/message_center_page.dart'; -import 'package:akuCommunity/service/base_model.dart'; import 'package:akuCommunity/ui/community/activity/activity_card.dart'; import 'package:akuCommunity/ui/community/activity/activity_list_page.dart'; import 'package:akuCommunity/ui/community/community_func.dart'; @@ -30,7 +29,6 @@ import 'package:akuCommunity/widget/buttons/column_action_button.dart'; import 'package:akuCommunity/widget/views/application_box.dart'; import 'package:akuCommunity/widget/views/application_view.dart'; import 'widget/home_search.dart'; -import 'widget/home_swiper.dart'; class HomePage extends StatefulWidget { HomePage({Key key}) : super(key: key); @@ -67,16 +65,31 @@ class _HomePageState extends State super.build(context); ScreenUtil.init(context, designSize: Size(750, 1334), allowFontScaling: true); + AppProvider appProvider = Provider.of(context); return Scaffold( extendBodyBehindAppBar: true, appBar: AnimateAppBar( scrollController: _scrollController, actions: [ - ColumnActionButton( - onPressed: MessageCenterPage().to, - title: '消息', - path: R.ASSETS_ICONS_ALARM_PNG, - ), + Stack(children: [ + ColumnActionButton( + onPressed: MessageCenterPage().to, + title: '消息', + path: R.ASSETS_ICONS_ALARM_PNG, + ), + Positioned( + top: 0, + right: 0, + child: appProvider.messageCenterModel.sysCount == 0 + ? SizedBox() + : Container( + width: 2.w, + height: 2.w, + decoration: BoxDecoration( + color: Colors.red, + borderRadius: BorderRadius.circular(1.w)), + )) + ]), ], ), body: EasyRefresh( @@ -86,6 +99,7 @@ class _HomePageState extends State onRefresh: () async { _activityItemModel = await CommunityFunc.activity(); _boardItemModels = await CommunityFunc.board(); + appProvider.getMessageCenter(); setState(() {}); }, child: CustomScrollView( diff --git a/lib/pages/manager_func.dart b/lib/pages/manager_func.dart index f22bc690..979ba295 100644 --- a/lib/pages/manager_func.dart +++ b/lib/pages/manager_func.dart @@ -1,5 +1,4 @@ // Package imports: -import 'dart:convert'; import 'package:akuCommunity/model/manager/article_QR_code_model.dart'; import 'package:akuCommunity/model/manager/moving_company_model.dart'; diff --git a/lib/pages/message_center_page/message_func.dart b/lib/pages/message_center_page/message_func.dart new file mode 100644 index 00000000..3c2f3805 --- /dev/null +++ b/lib/pages/message_center_page/message_func.dart @@ -0,0 +1,11 @@ +import 'package:akuCommunity/constants/api.dart'; +import 'package:akuCommunity/model/message/message_center_model.dart'; +import 'package:akuCommunity/service/net.dart'; +import 'package:dio/dio.dart'; + +class MessageFunc { + // static Future messageCenter() async { + // Response response = await Net().dio.get(API.message.center); + // return MessageCenterModel.fromJson(response.data); + // } +} diff --git a/lib/provider/app_provider.dart b/lib/provider/app_provider.dart index 99e86cb6..5da0e90c 100644 --- a/lib/provider/app_provider.dart +++ b/lib/provider/app_provider.dart @@ -1,5 +1,6 @@ // Flutter imports: import 'package:akuCommunity/model/common/real_time_weather_model.dart'; +import 'package:akuCommunity/model/message/message_center_model.dart'; import 'package:amap_location_fluttify/amap_location_fluttify.dart'; import 'package:dio/dio.dart'; import 'package:flutter/material.dart'; @@ -138,4 +139,13 @@ class AppProvider extends ChangeNotifier { _weatherModel = RealTimeWeatherModel.fromJson(response.data); notifyListeners(); } + + /// 消息中心 + MessageCenterModel _messageCenterModel; + MessageCenterModel get messageCenterModel => _messageCenterModel??MessageCenterModel.zero(); + getMessageCenter() async { + Response response = await NetUtil().dio.get(API.message.center); + _messageCenterModel=MessageCenterModel.fromJson(response.data); + notifyListeners(); + } }