From 9ddddb8d10094eddf6fcf3e5e046ff1bef70a0d1 Mon Sep 17 00:00:00 2001 From: user Date: Mon, 6 Jun 2022 16:36:11 +0800 Subject: [PATCH] =?UTF-8?q?v8.0=20*=20=E9=A1=B9=E7=9B=AE=E5=88=86=E7=B1=BB?= =?UTF-8?q?=E3=80=81=E9=A1=B9=E7=9B=AE=E5=88=97=E8=A1=A8=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 + lib/models/project_article_response.dart | 269 +++++++++--------- lib/models/project_article_response.g.dart | 93 +----- ...sponse.dart => project_tree_response.dart} | 20 +- ...se.g.dart => project_tree_response.g.dart} | 15 +- lib/pages/home/bindings/home_binding.dart | 10 + lib/pages/main/views/main_view.dart | 76 ++--- lib/pages/me/views/me_view.dart | 5 +- .../views/message_detail_web_page.dart | 6 +- lib/pages/message/views/message_view.dart | 2 +- .../project/bindings/project_binding.dart | 12 + .../controllers/project_controller.dart | 58 +++- .../project_tree_children_binding.dart | 9 + .../project_tree_children_controller.dart | 134 +++++++++ .../project_tree_children_page.dart | 62 ++++ lib/pages/project/views/project_view.dart | 64 ++++- lib/provider/request_api.dart | 4 +- lib/res/app_theme.dart | 2 +- lib/routes/app_pages.dart | 35 ++- lib/widgets/message_list_item_widget.dart | 5 +- lib/widgets/search_list_item_widget.dart | 3 +- 21 files changed, 575 insertions(+), 311 deletions(-) rename lib/models/{project_response.dart => project_tree_response.dart} (55%) rename lib/models/{project_response.g.dart => project_tree_response.g.dart} (76%) create mode 100644 lib/pages/home/bindings/home_binding.dart create mode 100644 lib/pages/project/bindings/project_binding.dart create mode 100644 lib/pages/project/project_tree_children/project_tree_children_binding.dart create mode 100644 lib/pages/project/project_tree_children/project_tree_children_controller.dart create mode 100644 lib/pages/project/project_tree_children/project_tree_children_page.dart diff --git a/README.md b/README.md index 1dbe295..1d11955 100644 --- a/README.md +++ b/README.md @@ -71,6 +71,8 @@ * 在BaseController中根据用户是否已经登陆请求数据接口,展示消息数据 * 将MessageControlLer中读取未读消息的数据,移动到未读消息控制器中,在数据请求到同时调用此接口 +### v8.0 +* 项目分类、项目列表数据 ## 五 使用的指令 diff --git a/lib/models/project_article_response.dart b/lib/models/project_article_response.dart index be063c4..72bb51e 100644 --- a/lib/models/project_article_response.dart +++ b/lib/models/project_article_response.dart @@ -1,3 +1,4 @@ +import 'package:flutter_wanandroid/models/home_article_response.dart'; import 'package:json_annotation/json_annotation.dart'; part 'project_article_response.g.dart'; @@ -8,7 +9,7 @@ part 'project_article_response.g.dart'; class ProjectArticleResponse extends Object { @JsonKey(name: 'data') - Data data; + ProjectData data; @JsonKey(name: 'errorCode') int errorCode; @@ -26,13 +27,13 @@ class ProjectArticleResponse extends Object { @JsonSerializable() -class Data extends Object { +class ProjectData extends Object { @JsonKey(name: 'curPage') int curPage; @JsonKey(name: 'datas') - List datas; + List
datas; @JsonKey(name: 'offset') int offset; @@ -49,141 +50,141 @@ class Data extends Object { @JsonKey(name: 'total') int total; - Data(this.curPage,this.datas,this.offset,this.over,this.pageCount,this.size,this.total,); + ProjectData(this.curPage,this.datas,this.offset,this.over,this.pageCount,this.size,this.total,); - factory Data.fromJson(Map srcJson) => _$DataFromJson(srcJson); + factory ProjectData.fromJson(Map srcJson) => _$ProjectDataFromJson(srcJson); - Map toJson() => _$DataToJson(this); + Map toJson() => _$ProjectDataToJson(this); } - -@JsonSerializable() -class Datas extends Object { - - @JsonKey(name: 'apkLink') - String apkLink; - - @JsonKey(name: 'audit') - int audit; - - @JsonKey(name: 'author') - String author; - - @JsonKey(name: 'canEdit') - bool canEdit; - - @JsonKey(name: 'chapterId') - int chapterId; - - @JsonKey(name: 'chapterName') - String chapterName; - - @JsonKey(name: 'collect') - bool collect; - - @JsonKey(name: 'courseId') - int courseId; - - @JsonKey(name: 'desc') - String desc; - - @JsonKey(name: 'descMd') - String descMd; - - @JsonKey(name: 'envelopePic') - String envelopePic; - - @JsonKey(name: 'fresh') - bool fresh; - - @JsonKey(name: 'host') - String host; - - @JsonKey(name: 'id') - int id; - - @JsonKey(name: 'link') - String link; - - @JsonKey(name: 'niceDate') - String niceDate; - - @JsonKey(name: 'niceShareDate') - String niceShareDate; - - @JsonKey(name: 'origin') - String origin; - - @JsonKey(name: 'prefix') - String prefix; - - @JsonKey(name: 'projectLink') - String projectLink; - - @JsonKey(name: 'publishTime') - int publishTime; - - @JsonKey(name: 'realSuperChapterId') - int realSuperChapterId; - - @JsonKey(name: 'selfVisible') - int selfVisible; - - @JsonKey(name: 'shareDate') - int shareDate; - - @JsonKey(name: 'shareUser') - String shareUser; - - @JsonKey(name: 'superChapterId') - int superChapterId; - - @JsonKey(name: 'superChapterName') - String superChapterName; - - @JsonKey(name: 'tags') - List tags; - - @JsonKey(name: 'title') - String title; - - @JsonKey(name: 'type') - int type; - - @JsonKey(name: 'userId') - int userId; - - @JsonKey(name: 'visible') - int visible; - - @JsonKey(name: 'zan') - int zan; - - Datas(this.apkLink,this.audit,this.author,this.canEdit,this.chapterId,this.chapterName,this.collect,this.courseId,this.desc,this.descMd,this.envelopePic,this.fresh,this.host,this.id,this.link,this.niceDate,this.niceShareDate,this.origin,this.prefix,this.projectLink,this.publishTime,this.realSuperChapterId,this.selfVisible,this.shareDate,this.shareUser,this.superChapterId,this.superChapterName,this.tags,this.title,this.type,this.userId,this.visible,this.zan,); - - factory Datas.fromJson(Map srcJson) => _$DatasFromJson(srcJson); - - Map toJson() => _$DatasToJson(this); - -} - - -@JsonSerializable() -class Tags extends Object { - - @JsonKey(name: 'name') - String name; - - @JsonKey(name: 'url') - String url; - - Tags(this.name,this.url,); - - factory Tags.fromJson(Map srcJson) => _$TagsFromJson(srcJson); - - Map toJson() => _$TagsToJson(this); - -} +// +// @JsonSerializable() +// class Datas extends Object { +// +// @JsonKey(name: 'apkLink') +// String apkLink; +// +// @JsonKey(name: 'audit') +// int audit; +// +// @JsonKey(name: 'author') +// String author; +// +// @JsonKey(name: 'canEdit') +// bool canEdit; +// +// @JsonKey(name: 'chapterId') +// int chapterId; +// +// @JsonKey(name: 'chapterName') +// String chapterName; +// +// @JsonKey(name: 'collect') +// bool collect; +// +// @JsonKey(name: 'courseId') +// int courseId; +// +// @JsonKey(name: 'desc') +// String desc; +// +// @JsonKey(name: 'descMd') +// String descMd; +// +// @JsonKey(name: 'envelopePic') +// String envelopePic; +// +// @JsonKey(name: 'fresh') +// bool fresh; +// +// @JsonKey(name: 'host') +// String host; +// +// @JsonKey(name: 'id') +// int id; +// +// @JsonKey(name: 'link') +// String link; +// +// @JsonKey(name: 'niceDate') +// String niceDate; +// +// @JsonKey(name: 'niceShareDate') +// String niceShareDate; +// +// @JsonKey(name: 'origin') +// String origin; +// +// @JsonKey(name: 'prefix') +// String prefix; +// +// @JsonKey(name: 'projectLink') +// String projectLink; +// +// @JsonKey(name: 'publishTime') +// int publishTime; +// +// @JsonKey(name: 'realSuperChapterId') +// int realSuperChapterId; +// +// @JsonKey(name: 'selfVisible') +// int selfVisible; +// +// @JsonKey(name: 'shareDate') +// int shareDate; +// +// @JsonKey(name: 'shareUser') +// String shareUser; +// +// @JsonKey(name: 'superChapterId') +// int superChapterId; +// +// @JsonKey(name: 'superChapterName') +// String superChapterName; +// +// @JsonKey(name: 'tags') +// List tags; +// +// @JsonKey(name: 'title') +// String title; +// +// @JsonKey(name: 'type') +// int type; +// +// @JsonKey(name: 'userId') +// int userId; +// +// @JsonKey(name: 'visible') +// int visible; +// +// @JsonKey(name: 'zan') +// int zan; +// +// Datas(this.apkLink,this.audit,this.author,this.canEdit,this.chapterId,this.chapterName,this.collect,this.courseId,this.desc,this.descMd,this.envelopePic,this.fresh,this.host,this.id,this.link,this.niceDate,this.niceShareDate,this.origin,this.prefix,this.projectLink,this.publishTime,this.realSuperChapterId,this.selfVisible,this.shareDate,this.shareUser,this.superChapterId,this.superChapterName,this.tags,this.title,this.type,this.userId,this.visible,this.zan,); +// +// factory Datas.fromJson(Map srcJson) => _$DatasFromJson(srcJson); +// +// Map toJson() => _$DatasToJson(this); +// +// } +// +// +// @JsonSerializable() +// class Tags extends Object { +// +// @JsonKey(name: 'name') +// String name; +// +// @JsonKey(name: 'url') +// String url; +// +// Tags(this.name,this.url,); +// +// factory Tags.fromJson(Map srcJson) => _$TagsFromJson(srcJson); +// +// Map toJson() => _$TagsToJson(this); +// +// } diff --git a/lib/models/project_article_response.g.dart b/lib/models/project_article_response.g.dart index 54a5741..7b0f0be 100644 --- a/lib/models/project_article_response.g.dart +++ b/lib/models/project_article_response.g.dart @@ -9,7 +9,7 @@ part of 'project_article_response.dart'; ProjectArticleResponse _$ProjectArticleResponseFromJson( Map json) => ProjectArticleResponse( - Data.fromJson(json['data'] as Map), + ProjectData.fromJson(json['data'] as Map), json['errorCode'] as int, json['errorMsg'] as String, ); @@ -22,10 +22,10 @@ Map _$ProjectArticleResponseToJson( 'errorMsg': instance.errorMsg, }; -Data _$DataFromJson(Map json) => Data( +ProjectData _$ProjectDataFromJson(Map json) => ProjectData( json['curPage'] as int, (json['datas'] as List) - .map((e) => Datas.fromJson(e as Map)) + .map((e) => Article.fromJson(e as Map)) .toList(), json['offset'] as int, json['over'] as bool, @@ -34,7 +34,8 @@ Data _$DataFromJson(Map json) => Data( json['total'] as int, ); -Map _$DataToJson(Data instance) => { +Map _$ProjectDataToJson(ProjectData instance) => + { 'curPage': instance.curPage, 'datas': instance.datas, 'offset': instance.offset, @@ -43,87 +44,3 @@ Map _$DataToJson(Data instance) => { 'size': instance.size, 'total': instance.total, }; - -Datas _$DatasFromJson(Map json) => Datas( - json['apkLink'] as String, - json['audit'] as int, - json['author'] as String, - json['canEdit'] as bool, - json['chapterId'] as int, - json['chapterName'] as String, - json['collect'] as bool, - json['courseId'] as int, - json['desc'] as String, - json['descMd'] as String, - json['envelopePic'] as String, - json['fresh'] as bool, - json['host'] as String, - json['id'] as int, - json['link'] as String, - json['niceDate'] as String, - json['niceShareDate'] as String, - json['origin'] as String, - json['prefix'] as String, - json['projectLink'] as String, - json['publishTime'] as int, - json['realSuperChapterId'] as int, - json['selfVisible'] as int, - json['shareDate'] as int, - json['shareUser'] as String, - json['superChapterId'] as int, - json['superChapterName'] as String, - (json['tags'] as List) - .map((e) => Tags.fromJson(e as Map)) - .toList(), - json['title'] as String, - json['type'] as int, - json['userId'] as int, - json['visible'] as int, - json['zan'] as int, - ); - -Map _$DatasToJson(Datas instance) => { - 'apkLink': instance.apkLink, - 'audit': instance.audit, - 'author': instance.author, - 'canEdit': instance.canEdit, - 'chapterId': instance.chapterId, - 'chapterName': instance.chapterName, - 'collect': instance.collect, - 'courseId': instance.courseId, - 'desc': instance.desc, - 'descMd': instance.descMd, - 'envelopePic': instance.envelopePic, - 'fresh': instance.fresh, - 'host': instance.host, - 'id': instance.id, - 'link': instance.link, - 'niceDate': instance.niceDate, - 'niceShareDate': instance.niceShareDate, - 'origin': instance.origin, - 'prefix': instance.prefix, - 'projectLink': instance.projectLink, - 'publishTime': instance.publishTime, - 'realSuperChapterId': instance.realSuperChapterId, - 'selfVisible': instance.selfVisible, - 'shareDate': instance.shareDate, - 'shareUser': instance.shareUser, - 'superChapterId': instance.superChapterId, - 'superChapterName': instance.superChapterName, - 'tags': instance.tags, - 'title': instance.title, - 'type': instance.type, - 'userId': instance.userId, - 'visible': instance.visible, - 'zan': instance.zan, - }; - -Tags _$TagsFromJson(Map json) => Tags( - json['name'] as String, - json['url'] as String, - ); - -Map _$TagsToJson(Tags instance) => { - 'name': instance.name, - 'url': instance.url, - }; diff --git a/lib/models/project_response.dart b/lib/models/project_tree_response.dart similarity index 55% rename from lib/models/project_response.dart rename to lib/models/project_tree_response.dart index deb1d1f..a120e62 100644 --- a/lib/models/project_response.dart +++ b/lib/models/project_tree_response.dart @@ -1,14 +1,14 @@ import 'package:json_annotation/json_annotation.dart'; -part 'project_response.g.dart'; +part 'project_tree_response.g.dart'; ///4-4.1 项目分类 @JsonSerializable() -class ProjectResponse extends Object { +class ProjectTreeResponse extends Object { @JsonKey(name: 'data') - List data; + List data; @JsonKey(name: 'errorCode') int errorCode; @@ -16,17 +16,17 @@ class ProjectResponse extends Object { @JsonKey(name: 'errorMsg') String errorMsg; - ProjectResponse(this.data,this.errorCode,this.errorMsg,); + ProjectTreeResponse(this.data,this.errorCode,this.errorMsg,); - factory ProjectResponse.fromJson(Map srcJson) => _$ProjectResponseFromJson(srcJson); + factory ProjectTreeResponse.fromJson(Map srcJson) => _$ProjectTreeResponseFromJson(srcJson); - Map toJson() => _$ProjectResponseToJson(this); + Map toJson() => _$ProjectTreeResponseToJson(this); } @JsonSerializable() -class Data extends Object { +class Project extends Object { @JsonKey(name: 'author') String author; @@ -67,11 +67,11 @@ class Data extends Object { @JsonKey(name: 'visible') int visible; - Data(this.author,this.children,this.courseId,this.cover,this.desc,this.id,this.lisense,this.lisenseLink,this.name,this.order,this.parentChapterId,this.userControlSetTop,this.visible,); + Project(this.author,this.children,this.courseId,this.cover,this.desc,this.id,this.lisense,this.lisenseLink,this.name,this.order,this.parentChapterId,this.userControlSetTop,this.visible,); - factory Data.fromJson(Map srcJson) => _$DataFromJson(srcJson); + factory Project.fromJson(Map srcJson) => _$ProjectFromJson(srcJson); - Map toJson() => _$DataToJson(this); + Map toJson() => _$ProjectToJson(this); } diff --git a/lib/models/project_response.g.dart b/lib/models/project_tree_response.g.dart similarity index 76% rename from lib/models/project_response.g.dart rename to lib/models/project_tree_response.g.dart index cf90d2e..ba3e8ff 100644 --- a/lib/models/project_response.g.dart +++ b/lib/models/project_tree_response.g.dart @@ -1,28 +1,29 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -part of 'project_response.dart'; +part of 'project_tree_response.dart'; // ************************************************************************** // JsonSerializableGenerator // ************************************************************************** -ProjectResponse _$ProjectResponseFromJson(Map json) => - ProjectResponse( +ProjectTreeResponse _$ProjectTreeResponseFromJson(Map json) => + ProjectTreeResponse( (json['data'] as List) - .map((e) => Data.fromJson(e as Map)) + .map((e) => Project.fromJson(e as Map)) .toList(), json['errorCode'] as int, json['errorMsg'] as String, ); -Map _$ProjectResponseToJson(ProjectResponse instance) => +Map _$ProjectTreeResponseToJson( + ProjectTreeResponse instance) => { 'data': instance.data, 'errorCode': instance.errorCode, 'errorMsg': instance.errorMsg, }; -Data _$DataFromJson(Map json) => Data( +Project _$ProjectFromJson(Map json) => Project( json['author'] as String, json['children'] as List, json['courseId'] as int, @@ -38,7 +39,7 @@ Data _$DataFromJson(Map json) => Data( json['visible'] as int, ); -Map _$DataToJson(Data instance) => { +Map _$ProjectToJson(Project instance) => { 'author': instance.author, 'children': instance.children, 'courseId': instance.courseId, diff --git a/lib/pages/home/bindings/home_binding.dart b/lib/pages/home/bindings/home_binding.dart new file mode 100644 index 0000000..044ceea --- /dev/null +++ b/lib/pages/home/bindings/home_binding.dart @@ -0,0 +1,10 @@ +import 'package:flutter_wanandroid/pages/home/controllers/home_controller.dart'; +import 'package:get/get.dart'; + +class HomeBinding extends Bindings{ + @override + void dependencies() { + Get.lazyPut(() => HomeController()); + } + +} \ No newline at end of file diff --git a/lib/pages/main/views/main_view.dart b/lib/pages/main/views/main_view.dart index 343b93a..928ac41 100644 --- a/lib/pages/main/views/main_view.dart +++ b/lib/pages/main/views/main_view.dart @@ -42,45 +42,45 @@ class MainView extends GetView { // } AppBar? _buildAppBar() { - return AppBar( - centerTitle: true, - title: Text("${controller.currentTitle}"), - actions: [ - (controller.currentTitle == Keys.me.tr) - ? IconButton( - icon: const Icon(Icons.settings), - onPressed: () { - Get.toNamed(Routes.setting); - }, - ) - : IconButton( - icon: const Icon(Icons.search), - onPressed: () {}, - ) - ], - ); + // return AppBar( + // centerTitle: true, + // title: Text("${controller.currentTitle}"), + // actions: [ + // (controller.currentTitle == Keys.me.tr) + // ? IconButton( + // icon: const Icon(Icons.settings), + // onPressed: () { + // Get.toNamed(Routes.setting); + // }, + // ) + // : IconButton( + // icon: const Icon(Icons.search), + // onPressed: () {}, + // ) + // ], + // ); - // if (controller.currentTitle == Keys.navigation.tr) { - // return null; - // } else { - // return AppBar( - // centerTitle: true, - // title: Text("${controller.currentTitle}"), - // actions: [ - // (controller.currentTitle == Keys.me.tr) - // ? IconButton( - // icon: const Icon(Icons.settings), - // onPressed: () { - // Get.toNamed(Routes.setting); - // }, - // ) - // : IconButton( - // icon: const Icon(Icons.search), - // onPressed: () {}, - // ) - // ], - // ); - // } + if (controller.currentTitle == Keys.project.tr) { + return null; + } else { + return AppBar( + centerTitle: true, + title: Text("${controller.currentTitle}"), + actions: [ + (controller.currentTitle == Keys.me.tr) + ? IconButton( + icon: const Icon(Icons.settings), + onPressed: () { + Get.toNamed(Routes.setting); + }, + ) + : IconButton( + icon: const Icon(Icons.search), + onPressed: () {}, + ) + ], + ); + } // if (controller.currentTitle == Keys.home.tr || // controller.currentTitle == Keys.me.tr) { diff --git a/lib/pages/me/views/me_view.dart b/lib/pages/me/views/me_view.dart index 38a5ef3..ee944cd 100644 --- a/lib/pages/me/views/me_view.dart +++ b/lib/pages/me/views/me_view.dart @@ -24,7 +24,7 @@ class MeView extends GetView { @override Widget build(BuildContext context) { return Obx( - () => ListView(children: [_buildHeadInfo(context), _buildCategory()])); + () => ListView(children: [_buildHeadInfo(context), _buildCategory(context)])); } ///me-head信息 @@ -92,7 +92,7 @@ class MeView extends GetView { ))); } - Widget _buildCategory() { + Widget _buildCategory(BuildContext context) { List gfComponents = [ { 'title': Keys.meTools.tr, @@ -151,6 +151,7 @@ class MeView extends GetView { GFTypography( text: Keys.meCommonTools.tr, type: GFTypographyType.typo5, + textColor: context.appIconColor, //dividerWidth: 25, dividerColor: Color(0xFF19CA4B), ), diff --git a/lib/pages/message/views/message_detail_web_page.dart b/lib/pages/message/views/message_detail_web_page.dart index f9856cd..6d01340 100644 --- a/lib/pages/message/views/message_detail_web_page.dart +++ b/lib/pages/message/views/message_detail_web_page.dart @@ -47,14 +47,14 @@ class MessageDetailWebPage extends GetView { }, // 页面开始加载时 onPageStarted: (String url) async { - controller.onPageStarted(url, model.link ?? ""); + controller.onPageStarted(url, model.link); }, onProgress: (int progress) { // WebView加载页面进度 controller.updateWebProgress(progress); }, onPageFinished: (url) async { - controller.onPageFinished(url, model.link ?? ""); + controller.onPageFinished(url, model.link); }, navigationDelegate: (NavigationRequest request) { if (!request.url.contains('http')) { @@ -63,7 +63,7 @@ class MessageDetailWebPage extends GetView { return NavigationDecision.navigate; }, onWebResourceError: (WebResourceError error) { - controller.onWebResourceError(error, url, model.link ?? ""); + controller.onWebResourceError(error, url, model.link); }, ), Obx(() { diff --git a/lib/pages/message/views/message_view.dart b/lib/pages/message/views/message_view.dart index bc25cb7..9d65741 100644 --- a/lib/pages/message/views/message_view.dart +++ b/lib/pages/message/views/message_view.dart @@ -33,7 +33,7 @@ class MessageView extends GetView { Widget _buildTabsWidget(){ return GFSegmentTabs( width: Get.width, - height: 40, + //height: 30, //controller: controller.tabController, tabController: controller.tabController, tabBarColor: GFColors.LIGHT, diff --git a/lib/pages/project/bindings/project_binding.dart b/lib/pages/project/bindings/project_binding.dart new file mode 100644 index 0000000..3622793 --- /dev/null +++ b/lib/pages/project/bindings/project_binding.dart @@ -0,0 +1,12 @@ +import 'package:get/get.dart'; + +import '../controllers/project_controller.dart'; +import '../project_tree_children/project_tree_children_controller.dart'; + +class ProjectBinding extends Bindings { + @override + void dependencies() { + Get.lazyPut(() => ProjectController()); + Get.lazyPut(() => ProjectTreeChildrenController()); + } +} diff --git a/lib/pages/project/controllers/project_controller.dart b/lib/pages/project/controllers/project_controller.dart index 1f7348c..ffd8ab4 100644 --- a/lib/pages/project/controllers/project_controller.dart +++ b/lib/pages/project/controllers/project_controller.dart @@ -1,8 +1,60 @@ -import 'package:get/get_state_manager/src/simple/get_controllers.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_wanandroid/models/project_tree_response.dart'; +import 'package:flutter_wanandroid/provider/base_controller.dart'; +import 'package:flutter_wanandroid/provider/request_api.dart'; +import 'package:get/get.dart'; +import '../../../provider/state/load_state.dart'; +import '../../../res/constant.dart'; /// 日期:2022-05-15 /// 描述:主页-主屏页面-Body-project-页面 /// 说明: -class ProjectController extends GetxController { -} \ No newline at end of file +class ProjectController extends BaseController { + ///Tab控制器 + late TabController tabController; + + ///项目分类 + final projectTreeList = RxList(); + + ///分类项 + late List tabPageBodies; + + @override + void onInit() { + super.onInit(); + //getProjectTreeList(); + // tabPageBodies = []; + } + + Future getProjectTreeList() async { + httpManager( + loadingType: Constant.showLoadingDialog, + future: provider.get(RequestAPI.projectTreeList), + onSuccess: (response) { + ///列表转换的时候一定要加一下强转List,否则会报错 + List dataList = (response as List) + .map((e) => Project.fromJson(e)) + .toList(); + projectTreeList.assignAll(dataList); + if (projectTreeList.isNotEmpty) { + initTabController(); + loadState = LoadState.success; + } else { + loadState = LoadState.empty; + } + }, + onFail: (value) { + loadState = LoadState.fail; + }, + onError: (error) { + loadState = LoadState.fail; + }, + ); + } + + void initTabController() { + tabController = TabController( + length: projectTreeList.length, initialIndex: 0, vsync: this); + } +} diff --git a/lib/pages/project/project_tree_children/project_tree_children_binding.dart b/lib/pages/project/project_tree_children/project_tree_children_binding.dart new file mode 100644 index 0000000..5b35b8b --- /dev/null +++ b/lib/pages/project/project_tree_children/project_tree_children_binding.dart @@ -0,0 +1,9 @@ +import 'package:get/get.dart'; +import 'project_tree_children_controller.dart'; + +class ProjectTreeChildrenBinding extends Bindings { + @override + void dependencies() { + Get.lazyPut(() => ProjectTreeChildrenController()); + } +} diff --git a/lib/pages/project/project_tree_children/project_tree_children_controller.dart b/lib/pages/project/project_tree_children/project_tree_children_controller.dart new file mode 100644 index 0000000..7e955ea --- /dev/null +++ b/lib/pages/project/project_tree_children/project_tree_children_controller.dart @@ -0,0 +1,134 @@ + +import 'package:flutter_easyloading/flutter_easyloading.dart'; +import 'package:flutter_wanandroid/models/home_article_response.dart'; +import 'package:flutter_wanandroid/models/project_article_response.dart'; +import 'package:flutter_wanandroid/provider/base_refresh_controller.dart'; +import 'package:flutter_wanandroid/provider/request_api.dart'; +import 'package:get/get.dart'; +import 'package:sprintf/sprintf.dart'; + +import '../../../provider/state/load_state.dart'; +import '../../../res/constant.dart'; + +class ProjectTreeChildrenController extends BaseRefreshController { + final Rx cid = 0.obs; + + final projectTreeArticleList = RxList
(); + + void setCid(int? id) { + cid.value = id; + } + + @override + void onInit() { + super.onInit(); + + loadState = LoadState.lottieRocketLoading; + // 项目列表数据 页码:拼接在链接中,从1开始 + currentPage = 1; + + // ever(isLogin, (callback) { + // onRefreshRequestData(); + // // 定位到顶部 + // if (scrollController.hasClients) { + // scrollController.jumpTo(0); + // } + // }); + } + + /// 第一次进入 + void onFirstInRequestData() { + initProjectChildrenArticleListData( + loadingType: Constant.multipleShimmerLoading, + refreshState: RefreshState.first, + cid: cid.value, + ); + } + + /// 下拉刷新首页 + void onRefreshRequestData() { + initProjectChildrenArticleListData( + loadingType: Constant.noLoading, + refreshState: RefreshState.refresh, + cid: cid.value, + ); + } + + /// 上滑加载更多 + void onLoadMoreRequestData() { + initProjectChildrenArticleListData( + loadingType: Constant.noLoading, + refreshState: RefreshState.loadMore, + cid: cid.value, + ); + } + + /// 项目分类下的文章 + Future initProjectChildrenArticleListData({ + required String loadingType, + required RefreshState refreshState, + required int? cid, + }) async { + if (refreshState == RefreshState.refresh || + refreshState == RefreshState.first) { + /// 下拉刷新 项目列表数据 页码:拼接在链接中,从1开始。 + currentPage = 1; + } + if (refreshState == RefreshState.loadMore) { + /// 上滑加载更多 + currentPage++; + } + + String requestUrl = sprintf(RequestAPI.projectArticleList, [currentPage,cid]); + + httpManagerWithRefreshPaging( + loadingType: loadingType, + refreshState: refreshState, + future:provider.get(requestUrl), + + onSuccess: (response) { + var articleDataModel = ProjectData.fromJson(response); + List
? dataList = articleDataModel.datas; + + // 加载到底部判断 + var over = articleDataModel.over; + if (over != null) { + if (over) { + loadNoData(); + } + } + + if (dataList != null && dataList.isNotEmpty) { + loadState = LoadState.success; + refreshLoadState = LoadState.success; + + /// 循环遍历 装载 可观察变量 isCollect + for (var element in dataList) { + var collect = element.collect; + + } + + if (refreshState == RefreshState.first) { + projectTreeArticleList.assignAll(dataList); + } else if (refreshState == RefreshState.refresh) { + projectTreeArticleList.assignAll(dataList); + } else if (refreshState == RefreshState.loadMore) { + projectTreeArticleList.addAll(dataList); + } + } else { + if (loadingType != Constant.noLoading) { + refreshLoadState = LoadState.empty; + } else { + loadNoData(); + } + } + }, + onFail: (value) { + EasyLoading.showError("${value.errorMsg}"); + }, + onError: (error) { + EasyLoading.showError("${value.errorMsg}"); + }, + ); + } +} diff --git a/lib/pages/project/project_tree_children/project_tree_children_page.dart b/lib/pages/project/project_tree_children/project_tree_children_page.dart new file mode 100644 index 0000000..687aaf2 --- /dev/null +++ b/lib/pages/project/project_tree_children/project_tree_children_page.dart @@ -0,0 +1,62 @@ +import 'package:flutter/material.dart'; +import 'package:get/get.dart'; +import 'package:pull_to_refresh/pull_to_refresh.dart'; +import '../../../provider/refresh/refresh_paging_state_page.dart'; +import '../../../widgets/search_list_item_widget.dart'; +import 'project_tree_children_controller.dart'; + +/// 类名: project_tree_children_page.dart +/// 描述: 项目分类下的文章列表 + +class ProjectTreeChildrenPage extends StatelessWidget { + const ProjectTreeChildrenPage({ + Key? key, + this.id, + }) : super(key: key); + + final int? id; + + @override + Widget build(BuildContext context) { + /// Don't use one refreshController to multiple SmartRefresher,It will cause some unexpected bugs mostly in TabBarView + /// 解决办法 + final controller = Get.put(ProjectTreeChildrenController(), tag: id.toString()); + + //final detailController = Get.find(); + // + // /// 赋值cid + controller.setCid(id); + + /// 第一次进入 + controller.onFirstInRequestData(); + + return Scaffold( + body: Obx(() { + return RefreshPagingStatePage( + controller: controller, + refreshController: controller.refreshController, + onPressed: () => controller.onFirstInRequestData(), + onRefresh: () => controller.onRefreshRequestData(), + onLoadMore: () => controller.onLoadMoreRequestData(), + header: const ClassicHeader(), + // lottieRocketRefreshHeader: false, + child: ListView.builder( + controller: controller.scrollController, + itemCount: controller.projectTreeArticleList.length, + itemBuilder: (context, index) { + return SearchListItemWidget( + dataList: controller.projectTreeArticleList, + index: index, + onCollectClick: (int index) { + // 文章列表收藏、取消收藏 + // detailController.requestCollectArticle( + // controller.projectTreeArticleList[index]); + }, + ); + }, + ), + ); + }), + ); + } +} diff --git a/lib/pages/project/views/project_view.dart b/lib/pages/project/views/project_view.dart index 80e6b91..258dcf0 100644 --- a/lib/pages/project/views/project_view.dart +++ b/lib/pages/project/views/project_view.dart @@ -1,16 +1,72 @@ import 'package:flutter/material.dart'; import 'package:flutter_wanandroid/pages/project/controllers/project_controller.dart'; +import 'package:get/get.dart'; +import 'package:get/get_core/src/get_main.dart'; import 'package:get/get_state_manager/src/simple/get_view.dart'; +import 'package:getwidget/colors/gf_color.dart'; +import 'package:getwidget/components/appbar/gf_appbar.dart'; +import 'package:getwidget/components/tabs/gf_segment_tabs.dart'; +import 'package:getwidget/components/tabs/gf_tabbar_view.dart'; + +import '../../../provider/refresh/common_state_page.dart'; +import '../../../widgets/keep_alive_wrapper.dart'; +import '../project_tree_children/project_tree_children_page.dart'; /// 日期:2022-05-15 /// 描述:主页-主屏页面-Body-project-页面 /// 说明: -class ProjectView extends GetView{ +class ProjectView extends GetView { const ProjectView({Key? key}) : super(key: key); @override Widget build(BuildContext context) { - //return Scaffold(appBar: AppBar(title: Text('Project'),),); - return const Center(child: Text('Project')); + controller.getProjectTreeList(); + return CommonStatePage( + controller: controller, + onPressed: () => controller.getProjectTreeList(), + child: Obx(() { + return Scaffold( + appBar: _buildAppBar(), + body: sliverPageView(context, controller), + ); + }), + ); + } + + ///项目标题栏 + AppBar? _buildAppBar() { + return controller.projectTreeList.isNotEmpty + ? AppBar( + title: const Text('项目'), + actions: const [Icon(Icons.search)], + bottom: TabBar( + tabs: controller.projectTreeList.map((f) { + return Text(f.name); + }).toList(), + controller: controller.tabController, + indicatorColor: Colors.red, + indicatorSize: TabBarIndicatorSize.tab, + isScrollable: true, + labelColor: Colors.red, + unselectedLabelColor: Colors.black, + indicatorWeight: 5.0), + ) + : null; + } + + ///导航条下面的内容 + Widget? sliverPageView(BuildContext context, ProjectController controller) { + if (controller.projectTreeList.isNotEmpty) { + var pageViewList = controller.projectTreeList + .map((element) => KeepAliveWrapper( + child: ProjectTreeChildrenPage(id: element.id), + )) + .toList(); + return TabBarView( + controller: controller.tabController, + children: pageViewList, + ); + } + return null; } -} \ No newline at end of file +} diff --git a/lib/provider/request_api.dart b/lib/provider/request_api.dart index f5be74a..e4c8d80 100644 --- a/lib/provider/request_api.dart +++ b/lib/provider/request_api.dart @@ -90,7 +90,7 @@ abstract class RequestAPI { /// 参数:无 ///******************************************************************/ - static const String projectList = 'project/tree/json'; + static const String projectTreeList = '/project/tree/json'; /// **********************4.2 项目列表数据****************************** /// 示例:https://www.wanandroid.com/project/list/1/json?cid=294 @@ -100,7 +100,7 @@ abstract class RequestAPI { /// - 页码:拼接在链接中,从1开始 ///******************************************************************/ - static const String projectArticleList = 'project/list/index/json'; + static const String projectArticleList = '/project/list/%s/json?cid=%s'; ///5- 登陆与注册 diff --git a/lib/res/app_theme.dart b/lib/res/app_theme.dart index 5aa1fe1..a48aa81 100644 --- a/lib/res/app_theme.dart +++ b/lib/res/app_theme.dart @@ -85,7 +85,7 @@ extension ThemeExtension on BuildContext { //WrapChip背景填充色 Color? get colorItemBackground { - return Get.isDarkMode ? Colors.black12.withOpacity(0.2) : Colors.white.withOpacity(0.2); + return Get.isDarkMode ? Colors.black12.withOpacity(0.3) : Colors.white.withOpacity(0.8); } //WrapChip背景填充色 diff --git a/lib/routes/app_pages.dart b/lib/routes/app_pages.dart index ae1c989..3f705e2 100644 --- a/lib/routes/app_pages.dart +++ b/lib/routes/app_pages.dart @@ -4,6 +4,7 @@ import 'package:flutter_wanandroid/pages/coin_list/bindings/coin_list_binding.da import 'package:flutter_wanandroid/pages/coin_list/views/coin_list_view.dart'; import 'package:flutter_wanandroid/pages/coin_rank/bindings/coin_rank_binding.dart'; import 'package:flutter_wanandroid/pages/coin_rank/views/coin_rank_view.dart'; +import 'package:flutter_wanandroid/pages/home/bindings/home_binding.dart'; import 'package:flutter_wanandroid/pages/login_register/bindings/login_register_binding.dart'; import 'package:flutter_wanandroid/pages/login_register/views/login_register_view.dart'; import 'package:flutter_wanandroid/pages/main/bindings/main_binding.dart'; @@ -24,6 +25,7 @@ import '../pages/language/bindings/language_binding.dart'; import '../pages/language/views/language_view.dart'; import '../pages/message/bindings/message_binding.dart'; import '../pages/not_found/not_found_view.dart'; +import '../pages/project/bindings/project_binding.dart'; import '../pages/theme/bindings/theme_binding.dart'; import '../pages/theme/views/theme_view.dart'; @@ -34,17 +36,24 @@ import '../pages/theme/views/theme_view.dart'; class AppPages { static String init = Routes.main.nameToRoute(); - static final unknownRoute = - GetPage(name: Routes.notFound.nameToRoute(), page: () => const NotFound()); + static final unknownRoute = GetPage( + name: Routes.notFound.nameToRoute(), page: () => const NotFound()); static final routes = [ ///主界面 GetPage( - name: Routes.main.nameToRoute(), - page: () => const MainView(), - title: Routes.main, - bindings: [MainBinding(),NavigationBinding(),MessageBinding()], - /// binding: MainBinding() + name: Routes.main.nameToRoute(), + page: () => const MainView(), + title: Routes.main, + bindings: [ + MainBinding(), + //HomeBinding(), + NavigationBinding(), + MessageBinding(), + ProjectBinding() + ], + + /// binding: MainBinding() ), ///设置页面 @@ -89,17 +98,15 @@ class AppPages { title: Routes.coinRank, binding: CoinRankBinging()), GetPage( - name: Routes.articleDetail.nameToRoute(), - page: () => const ArticleDetailPage(), - title: Routes.articleDetail, - binding: ArticleDetailBinding() - ), + name: Routes.articleDetail.nameToRoute(), + page: () => const ArticleDetailPage(), + title: Routes.articleDetail, + binding: ArticleDetailBinding()), GetPage( name: Routes.messageWebView.nameToRoute(), page: () => const MessageDetailWebPage(), title: Routes.messageWebView, - binding: MessageDetailWebBinding() - ), + binding: MessageDetailWebBinding()), ///金币 // GetPage( diff --git a/lib/widgets/message_list_item_widget.dart b/lib/widgets/message_list_item_widget.dart index 481dd34..6e28609 100644 --- a/lib/widgets/message_list_item_widget.dart +++ b/lib/widgets/message_list_item_widget.dart @@ -69,7 +69,7 @@ class MessageListItemWidget extends GetView { } Widget leftContainer(BuildContext context) { - return Text(dataList[index].message); + return SizedBox(width: Get.width,child: Text(dataList[index].message)); } // /// 作者、时间 @@ -82,7 +82,8 @@ class MessageListItemWidget extends GetView { /// tags Widget chapterTag(BuildContext context) { return Container( - margin: const EdgeInsets.only(right: 10), + width: Get.width, + margin: const EdgeInsets.only(right: 0), padding: const EdgeInsets.symmetric( horizontal: 3, vertical: 2, diff --git a/lib/widgets/search_list_item_widget.dart b/lib/widgets/search_list_item_widget.dart index 4086db9..bacf55d 100644 --- a/lib/widgets/search_list_item_widget.dart +++ b/lib/widgets/search_list_item_widget.dart @@ -53,8 +53,7 @@ class SearchListItemWidget extends GetView { color: context.colorItemBackground, padding: const EdgeInsets.all(5), margin: const EdgeInsets.all(5), - colorFilter: - ColorFilter.mode(Colors.red.withOpacity(0.67), BlendMode.darken), + colorFilter:ColorFilter.mode(Colors.red.withOpacity(0.2), BlendMode.darken), boxFit: BoxFit.cover, content: Column( children: [