From aa30a11af2d4abcddaf7e86fcddd4f511fee3002 Mon Sep 17 00:00:00 2001 From: Jason Date: Thu, 27 Oct 2022 10:43:44 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8F=91=E7=8E=B0=E9=A1=B5=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/controllers/moment_controller.dart | 3 ++- lib/models/moment/moment_model.dart | 13 +++++++------ lib/providers/moment_provider.dart | 10 ++++++---- lib/views/moments/index/widgets/moment_header.dart | 11 ++++++----- lib/views/public/app_page.dart | 13 +++++++------ lib/views/user/info/index_page.dart | 5 +++-- 6 files changed, 31 insertions(+), 24 deletions(-) diff --git a/lib/controllers/moment_controller.dart b/lib/controllers/moment_controller.dart index 6a799ce..e1ff87e 100644 --- a/lib/controllers/moment_controller.dart +++ b/lib/controllers/moment_controller.dart @@ -52,7 +52,8 @@ class MomentController extends GetxController { Future loadMoreList() async { final res = await MomentProvider.fetchMomentList( - momentData.value?.data?.last.createdAt); + momentData.value?.data?.last.createdAt, + ); if (res != null) { final data = res.data ?? []; if (data.isEmpty || res.page?.hasMore == true) { diff --git a/lib/models/moment/moment_model.dart b/lib/models/moment/moment_model.dart index b38438f..106d6d9 100644 --- a/lib/models/moment/moment_model.dart +++ b/lib/models/moment/moment_model.dart @@ -10,10 +10,10 @@ class MomentModel { List? data; PageModel? page; - factory MomentModel.fromMap(Map json) => MomentModel( + factory MomentModel.fromJson(Map json) => MomentModel( data: List.from( json['data'].map( - (x) => MomentItemModel.fromMap(x), + (x) => MomentItemModel.fromJson(x), ), ), page: PageModel.fromJson(json['page']), @@ -47,7 +47,8 @@ class MomentItemModel { String? createdAt; String? time; - factory MomentItemModel.fromMap(Map json) => MomentItemModel( + factory MomentItemModel.fromJson(Map json) => + MomentItemModel( dynamicId: json['dynamic_id'], user: UserInfoModel.fromJson(json['user']), description: json['description'], @@ -57,8 +58,8 @@ class MomentItemModel { likerCount: json['liker_count'], liker: List.from( json['liker'].map((x) => UserInfoModel.fromJson(x))), - comments: - List.from(json['comments'].map((x) => Comment.fromMap(x))), + comments: List.from( + json['comments'].map((x) => Comment.fromJson(x))), createdAt: json['created_at'], time: json['time'], ); @@ -79,7 +80,7 @@ class Comment { String? content; bool isMe; - factory Comment.fromMap(Map json) => Comment( + factory Comment.fromJson(Map json) => Comment( id: json['comment_id'], parent: json['parent'] == null ? null diff --git a/lib/providers/moment_provider.dart b/lib/providers/moment_provider.dart index 814cf4c..28eeaca 100644 --- a/lib/providers/moment_provider.dart +++ b/lib/providers/moment_provider.dart @@ -9,10 +9,12 @@ class MomentProvider { static Future fetchMomentList([String? createAt]) async { try { final result = await Http.get( - 'user/dynamics', - params: {'created_at': createAt}, + 'dynamics', + params: { + 'created_at': createAt, + }, ); - return MomentModel.fromMap(result); + return MomentModel.fromJson(result); } catch (e) { UiTools.toast('获取发现列表失败'); } @@ -60,7 +62,7 @@ class MomentProvider { 'parent_id': parentId, }, ); - return Comment.fromMap(result); + return Comment.fromJson(result); } catch (e) { UiTools.toast('评论失败'); } diff --git a/lib/views/moments/index/widgets/moment_header.dart b/lib/views/moments/index/widgets/moment_header.dart index 9cba93d..f16a30a 100644 --- a/lib/views/moments/index/widgets/moment_header.dart +++ b/lib/views/moments/index/widgets/moment_header.dart @@ -1,5 +1,6 @@ import 'package:chat/configs/app_colors.dart'; import 'package:chat/routes/moments_routes.dart'; +import 'package:chat/services/auth_service.dart'; import 'package:chat/services/tabbar_service.dart'; import 'package:chat/widgets/custom_avatar.dart'; import 'package:flutter/material.dart'; @@ -79,7 +80,7 @@ class _HeaderBackground extends StatelessWidget { bottom: 32, child: GestureDetector( child: Image.asset( - 'assets/backgrounds/moment_3.jpg', + 'assets/images/login_bg.png', fit: BoxFit.cover, ), ), @@ -94,9 +95,9 @@ class _HeaderBackground extends StatelessWidget { SizedBox( height: 52, child: Obx(() { - return const Text( - "UserController.to.userInfo.value?.nickname ?? ''", - style: TextStyle( + return Text( + AuthService.to.userInfo.value.nickname ?? '', + style: const TextStyle( color: AppColors.white, fontWeight: FontWeight.bold, fontSize: 16, @@ -109,7 +110,7 @@ class _HeaderBackground extends StatelessWidget { return GestureDetector( onTap: () => TabbarService.to.index = 4, child: CustomAvatar( - '', + AuthService.to.userInfo.value.avatar, size: 64, ), ); diff --git a/lib/views/public/app_page.dart b/lib/views/public/app_page.dart index 75ef873..e380632 100644 --- a/lib/views/public/app_page.dart +++ b/lib/views/public/app_page.dart @@ -2,6 +2,7 @@ import 'package:chat/configs/app_colors.dart'; import 'package:chat/services/tabbar_service.dart'; import 'package:chat/views/contact/index/index_page.dart'; import 'package:chat/views/home/index_page.dart'; +import 'package:chat/views/moments/index/index_page.dart'; import 'package:chat/views/user/index/index_page.dart'; import 'package:flutter/material.dart'; import 'package:get/get.dart'; @@ -13,7 +14,7 @@ class AppPage extends StatelessWidget { final List _tabBarPageList = [ IndexedStackChild(child: const HomePage()), IndexedStackChild(child: const ContactPage()), - // IndexedStackChild(child: const MomentsPage()), + IndexedStackChild(child: const MomentsPage()), IndexedStackChild(child: const UserPage()), ]; @@ -28,11 +29,11 @@ class AppPage extends StatelessWidget { 'active_icon': Icons.contact_page, 'label': '通讯录', }, - // { - // 'icon': Icons.explore_outlined, - // 'active_icon': Icons.explore, - // 'label': '发现', - // }, + { + 'icon': Icons.explore_outlined, + 'active_icon': Icons.explore, + 'label': '发现', + }, { 'icon': Icons.person_outline, 'active_icon': Icons.person, diff --git a/lib/views/user/info/index_page.dart b/lib/views/user/info/index_page.dart index 742eaeb..0ea26d4 100644 --- a/lib/views/user/info/index_page.dart +++ b/lib/views/user/info/index_page.dart @@ -34,6 +34,7 @@ class _UserInfoPageState extends State { Get.context!, pickerConfig: const AssetPickerConfig( maxAssets: 1, + textDelegate: AssetPickerTextDelegate(), requestType: RequestType.image, ), ); @@ -77,12 +78,12 @@ class _UserInfoPageState extends State { sourcePath: imagePath, maxHeight: 128, maxWidth: 128, - compressQuality: 70, + compressQuality: 100, aspectRatio: const CropAspectRatio( ratioX: 1, ratioY: 1, ), - compressFormat: ImageCompressFormat.png, + compressFormat: ImageCompressFormat.jpg, uiSettings: [ IOSUiSettings( title: '头像剪裁',