diff --git a/lib/constants/api.dart b/lib/constants/api.dart index bc1d88a1..dfc7e902 100644 --- a/lib/constants/api.dart +++ b/lib/constants/api.dart @@ -19,6 +19,7 @@ class API { static _Community community = _Community(); static _Message message = _Message(); static _Market market = _Market(); + static _News news = _News(); } class _Login { @@ -88,6 +89,14 @@ class _User { String get carList => '/user/myCar/list'; } +class _News { + ///app公共资讯:查询所有的资讯分类(【全部】是默认显示的值) + String get category => '/user/news/categoryList'; + + ///app公共资讯:根据资讯分类主键id查询资讯信息 + String get list => '/user/news/newsList'; +} + class _Manager { _Facility facility = _Facility(); diff --git a/lib/main_initialize.dart b/lib/main_initialize.dart index 6f3144ed..f7fc57bf 100644 --- a/lib/main_initialize.dart +++ b/lib/main_initialize.dart @@ -1,6 +1,5 @@ import 'dart:io'; -import 'package:aku_community/provider/app_provider.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; @@ -12,11 +11,12 @@ import 'package:fluwx/fluwx.dart'; import 'package:get/get.dart'; import 'package:jpush_flutter/jpush_flutter.dart'; import 'package:power_logger/power_logger.dart'; +import 'package:provider/provider.dart'; import 'package:aku_community/constants/app_theme.dart'; import 'package:aku_community/constants/config.dart'; +import 'package:aku_community/provider/app_provider.dart'; import 'package:aku_community/utils/message_parser.dart'; -import 'package:provider/provider.dart'; class MainInitialize { ///初始化firebase diff --git a/lib/models/market/goods_detail_model.dart b/lib/models/market/goods_detail_model.dart index 7c24a3b9..0f41e71c 100644 --- a/lib/models/market/goods_detail_model.dart +++ b/lib/models/market/goods_detail_model.dart @@ -1,6 +1,8 @@ -import 'package:aku_community/model/common/img_model.dart'; import 'package:equatable/equatable.dart'; import 'package:json_annotation/json_annotation.dart'; + +import 'package:aku_community/model/common/img_model.dart'; + part 'goods_detail_model.g.dart'; @JsonSerializable() diff --git a/lib/models/news/news_category_model.dart b/lib/models/news/news_category_model.dart new file mode 100644 index 00000000..5ece2221 --- /dev/null +++ b/lib/models/news/news_category_model.dart @@ -0,0 +1,16 @@ +import 'package:json_annotation/json_annotation.dart'; + +part 'news_category_model.g.dart'; + +@JsonSerializable() +class NewsCategoryModel { + final int id; + final String name; + NewsCategoryModel({ + required this.id, + required this.name, + }); + + factory NewsCategoryModel.fromJson(Map json) => + _$NewsCategoryModelFromJson(json); +} diff --git a/lib/models/news/news_category_model.g.dart b/lib/models/news/news_category_model.g.dart new file mode 100644 index 00000000..5b68fb75 --- /dev/null +++ b/lib/models/news/news_category_model.g.dart @@ -0,0 +1,14 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'news_category_model.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +NewsCategoryModel _$NewsCategoryModelFromJson(Map json) { + return NewsCategoryModel( + id: json['id'] as int, + name: json['name'] as String, + ); +} diff --git a/lib/models/news/news_item_model.dart b/lib/models/news/news_item_model.dart new file mode 100644 index 00000000..51b95099 --- /dev/null +++ b/lib/models/news/news_item_model.dart @@ -0,0 +1,24 @@ +import 'package:flustars/flustars.dart'; +import 'package:json_annotation/json_annotation.dart'; + +import 'package:aku_community/model/common/img_model.dart'; + +part 'news_item_model.g.dart'; + +@JsonSerializable() +class NewsItemModel { + final int id; + final String title; + final String createDate; + final List imgList; + DateTime? get create => DateUtil.getDateTime(createDate); + NewsItemModel({ + required this.id, + required this.title, + required this.createDate, + required this.imgList, + }); + + factory NewsItemModel.fromJson(Map json) => + _$NewsItemModelFromJson(json); +} diff --git a/lib/models/news/news_item_model.g.dart b/lib/models/news/news_item_model.g.dart new file mode 100644 index 00000000..a5c0fa91 --- /dev/null +++ b/lib/models/news/news_item_model.g.dart @@ -0,0 +1,18 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'news_item_model.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +NewsItemModel _$NewsItemModelFromJson(Map json) { + return NewsItemModel( + id: json['id'] as int, + title: json['title'] as String, + createDate: json['createDate'] as String, + imgList: (json['imgList'] as List) + .map((e) => ImgModel.fromJson(e as Map)) + .toList(), + ); +} diff --git a/lib/pages/home/home_page.dart b/lib/pages/home/home_page.dart index 3a8196de..13d1839c 100644 --- a/lib/pages/home/home_page.dart +++ b/lib/pages/home/home_page.dart @@ -1,5 +1,10 @@ // Dart imports: +import 'package:aku_community/constants/api.dart'; +import 'package:aku_community/models/news/news_category_model.dart'; +import 'package:aku_community/utils/network/base_model.dart'; +import 'package:aku_community/utils/network/net_util.dart'; +import 'package:bot_toast/bot_toast.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; @@ -117,7 +122,19 @@ class _HomePageState extends State HomeTitle( title: '公共资讯', suffixTitle: '更多资讯', - onTap: () => Get.to(() => PublicInfomationPage()), + onTap: () async { + final cancel = BotToast.showLoading(); + BaseModel model = await NetUtil().get(API.news.category); + List? category; + if (model.status == true && model.data != null) { + category = (model.data as List) + .map((e) => NewsCategoryModel.fromJson(e)) + .toList(); + } + cancel(); + Get.to( + () => PublicInfomationPage(models: category ?? [])); + }, ), HomeTitle( title: '社区活动', diff --git a/lib/pages/things_page/widget/fixed_detail_page.dart b/lib/pages/things_page/widget/fixed_detail_page.dart index 24acc014..78e4a9ac 100644 --- a/lib/pages/things_page/widget/fixed_detail_page.dart +++ b/lib/pages/things_page/widget/fixed_detail_page.dart @@ -306,9 +306,11 @@ class _FixedDetailPageState extends State { height: double.infinity, padding: EdgeInsets.zero, materialTapTargetSize: MaterialTapTargetSize.shrinkWrap, - onPressed: showProcessCard ? () async{ - await launch('tel:0574-87760023'); - } : null, + onPressed: showProcessCard + ? () async { + await launch('tel:0574-87760023'); + } + : null, disabledColor: kDarkSubColor.withOpacity(0.1), disabledTextColor: ktextSubColor.withOpacity(0.3), textColor: ktextPrimary, diff --git a/lib/pages/visitor_access_page/visitor_access_page.dart b/lib/pages/visitor_access_page/visitor_access_page.dart index 3e3ee0cd..42f286bc 100644 --- a/lib/pages/visitor_access_page/visitor_access_page.dart +++ b/lib/pages/visitor_access_page/visitor_access_page.dart @@ -1,4 +1,3 @@ -import 'package:aku_community/constants/api.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; @@ -9,6 +8,7 @@ import 'package:provider/provider.dart'; import 'package:share/share.dart'; import 'package:velocity_x/velocity_x.dart'; +import 'package:aku_community/constants/api.dart'; import 'package:aku_community/pages/manager_func.dart'; import 'package:aku_community/provider/app_provider.dart'; import 'package:aku_community/provider/user_provider.dart'; diff --git a/lib/ui/community/community_views/community_page.dart b/lib/ui/community/community_views/community_page.dart index ef1dcb63..83b0ca73 100644 --- a/lib/ui/community/community_views/community_page.dart +++ b/lib/ui/community/community_views/community_page.dart @@ -1,11 +1,11 @@ -import 'package:aku_community/provider/app_provider.dart'; -import 'package:badges/badges.dart'; import 'package:flutter/material.dart'; +import 'package:badges/badges.dart'; import 'package:get/get.dart'; import 'package:provider/provider.dart'; import 'package:aku_community/pages/message_center_page/message_center_page.dart'; +import 'package:aku_community/provider/app_provider.dart'; import 'package:aku_community/provider/user_provider.dart'; import 'package:aku_community/ui/community/community_views/add_new_event_page.dart'; import 'package:aku_community/ui/community/community_views/my_community_view.dart'; diff --git a/lib/ui/home/public_infomation/public_infomation_card.dart b/lib/ui/home/public_infomation/public_infomation_card.dart index 1e469e79..d6b415c4 100644 --- a/lib/ui/home/public_infomation/public_infomation_card.dart +++ b/lib/ui/home/public_infomation/public_infomation_card.dart @@ -1,10 +1,15 @@ +import 'package:aku_community/constants/api.dart'; +import 'package:aku_community/model/common/img_model.dart'; +import 'package:aku_community/models/news/news_item_model.dart'; +import 'package:flustars/flustars.dart'; import 'package:flutter/material.dart'; import 'package:aku_community/base/base_style.dart'; import 'package:aku_community/utils/headers.dart'; class PublicInfomationCard extends StatelessWidget { - const PublicInfomationCard({Key? key}) : super(key: key); + final NewsItemModel model; + const PublicInfomationCard({Key? key, required this.model}) : super(key: key); @override Widget build(BuildContext context) { @@ -22,7 +27,7 @@ class PublicInfomationCard extends StatelessWidget { Expanded( child: Column( children: [ - Text('今日快讯|日本决定将核污水拍入海中,中方对此强势喊话日本考虑需谨慎'), + Text(model.title), Spacer(), DefaultTextStyle( style: TextStyle( @@ -31,9 +36,12 @@ class PublicInfomationCard extends StatelessWidget { ), child: Row( children: [ - Text('测试'), + // Text('测试'), Spacer(), - Text('发布于 4-11 10:11'), + Text('发布于 ${DateUtil.formatDate( + model.create, + format: 'yyyy-MM-dd HH:mm', + )}'), ], ), ), @@ -41,10 +49,12 @@ class PublicInfomationCard extends StatelessWidget { ), ), 32.wb, - SizedBox( + FadeInImage.assetNetwork( + placeholder: R.ASSETS_IMAGES_PLACEHOLDER_WEBP, width: 240.w, height: 200.w, - child: Placeholder(), + fit: BoxFit.cover, + image: API.image(ImgModel.first(model.imgList)), ), ], ), diff --git a/lib/ui/home/public_infomation/public_infomation_page.dart b/lib/ui/home/public_infomation/public_infomation_page.dart index e1e8faed..6ccca0e4 100644 --- a/lib/ui/home/public_infomation/public_infomation_page.dart +++ b/lib/ui/home/public_infomation/public_infomation_page.dart @@ -1,11 +1,16 @@ import 'package:flutter/material.dart'; +import 'package:aku_community/models/news/news_category_model.dart'; import 'package:aku_community/ui/home/public_infomation/public_infomation_view.dart'; import 'package:aku_community/widget/bee_scaffold.dart'; import 'package:aku_community/widget/tab_bar/bee_tab_bar.dart'; class PublicInfomationPage extends StatefulWidget { - PublicInfomationPage({Key? key}) : super(key: key); + final List models; + PublicInfomationPage({ + Key? key, + required this.models, + }) : super(key: key); @override _PublicInfomationPageState createState() => _PublicInfomationPageState(); @@ -13,20 +18,27 @@ class PublicInfomationPage extends StatefulWidget { class _PublicInfomationPageState extends State with TickerProviderStateMixin { - static const pubTabs = ['全部', '政务', '生活', '医疗', '教育']; TabController? _tabController; @override void initState() { super.initState(); - _tabController = TabController(length: pubTabs.length, vsync: this); + _tabController = TabController(length: widget.models.length, vsync: this); } @override Widget build(BuildContext context) { return BeeScaffold( title: '公共资讯', - appBarBottom: BeeTabBar(controller: _tabController, tabs: pubTabs), - body: PublicInfomationView(), + appBarBottom: BeeTabBar( + controller: _tabController, + tabs: widget.models.map((e) => e.name).toList(), + scrollable: true, + ), + body: TabBarView( + children: + widget.models.map((e) => PublicInfomationView(model: e)).toList(), + controller: _tabController, + ), ); } } diff --git a/lib/ui/home/public_infomation/public_infomation_view.dart b/lib/ui/home/public_infomation/public_infomation_view.dart index f62ee2d9..819bdcf1 100644 --- a/lib/ui/home/public_infomation/public_infomation_view.dart +++ b/lib/ui/home/public_infomation/public_infomation_view.dart @@ -1,25 +1,45 @@ +import 'package:aku_community/constants/api.dart'; +import 'package:aku_community/models/news/news_category_model.dart'; +import 'package:aku_community/models/news/news_item_model.dart'; +import 'package:aku_community/pages/things_page/widget/bee_list_view.dart'; import 'package:flutter/material.dart'; import 'package:aku_community/ui/home/public_infomation/public_infomation_card.dart'; import 'package:aku_community/utils/headers.dart'; +import 'package:flutter_easyrefresh/easy_refresh.dart'; class PublicInfomationView extends StatefulWidget { - PublicInfomationView({Key? key}) : super(key: key); + final NewsCategoryModel model; + PublicInfomationView({Key? key, required this.model}) : super(key: key); @override _PublicInfomationViewState createState() => _PublicInfomationViewState(); } -class _PublicInfomationViewState extends State { +class _PublicInfomationViewState extends State + with AutomaticKeepAliveClientMixin { + EasyRefreshController _refreshController = EasyRefreshController(); @override Widget build(BuildContext context) { - return ListView.separated( - padding: EdgeInsets.symmetric(vertical: 24.w), - itemBuilder: (context, index) { - return PublicInfomationCard(); + super.build(context); + return BeeListView( + path: API.news.list, + controller: _refreshController, + convert: (model) => + model.tableList!.map((e) => NewsItemModel.fromJson(e)).toList(), + builder: (items) { + return ListView.separated( + padding: EdgeInsets.symmetric(vertical: 24.w), + itemBuilder: (context, index) { + return PublicInfomationCard(model: items[index]); + }, + separatorBuilder: (_, __) => 24.hb, + itemCount: items.length, + ); }, - separatorBuilder: (_, __) => 24.hb, - itemCount: 100, ); } + + @override + bool get wantKeepAlive => true; } diff --git a/lib/ui/market/goods/goods_card.dart b/lib/ui/market/goods/goods_card.dart index a8c39e61..8d48a713 100644 --- a/lib/ui/market/goods/goods_card.dart +++ b/lib/ui/market/goods/goods_card.dart @@ -1,9 +1,9 @@ -import 'package:aku_community/models/market/goods_item.dart'; import 'package:flutter/material.dart'; import 'package:get/get.dart'; import 'package:aku_community/base/base_style.dart'; +import 'package:aku_community/models/market/goods_item.dart'; import 'package:aku_community/ui/market/goods/goods_detail_page.dart'; import 'package:aku_community/utils/headers.dart'; diff --git a/lib/ui/market/goods/goods_detail_page.dart b/lib/ui/market/goods/goods_detail_page.dart index f8b56fd2..526ef1f5 100644 --- a/lib/ui/market/goods/goods_detail_page.dart +++ b/lib/ui/market/goods/goods_detail_page.dart @@ -1,4 +1,16 @@ +import 'package:flutter/cupertino.dart'; +import 'package:flutter/material.dart'; + +import 'package:bot_toast/bot_toast.dart'; +import 'package:flutter_easyrefresh/easy_refresh.dart'; +import 'package:flutter_screenutil/flutter_screenutil.dart'; +import 'package:get/get.dart'; +import 'package:provider/provider.dart'; +import 'package:velocity_x/velocity_x.dart'; +import 'package:waterfall_flow/waterfall_flow.dart'; + import 'package:aku_community/base/base_style.dart'; +import 'package:aku_community/const/resource.dart'; import 'package:aku_community/constants/api.dart'; import 'package:aku_community/model/common/img_model.dart'; import 'package:aku_community/models/market/goods_detail_model.dart'; @@ -9,18 +21,7 @@ import 'package:aku_community/ui/market/search/search_goods_page.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_back_button.dart'; -import 'package:bot_toast/bot_toast.dart'; -import 'package:flutter/cupertino.dart'; -import 'package:flutter/material.dart'; - import 'package:aku_community/widget/bee_scaffold.dart'; -import 'package:flutter_easyrefresh/easy_refresh.dart'; -import 'package:get/get.dart'; -import 'package:provider/provider.dart'; -import 'package:velocity_x/velocity_x.dart'; -import 'package:flutter_screenutil/flutter_screenutil.dart'; -import 'package:aku_community/const/resource.dart'; -import 'package:waterfall_flow/waterfall_flow.dart'; ///商品详情页面 class GoodsDetailPage extends StatefulWidget { diff --git a/lib/ui/market/goods/goods_tab_list_view.dart b/lib/ui/market/goods/goods_tab_list_view.dart index 1cae0521..6f0085d7 100644 --- a/lib/ui/market/goods/goods_tab_list_view.dart +++ b/lib/ui/market/goods/goods_tab_list_view.dart @@ -1,4 +1,3 @@ -import 'package:aku_community/ui/market/goods/goods_card.dart'; import 'package:flutter/material.dart'; import 'package:flutter_easyrefresh/easy_refresh.dart'; @@ -8,6 +7,7 @@ import 'package:aku_community/constants/api.dart'; import 'package:aku_community/models/market/goods_item.dart'; import 'package:aku_community/models/market/market_category_model.dart'; import 'package:aku_community/pages/things_page/widget/bee_list_view.dart'; +import 'package:aku_community/ui/market/goods/goods_card.dart'; import 'package:aku_community/utils/headers.dart'; class GoodsTabListView extends StatefulWidget { diff --git a/lib/ui/market/market_page.dart b/lib/ui/market/market_page.dart index 6d260a29..a078163b 100644 --- a/lib/ui/market/market_page.dart +++ b/lib/ui/market/market_page.dart @@ -1,25 +1,28 @@ // import 'package:aku_community/base/base_style.dart'; -import 'package:aku_community/constants/api.dart'; -import 'package:aku_community/models/market/goods_item.dart'; -import 'package:aku_community/ui/market/goods/goods_card.dart'; -// import 'package:aku_community/ui/market/goods/goods_detail_page.dart'; -import 'package:aku_community/utils/network/base_model.dart'; -import 'package:aku_community/utils/network/net_util.dart'; + import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:bot_toast/bot_toast.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:get/get.dart'; +import 'package:waterfall_flow/waterfall_flow.dart'; +import 'package:aku_community/constants/api.dart'; import 'package:aku_community/models/market/display_category_model.dart'; +import 'package:aku_community/models/market/goods_item.dart'; import 'package:aku_community/models/market/market_category_model.dart'; import 'package:aku_community/ui/market/category/category_card.dart'; import 'package:aku_community/ui/market/category/category_page.dart'; +import 'package:aku_community/ui/market/goods/goods_card.dart'; import 'package:aku_community/ui/market/search/search_goods_page.dart'; import 'package:aku_community/utils/headers.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_scaffold.dart'; -import 'package:waterfall_flow/waterfall_flow.dart'; + +// import 'package:aku_community/ui/market/goods/goods_detail_page.dart'; + // import 'package:aku_community/widget/tab_bar/bee_tab_bar.dart'; class MarketPage extends StatefulWidget { diff --git a/lib/ui/market/search/search_goods_page.dart b/lib/ui/market/search/search_goods_page.dart index 5315cc47..60a52066 100644 --- a/lib/ui/market/search/search_goods_page.dart +++ b/lib/ui/market/search/search_goods_page.dart @@ -1,13 +1,13 @@ -import 'package:aku_community/constants/api.dart'; -import 'package:aku_community/models/market/goods_item.dart'; -import 'package:aku_community/pages/things_page/widget/bee_list_view.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; -import 'package:flutter_easyrefresh/easy_refresh.dart'; +import 'package:flutter_easyrefresh/easy_refresh.dart'; import 'package:waterfall_flow/waterfall_flow.dart'; import 'package:aku_community/base/base_style.dart'; +import 'package:aku_community/constants/api.dart'; +import 'package:aku_community/models/market/goods_item.dart'; +import 'package:aku_community/pages/things_page/widget/bee_list_view.dart'; import 'package:aku_community/ui/market/goods/goods_card.dart'; import 'package:aku_community/utils/headers.dart'; import 'package:aku_community/widget/bee_scaffold.dart';