From b077ef64495bdfd174a440507d9e14eb6aa39530 Mon Sep 17 00:00:00 2001 From: zhangmeng <494089941@qq.com> Date: Mon, 12 Apr 2021 14:16:05 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=A6=96=E9=A1=B5=E5=85=AC?= =?UTF-8?q?=E5=91=8A=E4=B8=BA=E8=BF=9B=E5=85=A5=E9=A6=96=E9=A1=B5=E5=88=B7?= =?UTF-8?q?=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/main.dart | 2 -- lib/provider/anouncement_provider.dart | 16 ---------------- lib/ui/home/home_page.dart | 25 +++++++++++++++++++------ 3 files changed, 19 insertions(+), 24 deletions(-) delete mode 100644 lib/provider/anouncement_provider.dart diff --git a/lib/main.dart b/lib/main.dart index 606e03c..cf40da1 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -14,7 +14,6 @@ import 'package:jpush_flutter/jpush_flutter.dart'; import 'package:provider/provider.dart'; // Project imports: -import 'package:aku_community_manager/provider/anouncement_provider.dart'; import 'package:aku_community_manager/provider/app_provider.dart'; import 'package:aku_community_manager/provider/fix_provider.dart'; import 'package:aku_community_manager/provider/manage_provider.dart'; @@ -65,7 +64,6 @@ class MyApp extends StatelessWidget { ChangeNotifierProvider(create: (context) => GreenManageProvider()), ChangeNotifierProvider( create: (context) => InspectionManageProvider()), - ChangeNotifierProvider(create: (context) => AnouncementProvider()), ], child: GestureDetector( onTap: () { diff --git a/lib/provider/anouncement_provider.dart b/lib/provider/anouncement_provider.dart deleted file mode 100644 index e416cab..0000000 --- a/lib/provider/anouncement_provider.dart +++ /dev/null @@ -1,16 +0,0 @@ -// Flutter imports: -import 'package:aku_community_manager/models/announce/announcement_detail_model.dart'; -import 'package:aku_community_manager/models/announce/announcement_list_model.dart'; -import 'package:flutter/material.dart'; - -// Project imports: - -class AnouncementProvider extends ChangeNotifier { - List _anouncementCardModel = []; - List get anouncementCardModels => - _anouncementCardModel; - addAnouncementCardModel(AnnouncementListModel model) { - _anouncementCardModel.insert(0, model); - notifyListeners(); - } -} diff --git a/lib/ui/home/home_page.dart b/lib/ui/home/home_page.dart index 99305f6..624b60e 100644 --- a/lib/ui/home/home_page.dart +++ b/lib/ui/home/home_page.dart @@ -1,5 +1,6 @@ // Flutter imports: import 'package:aku_community_manager/const/api.dart'; +import 'package:aku_community_manager/models/announce/announcement_list_model.dart'; import 'package:aku_community_manager/models/manager/bussiness_and_fix/bussiness_and_fix_model.dart'; import 'package:aku_community_manager/models/manager/decoration/decoration_list_model.dart'; import 'package:aku_community_manager/models/manager/item_num_model.dart'; @@ -8,6 +9,7 @@ import 'package:aku_community_manager/models/todo_bussiness/todo_outdoor_model.d import 'package:aku_community_manager/ui/home/business/business_view.dart'; import 'package:aku_community_manager/ui/home/business/bussiness_func.dart'; import 'package:aku_community_manager/ui/home/business/todo_outdoor_card.dart'; +import 'package:aku_community_manager/utils/network/base_list_model.dart'; import 'package:aku_community_manager/utils/network/net_util.dart'; import 'package:dio/dio.dart'; import 'package:flutter/material.dart'; @@ -27,7 +29,6 @@ import 'package:provider/provider.dart'; import 'package:aku_community_manager/const/resource.dart'; import 'package:aku_community_manager/mock_models/all_model.dart'; import 'package:aku_community_manager/mock_models/decoration/decoration_model.dart'; -import 'package:aku_community_manager/provider/anouncement_provider.dart'; import 'package:aku_community_manager/provider/app_provider.dart'; import 'package:aku_community_manager/provider/user_provider.dart'; import 'package:aku_community_manager/style/app_style.dart'; @@ -60,6 +61,7 @@ class HomePage extends StatefulWidget { class _HomePageState extends State { ItemNumModel _itemNumModel; List _todoModelList; + List _anounceMentList; bool _onload = true; ///自定义bar的菜单按钮 @@ -156,6 +158,7 @@ class _HomePageState extends State { _itemNumModel = await _getItemNum(); var dataList = await BussinessFunc.getBussinessModelList(1); _todoModelList = dataList.map((e) => ToDoModel.fromJson(e)).toList(); + _anounceMentList = await _getAnouncement(); _onload = false; setState(() {}); }); @@ -168,10 +171,21 @@ class _HomePageState extends State { return ItemNumModel.fromJson(response.data); } + Future _getAnouncement() async { + BaseListModel baseListModel = + (await NetUtil().getList(API.message.announcementList, params: { + "pageNum": 1, + "size": 3, + })); + List anounceModels = baseListModel.tableList + .map((e) => AnnouncementListModel.fromJson(e)) + .toList(); + return anounceModels; + } + @override Widget build(BuildContext context) { final userProvider = Provider.of(context); - final _anouncementProvider = Provider.of(context); return AnnotatedRegion( child: Scaffold( drawer: PersonalDraw(), @@ -439,7 +453,7 @@ class _HomePageState extends State { height: 172.w, child: Stack(children: [ CarouselSlider( - items: _anouncementProvider.anouncementCardModels + items: _anounceMentList .map((e) => AllAnouncementState.anounceCard(e)) .toList(), options: CarouselOptions( @@ -461,10 +475,9 @@ class _HomePageState extends State { child: Row( mainAxisSize: MainAxisSize.max, mainAxisAlignment: MainAxisAlignment.center, - children: _anouncementProvider.anouncementCardModels + children: _anounceMentList .map((e) { - int index = _anouncementProvider - .anouncementCardModels + int index = _anounceMentList .indexOf(e); return Container( width: 12.w,