From 52d775dd7836747dd3fcd3be001b989ff506b539 Mon Sep 17 00:00:00 2001 From: Jason Date: Mon, 31 Oct 2022 10:42:17 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A1=B5=E9=9D=A2=E7=B2=BE=E7=AE=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/services/tim/friend_service.dart | 6 + lib/views/contact/index/index_page.dart | 13 +-- lib/views/moments/index/index_page.dart | 20 ++-- lib/views/user/index/index_page.dart | 109 ++++++++---------- .../user/index/widgets/user_top_bar.dart | 11 +- 5 files changed, 75 insertions(+), 84 deletions(-) diff --git a/lib/services/tim/friend_service.dart b/lib/services/tim/friend_service.dart index 5a8dde4..7b3db72 100644 --- a/lib/services/tim/friend_service.dart +++ b/lib/services/tim/friend_service.dart @@ -53,6 +53,12 @@ class TimFriendService extends GetxService { ), ]; + @override + void onInit() async { + super.onInit(); + await fetchList(); + } + Future fetchList() async { var result = await friendshipManager.getFriendList(); if (result.code == 0) { diff --git a/lib/views/contact/index/index_page.dart b/lib/views/contact/index/index_page.dart index 30875cd..ae6b8be 100644 --- a/lib/views/contact/index/index_page.dart +++ b/lib/views/contact/index/index_page.dart @@ -9,20 +9,9 @@ import 'package:chat/widgets/custom_avatar.dart'; import 'package:flutter/material.dart'; import 'package:get/get.dart'; -class ContactPage extends StatefulWidget { +class ContactPage extends StatelessWidget { const ContactPage({Key? key}) : super(key: key); - @override - State createState() => _ContactPageState(); -} - -class _ContactPageState extends State { - @override - void initState() { - super.initState(); - TimFriendService.to.fetchList(); - } - @override Widget build(BuildContext context) { return Scaffold( diff --git a/lib/views/moments/index/index_page.dart b/lib/views/moments/index/index_page.dart index 40dc374..e4cd41a 100644 --- a/lib/views/moments/index/index_page.dart +++ b/lib/views/moments/index/index_page.dart @@ -8,33 +8,33 @@ import 'package:flutter/material.dart'; import 'package:flutter_easyrefresh/easy_refresh.dart'; import 'package:get/get.dart'; -class MomentsPage extends StatelessWidget { +class MomentsPage extends GetView { const MomentsPage({Key? key}) : super(key: key); + @override Widget build(BuildContext context) { - final ctrl = MomentController.to; return Scaffold( body: Padding( padding: EdgeInsets.only( bottom: MediaQuery.of(context).viewPadding.bottom, ), child: EasyRefresh.custom( - scrollController: ctrl.scrollController, - controller: ctrl.refreshController, + scrollController: controller.scrollController, + controller: controller.refreshController, header: LinkHeader( - ctrl.headerNotifier, + controller.headerNotifier, extent: 70.0, triggerDistance: 70.0, completeDuration: const Duration(milliseconds: 500), ), footer: CustomEasyRefresh.footer, - onRefresh: () => ctrl.refreshList(), - onLoad: () => ctrl.loadMoreList(), + onRefresh: () => controller.refreshList(), + onLoad: () => controller.loadMoreList(), slivers: [ MomentHeader( - linkNotifier: ctrl.headerNotifier, + linkNotifier: controller.headerNotifier, onTitleDoubleTap: () { - ctrl.scrollController.animateTo( + controller.scrollController.animateTo( 0, duration: const Duration(milliseconds: 300), curve: Curves.fastOutSlowIn, @@ -42,7 +42,7 @@ class MomentsPage extends StatelessWidget { }, ), Obx(() { - final momentList = ctrl.momentData.value?.data ?? []; + final momentList = controller.momentData.value?.data ?? []; if (momentList.isEmpty) { return SliverFillRemaining( child: CustomEasyRefresh.empty(text: '暂无动态内容'), diff --git a/lib/views/user/index/index_page.dart b/lib/views/user/index/index_page.dart index 797ca7e..e7394fd 100644 --- a/lib/views/user/index/index_page.dart +++ b/lib/views/user/index/index_page.dart @@ -5,68 +5,61 @@ import 'package:chat/views/user/index/widgets/user_top_bar.dart'; import 'package:flutter/material.dart'; import 'package:get/get.dart'; -class UserPage extends StatefulWidget { +class UserPage extends StatelessWidget { const UserPage({Key? key}) : super(key: key); - @override - _UserPageState createState() => _UserPageState(); -} - -class _UserPageState extends State { @override Widget build(BuildContext context) { - return SafeArea( - child: Scaffold( - body: Column( - children: [ - const UserTopBar(), - const Divider( - height: 0, - color: AppColors.border, - ), - const SizedBox(height: 8), - const Divider( - height: 0, - color: AppColors.border, - ), - ActionItem( - '服务', - onTap: () { - Get.toNamed(UserRoutes.serve); - }, - ), - const Divider( - height: 0, - color: AppColors.border, - ), - const SizedBox(height: 8), - const Divider( - height: 0, - color: AppColors.border, - ), - ActionItem( - '分享邀请', - onTap: () { - Get.toNamed(UserRoutes.share); - }, - ), - const Divider( - height: 0, - color: AppColors.border, - indent: 16, - ), - ActionItem( - '设置', - onTap: () { - Get.toNamed(UserRoutes.setting); - }, - ), - const Divider( - height: 0, - color: AppColors.border, - ), - ], - ), + return Scaffold( + body: Column( + children: [ + const UserTopBar(), + const Divider( + height: 0, + color: AppColors.border, + ), + const SizedBox(height: 8), + const Divider( + height: 0, + color: AppColors.border, + ), + ActionItem( + '服务', + onTap: () { + Get.toNamed(UserRoutes.serve); + }, + ), + const Divider( + height: 0, + color: AppColors.border, + ), + const SizedBox(height: 8), + const Divider( + height: 0, + color: AppColors.border, + ), + ActionItem( + '分享邀请', + onTap: () { + Get.toNamed(UserRoutes.share); + }, + ), + const Divider( + height: 0, + color: AppColors.border, + indent: 16, + ), + ActionItem( + '设置', + onTap: () { + Get.toNamed(UserRoutes.setting); + }, + ), + const Divider( + height: 0, + color: AppColors.border, + ), + ], ), ); } diff --git a/lib/views/user/index/widgets/user_top_bar.dart b/lib/views/user/index/widgets/user_top_bar.dart index 04de801..844045c 100644 --- a/lib/views/user/index/widgets/user_top_bar.dart +++ b/lib/views/user/index/widgets/user_top_bar.dart @@ -11,17 +11,20 @@ import 'package:get/get.dart'; class UserTopBar extends StatelessWidget { const UserTopBar({Key? key}) : super(key: key); + final double paddingTop = 96; + final double avatarHeight = 64; + @override Widget build(BuildContext context) { return Container( color: AppColors.white, - padding: const EdgeInsets.only( + padding: EdgeInsets.only( left: 24, - top: 48, + top: paddingTop, right: 24, bottom: 24, ), - height: 64 + 48 + 24, + // height: avatarHeight + paddingTop + 24, child: GetX(builder: (_) { return Row( crossAxisAlignment: CrossAxisAlignment.end, @@ -32,7 +35,7 @@ class UserTopBar extends StatelessWidget { }, child: CustomAvatar( _.userInfo.value.avatar, - size: 64, + size: avatarHeight, ), ), const SizedBox(width: 16),