diff --git a/android/app/build.gradle b/android/app/build.gradle index 01c6690..23ce002 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -48,7 +48,7 @@ android { defaultConfig { applicationId "site.zhchain.chat" // minSdkVersion flutter.minSdkVersion - minSdkVersion 21 + minSdkVersion 28 targetSdkVersion flutter.targetSdkVersion versionCode flutterVersionCode.toInteger() versionName flutterVersionName diff --git a/assets/images/default_avatar.png b/assets/images/default_avatar.png new file mode 100644 index 0000000..4511838 Binary files /dev/null and b/assets/images/default_avatar.png differ diff --git a/lib/controllers/private_controller.dart b/lib/controllers/private_controller.dart index 1b1c0f9..4a8806c 100644 --- a/lib/controllers/private_controller.dart +++ b/lib/controllers/private_controller.dart @@ -30,7 +30,7 @@ class PrivateController extends GetxController { currentFriend.value.isFriend = info.relation == UserRelationEnum.V2TIM_FRIEND_RELATION_TYPE_BOTH_WAY; - currentFriend.value.friendRemark = info.friendInfo!.friendRemark!; + currentFriend.value.friendRemark = info.friendInfo!.friendRemark ?? ''; currentFriend.value.userProfile = info.friendInfo!.userProfile; /// 通过自定义Staffer字段,判断是否是客服,属于哪个店铺 diff --git a/lib/routes/contact_routes.dart b/lib/routes/contact_routes.dart index a17b6eb..fb2dbb5 100644 --- a/lib/routes/contact_routes.dart +++ b/lib/routes/contact_routes.dart @@ -1,4 +1,11 @@ import 'package:chat/middleware/auth_middleware.dart'; +import 'package:chat/views/contact/firend/profile/index_page.dart'; +import 'package:chat/views/contact/firend/profile/more_page.dart'; +import 'package:chat/views/contact/firend/recommend/friend_page.dart'; +import 'package:chat/views/contact/firend/recommend/group_page.dart'; +import 'package:chat/views/contact/firend/recommend/index_page.dart'; +import 'package:chat/views/contact/firend/remark/index_page.dart'; +import 'package:chat/views/contact/firend/search/index_page.dart'; import 'package:chat/views/contact/group/create/index_page.dart'; import 'package:chat/views/contact/group/index_page.dart'; import 'package:chat/views/contact/group/manage/index_page.dart'; @@ -13,10 +20,13 @@ abstract class ContactRoutes { static const String friend = '/contact/friend'; static const String friendSearch = '/contact/friend/search'; static const String friendProfile = '/contact/friend/profile'; - static const String friendProfileMore = '/contact/friend/profile'; - static const String friendRemark = '/contact/friend/profile'; + static const String friendProfileMore = '/contact/friend/profile/more'; + static const String friendRemark = '/contact/friend/remark'; static const String friendApply = '/contact/friend/profile'; - static const String friendRecommend = '/contact/friend/profile'; + static const String friendRecommend = '/contact/friend/recommend'; + static const String friendRecommendFriend = + '/contact/friend/recommend/friend'; + static const String friendRecommendGroup = '/contact/friend/recommend/group'; static const String group = '/contact/group'; static const String groupQrCode = '/contact/group/qrCode'; @@ -40,7 +50,35 @@ abstract class ContactRoutes { children: [ GetPage( name: '/search', - page: () => const ContactGroupCreatePage(), + page: () => const ContactFriendSearchPage(), + ), + GetPage( + name: '/profile', + page: () => const ContactFriendProfilePage(), + children: [ + GetPage( + name: '/more', + page: () => const ContactFriendProfileMorePage(), + ), + ], + ), + GetPage( + name: '/remark', + page: () => const ContactFriendRemarkPage(), + ), + GetPage( + name: '/recommend', + page: () => const ContactFriendRecommendPage(), + children: [ + GetPage( + name: '/friend', + page: () => const ContactFriendRecommendFriendPage(), + ), + GetPage( + name: '/group', + page: () => const ContactFriendRecommendGroupPage(), + ), + ], ), ], ), diff --git a/lib/utils/im_tools.dart b/lib/utils/im_tools.dart index 79fe947..13e6754 100644 --- a/lib/utils/im_tools.dart +++ b/lib/utils/im_tools.dart @@ -30,8 +30,9 @@ class ImTools { } static String parseNicknameFromInfo(V2TimFriendInfo infoResult) { - if (infoResult.friendRemark != '') { - return infoResult.friendRemark!; + if (infoResult.friendRemark != null && + infoResult.friendRemark!.isNotEmpty) { + return infoResult.friendRemark ?? ''; } return infoResult.userProfile!.nickName!; diff --git a/lib/views/contact/firend/profile/index_page.dart b/lib/views/contact/firend/profile/index_page.dart index 9890a40..7c08020 100644 --- a/lib/views/contact/firend/profile/index_page.dart +++ b/lib/views/contact/firend/profile/index_page.dart @@ -2,7 +2,6 @@ import 'package:chat/configs/app_colors.dart'; import 'package:chat/controllers/private_controller.dart'; import 'package:chat/routes/contact_routes.dart'; import 'package:chat/routes/conversation_routes.dart'; -import 'package:chat/routes/moments_routes.dart'; import 'package:chat/services/tim/conversation_service.dart'; import 'package:chat/utils/im_tools.dart'; import 'package:chat/views/home/widgets/action_button.dart'; @@ -11,8 +10,8 @@ import 'package:chat/widgets/custom_avatar.dart'; import 'package:flutter/material.dart'; import 'package:get/get.dart'; -class ImFriendProfilePage extends StatelessWidget { - const ImFriendProfilePage({Key? key}) : super(key: key); +class ContactFriendProfilePage extends StatelessWidget { + const ContactFriendProfilePage({Key? key}) : super(key: key); @override Widget build(BuildContext context) { @@ -76,18 +75,18 @@ class ImFriendProfilePage extends StatelessWidget { ); }, ), - const SizedBox(height: 8), - ActionItem( - '他的动态', - onTap: () { - Get.toNamed( - MomentsRoutes.user, - arguments: { - 'userId': _.currentFriend.value.userID, - }, - ); - }, - ), + // const SizedBox(height: 8), + // ActionItem( + // '他的动态', + // onTap: () { + // Get.toNamed( + // MomentsRoutes.user, + // arguments: { + // 'userId': _.currentFriend.value.userID, + // }, + // ); + // }, + // ), const SizedBox(height: 8), Visibility( visible: !_.currentFriend.value.isFriend, diff --git a/lib/views/contact/firend/profile/more_page.dart b/lib/views/contact/firend/profile/more_page.dart index d63d5dc..72ac7a2 100644 --- a/lib/views/contact/firend/profile/more_page.dart +++ b/lib/views/contact/firend/profile/more_page.dart @@ -1,6 +1,7 @@ import 'package:adaptive_dialog/adaptive_dialog.dart'; import 'package:chat/controllers/private_controller.dart'; import 'package:chat/routes/contact_routes.dart'; +import 'package:chat/services/tim/block_service.dart'; import 'package:chat/services/tim/friend_service.dart'; import 'package:chat/utils/ui_tools.dart'; import 'package:chat/views/home/widgets/action_button.dart'; @@ -8,8 +9,8 @@ import 'package:chat/views/home/widgets/action_item.dart'; import 'package:flutter/material.dart'; import 'package:get/get.dart'; -class ImFriendProfileMorePage extends StatelessWidget { - const ImFriendProfileMorePage({Key? key}) : super(key: key); +class ContactFriendProfileMorePage extends StatelessWidget { + const ContactFriendProfileMorePage({Key? key}) : super(key: key); @override Widget build(BuildContext context) { diff --git a/lib/views/contact/firend/recommend/friends_page.dart b/lib/views/contact/firend/recommend/friend_page.dart similarity index 95% rename from lib/views/contact/firend/recommend/friends_page.dart rename to lib/views/contact/firend/recommend/friend_page.dart index 1d6c0f8..ae8ac42 100644 --- a/lib/views/contact/firend/recommend/friends_page.dart +++ b/lib/views/contact/firend/recommend/friend_page.dart @@ -5,6 +5,7 @@ import 'package:chat/controllers/private_controller.dart'; import 'package:chat/models/im/contact_info_model.dart'; import 'package:chat/models/im/name_card_model.dart'; import 'package:chat/models/im/private_conversation_model.dart'; +import 'package:chat/routes/contact_routes.dart'; import 'package:chat/services/tim/conversation_service.dart'; import 'package:chat/services/tim/friend_service.dart'; import 'package:chat/utils/im_tools.dart'; @@ -14,8 +15,8 @@ import 'package:get/get.dart'; import 'package:tencent_im_sdk_plugin/models/v2_tim_conversation.dart'; -class ImFriendRecommendFriendsPage extends StatelessWidget { - const ImFriendRecommendFriendsPage({Key? key}) : super(key: key); +class ContactFriendRecommendFriendPage extends StatelessWidget { + const ContactFriendRecommendFriendPage({Key? key}) : super(key: key); @override Widget build(BuildContext context) { @@ -65,7 +66,7 @@ class ImFriendRecommendFriendsPage extends StatelessWidget { InkWell( onTap: () { FocusScope.of(Get.context!).requestFocus(FocusNode()); - // Get.offNamed(ImRoutes.friendRecommendGroups); + Get.offNamed(ContactRoutes.friendRecommendGroup); }, child: Container( decoration: const BoxDecoration( diff --git a/lib/views/contact/firend/recommend/groups_page.dart b/lib/views/contact/firend/recommend/group_page.dart similarity index 97% rename from lib/views/contact/firend/recommend/groups_page.dart rename to lib/views/contact/firend/recommend/group_page.dart index 64656b9..268dca1 100644 --- a/lib/views/contact/firend/recommend/groups_page.dart +++ b/lib/views/contact/firend/recommend/group_page.dart @@ -11,8 +11,8 @@ import 'package:get/get.dart'; import 'package:tencent_im_sdk_plugin/models/v2_tim_conversation.dart'; import 'package:tencent_im_sdk_plugin/models/v2_tim_group_info.dart'; -class ImFriendRecommendGroupsPage extends StatelessWidget { - const ImFriendRecommendGroupsPage({Key? key}) : super(key: key); +class ContactFriendRecommendGroupPage extends StatelessWidget { + const ContactFriendRecommendGroupPage({Key? key}) : super(key: key); @override Widget build(BuildContext context) { diff --git a/lib/views/contact/firend/recommend/index_page.dart b/lib/views/contact/firend/recommend/index_page.dart index 6759a7b..1484e57 100644 --- a/lib/views/contact/firend/recommend/index_page.dart +++ b/lib/views/contact/firend/recommend/index_page.dart @@ -4,6 +4,7 @@ import 'package:chat/configs/app_size.dart'; import 'package:chat/controllers/private_controller.dart'; import 'package:chat/models/im/name_card_model.dart'; import 'package:chat/models/im/private_conversation_model.dart'; +import 'package:chat/routes/contact_routes.dart'; import 'package:chat/services/tim/conversation_service.dart'; import 'package:chat/views/home/widgets/group_avatar.dart'; import 'package:chat/widgets/custom_avatar.dart'; @@ -12,8 +13,8 @@ import 'package:flutter/material.dart'; import 'package:get/get.dart'; import 'package:tencent_im_sdk_plugin/enum/conversation_type.dart'; -class ImFriendRecommendPage extends StatelessWidget { - const ImFriendRecommendPage({Key? key}) : super(key: key); +class ContactFriendRecommendPage extends StatelessWidget { + const ContactFriendRecommendPage({Key? key}) : super(key: key); @override Widget build(BuildContext context) { @@ -68,7 +69,7 @@ class ImFriendRecommendPage extends StatelessWidget { InkWell( onTap: () { FocusScope.of(Get.context!).requestFocus(FocusNode()); - // Get.offNamed(ImRoutes.friendRecommendFriends); + Get.offNamed(ContactRoutes.friendRecommendFriend); }, child: Container( decoration: const BoxDecoration( diff --git a/lib/views/contact/firend/remark/index_page.dart b/lib/views/contact/firend/remark/index_page.dart index dc5ee8f..9223920 100644 --- a/lib/views/contact/firend/remark/index_page.dart +++ b/lib/views/contact/firend/remark/index_page.dart @@ -3,14 +3,15 @@ import 'package:chat/controllers/private_controller.dart'; import 'package:flutter/material.dart'; import 'package:get/get.dart'; -class ImFriendRemarkPage extends StatefulWidget { - const ImFriendRemarkPage({Key? key}) : super(key: key); +class ContactFriendRemarkPage extends StatefulWidget { + const ContactFriendRemarkPage({Key? key}) : super(key: key); @override - State createState() => _ImFriendRemarkPageState(); + State createState() => + _ContactFriendRemarkPageState(); } -class _ImFriendRemarkPageState extends State { +class _ContactFriendRemarkPageState extends State { final TextEditingController _controller = TextEditingController(); @override diff --git a/lib/views/contact/firend/request/apply_page.dart b/lib/views/contact/firend/request/apply_page.dart index d4ad553..9c15647 100644 --- a/lib/views/contact/firend/request/apply_page.dart +++ b/lib/views/contact/firend/request/apply_page.dart @@ -5,15 +5,16 @@ import 'package:chat/widgets/custom_primary_button.dart'; import 'package:flutter/material.dart'; import 'package:get/get.dart'; -class ImFriendRequestApplyPage extends StatefulWidget { - const ImFriendRequestApplyPage({Key? key}) : super(key: key); +class ContactFriendRequestApplyPage extends StatefulWidget { + const ContactFriendRequestApplyPage({Key? key}) : super(key: key); @override - State createState() => - _ImFriendRequestApplyPageState(); + State createState() => + _ContactFriendRequestApplyPageState(); } -class _ImFriendRequestApplyPageState extends State { +class _ContactFriendRequestApplyPageState + extends State { late final String userID; String _remark = ''; String _wording = ''; diff --git a/lib/views/contact/firend/request/index_page.dart b/lib/views/contact/firend/request/index_page.dart index 31cf6ba..d9e9586 100644 --- a/lib/views/contact/firend/request/index_page.dart +++ b/lib/views/contact/firend/request/index_page.dart @@ -11,14 +11,14 @@ import 'package:tencent_im_sdk_plugin/enum/friend_type.dart'; import 'package:tencent_im_sdk_plugin/models/v2_tim_friend_application.dart'; import 'package:tencent_im_sdk_plugin/models/v2_tim_friend_check_result.dart'; -class ImFriendRequestPage extends StatefulWidget { - const ImFriendRequestPage({Key? key}) : super(key: key); +class ContactFriendRequestPage extends StatefulWidget { + const ContactFriendRequestPage({Key? key}) : super(key: key); @override - State createState() => _ImFriendRequestState(); + State createState() => _ImFriendRequestState(); } -class _ImFriendRequestState extends State { +class _ImFriendRequestState extends State { List? searchList; @override diff --git a/lib/views/contact/firend/search/index_page.dart b/lib/views/contact/firend/search/index_page.dart index e3a32c6..7c18a11 100644 --- a/lib/views/contact/firend/search/index_page.dart +++ b/lib/views/contact/firend/search/index_page.dart @@ -1,14 +1,15 @@ import 'package:chat/configs/app_colors.dart'; import 'package:flutter/material.dart'; -class ImFriendSearchPage extends StatefulWidget { - const ImFriendSearchPage({Key? key}) : super(key: key); +class ContactFriendSearchPage extends StatefulWidget { + const ContactFriendSearchPage({Key? key}) : super(key: key); @override - State createState() => _ImFriendSearchPageState(); + State createState() => + _ContactFriendSearchPageState(); } -class _ImFriendSearchPageState extends State { +class _ContactFriendSearchPageState extends State { @override Widget build(BuildContext context) { return Scaffold( diff --git a/lib/views/contact/group/create/index_page.dart b/lib/views/contact/group/create/index_page.dart index 3e1bdaa..5d5b9f7 100644 --- a/lib/views/contact/group/create/index_page.dart +++ b/lib/views/contact/group/create/index_page.dart @@ -1,15 +1,174 @@ +import 'package:chat/configs/app_colors.dart'; +import 'package:chat/routes/conversation_routes.dart'; +import 'package:chat/services/tim/conversation_service.dart'; +import 'package:chat/services/tim/friend_service.dart'; +import 'package:chat/services/tim/group_service.dart'; +import 'package:chat/views/home/widgets/friend_selector.dart'; +import 'package:chat/widgets/custom_avatar.dart'; import 'package:flutter/material.dart'; +import 'package:get/get.dart'; +import 'package:tencent_im_sdk_plugin/enum/group_type.dart'; +import 'package:tencent_im_sdk_plugin/models/v2_tim_friend_info.dart'; class ContactGroupCreatePage extends StatefulWidget { const ContactGroupCreatePage({Key? key}) : super(key: key); @override - _ContactGroupCreatePageState createState() => _ContactGroupCreatePageState(); + State createState() => _ContactGroupCreatePageState(); } class _ContactGroupCreatePageState extends State { + final ScrollController _scrollController = ScrollController(); + + /// 选中的好友列表 + List _selectList = + List.empty(growable: true); + + @override + void initState() { + super.initState(); + TimFriendService.to.fetchList(); + } + @override Widget build(BuildContext context) { - return Container(); + return Scaffold( + appBar: AppBar( + title: const Text( + '发起群聊', + ), + ), + body: SafeArea( + top: false, + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Container( + color: Colors.white, + height: 58, + padding: const EdgeInsets.all( + 4, + ), + child: ListView.builder( + controller: _scrollController, + scrollDirection: Axis.horizontal, + itemCount: _selectList.length, + itemBuilder: (context, index) { + return Container( + width: 50, + height: 50, + padding: const EdgeInsets.all(4), + child: GestureDetector( + onTap: () { + setState(() { + _selectList.removeAt(index); + }); + }, + child: CustomAvatar( + _selectList[index].userProfile!.faceUrl, + size: 42, + ), + ), + ); + }, + ), + ), + const Divider(height: 0), + Container( + color: AppColors.unactive.withOpacity(0.1), + alignment: Alignment.centerLeft, + padding: const EdgeInsets.only( + left: 16, + ), + height: 40, + width: double.infinity, + child: const Text( + '选择群成员', + style: TextStyle( + fontSize: 14, + ), + ), + ), + Expanded( + child: FriendSelector( + onChanged: onChanged, + ), + ), + Container( + padding: const EdgeInsets.only( + right: 16, + left: 16, + top: 4, + ), + decoration: const BoxDecoration( + color: Colors.white, + border: Border( + top: BorderSide( + color: Colors.black12, + width: 0.4, + ), + ), + ), + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Text( + '已选 ${_selectList.length}', + style: const TextStyle( + color: Colors.grey, + ), + ), + ElevatedButton( + onPressed: + _selectList.isNotEmpty && _selectList.length < 200 + ? _createGroup + : null, + child: const Text( + '完成', + ), + ) + ], + ), + ), + ], + ), + ), + ); + } + + /// 好友选择,添加到选择列表 + Future onChanged(e) async { + setState(() { + _selectList = e; + + Future.delayed(const Duration(milliseconds: 200), () { + _scrollController.animateTo( + _scrollController.position.maxScrollExtent, + duration: const Duration(milliseconds: 200), + curve: Curves.bounceIn, + ); + }); + }); + } + + /// 创建群聊 + Future _createGroup() async { + String groupName = '创建的群聊'; + var result = await TimGroupService.to.create( + groupName, + _selectList, + groupType: GroupType.Public, + ); + + if (result != null) { + Get.offNamed( + ConversationRoutes.index, + arguments: { + 'conversation': await TimConversationService.to.getById( + 'group_' + result, + ), + }, + ); + } } } diff --git a/lib/views/contact/group/create/user_page.dart b/lib/views/contact/group/create/user_page.dart new file mode 100644 index 0000000..2a87f5b --- /dev/null +++ b/lib/views/contact/group/create/user_page.dart @@ -0,0 +1,179 @@ +import 'package:chat/configs/app_colors.dart'; +import 'package:chat/routes/conversation_routes.dart'; +import 'package:chat/services/tim/conversation_service.dart'; +import 'package:chat/services/tim/friend_service.dart'; +import 'package:chat/services/tim/group_service.dart'; +import 'package:chat/views/home/widgets/friend_selector.dart'; +import 'package:chat/widgets/custom_avatar.dart'; +import 'package:flutter/material.dart'; +import 'package:get/get.dart'; +import 'package:tencent_im_sdk_plugin/enum/group_type.dart'; +import 'package:tencent_im_sdk_plugin/models/v2_tim_friend_info.dart'; + +class ContactGroupCreateUserPage extends StatefulWidget { + const ContactGroupCreateUserPage({Key? key}) : super(key: key); + + @override + State createState() => + _ContactGroupCreateUserPageState(); +} + +class _ContactGroupCreateUserPageState + extends State { + final ScrollController _scrollController = ScrollController(); + + late final String groupType; + + /// 选中的好友列表 + List _selectList = + List.empty(growable: true); + + @override + void initState() { + super.initState(); + groupType = Get.arguments['groupType']; + TimFriendService.to.fetchList(); + } + + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: AppBar( + title: const Text( + '发起群聊', + ), + ), + body: SafeArea( + top: false, + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Container( + color: Colors.white, + height: 58, + padding: const EdgeInsets.all( + 4, + ), + child: ListView.builder( + controller: _scrollController, + scrollDirection: Axis.horizontal, + itemCount: _selectList.length, + itemBuilder: (context, index) { + return Container( + width: 50, + height: 50, + padding: const EdgeInsets.all(4), + child: GestureDetector( + onTap: () { + setState(() { + _selectList.removeAt(index); + }); + }, + child: CustomAvatar( + _selectList[index].userProfile!.faceUrl, + size: 42, + ), + ), + ); + }, + ), + ), + const Divider(height: 0), + Container( + color: AppColors.unactive.withOpacity(0.1), + alignment: Alignment.centerLeft, + padding: const EdgeInsets.only( + left: 16, + ), + height: 40, + width: double.infinity, + child: const Text( + '选择群成员', + style: TextStyle( + fontSize: 14, + ), + ), + ), + Expanded( + child: FriendSelector( + onChanged: onChanged, + ), + ), + Container( + padding: const EdgeInsets.only( + right: 16, + left: 16, + top: 4, + ), + decoration: const BoxDecoration( + color: Colors.white, + border: Border( + top: BorderSide( + color: Colors.black12, + width: 0.4, + ), + ), + ), + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Text( + '已选 ${_selectList.length}', + style: const TextStyle( + color: Colors.grey, + ), + ), + ElevatedButton( + onPressed: + _selectList.isNotEmpty && _selectList.length < 200 + ? _createGroup + : null, + child: const Text( + '完成', + ), + ) + ], + ), + ), + ], + ), + ), + ); + } + + /// 好友选择,添加到选择列表 + Future onChanged(e) async { + setState(() { + _selectList = e; + + Future.delayed(const Duration(milliseconds: 200), () { + _scrollController.animateTo( + _scrollController.position.maxScrollExtent, + duration: const Duration(milliseconds: 200), + curve: Curves.bounceIn, + ); + }); + }); + } + + /// 创建群聊 + Future _createGroup() async { + String groupName = '创建的群聊'; + var result = await TimGroupService.to.create( + groupName, + _selectList, + groupType: GroupType.Public, + ); + + if (result != null) { + Get.offNamed( + ConversationRoutes.index, + arguments: { + 'conversation': await TimConversationService.to.getById( + 'group_' + result, + ), + }, + ); + } + } +} diff --git a/lib/views/public/app_page.dart b/lib/views/public/app_page.dart index 6a2df01..572c211 100644 --- a/lib/views/public/app_page.dart +++ b/lib/views/public/app_page.dart @@ -2,7 +2,6 @@ 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/user_page.dart'; import 'package:flutter/material.dart'; import 'package:get/get.dart'; @@ -14,7 +13,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()), ]; @@ -29,11 +28,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/qr_code/index_page.dart b/lib/views/user/qr_code/index_page.dart index 5700022..120192d 100644 --- a/lib/views/user/qr_code/index_page.dart +++ b/lib/views/user/qr_code/index_page.dart @@ -1,15 +1,131 @@ +import 'package:chat/configs/app_colors.dart'; +import 'package:chat/views/home/widgets/pop_menu_item.dart'; +import 'package:chat/views/public/scan_page.dart'; +import 'package:chat/widgets/custom_avatar.dart'; import 'package:flutter/material.dart'; +import 'package:get/get.dart'; +import 'package:permission_handler/permission_handler.dart'; +import 'package:qr_flutter/qr_flutter.dart'; class UserQrCodePage extends StatefulWidget { const UserQrCodePage({Key? key}) : super(key: key); @override - _UserQrCodePageState createState() => _UserQrCodePageState(); + State createState() => _UserQrCodePageState(); } class _UserQrCodePageState extends State { @override Widget build(BuildContext context) { - return Container(); + return Scaffold( + appBar: AppBar( + title: const Text('我的二维码'), + actions: [ + IconButton( + onPressed: () { + _showLongPressMenu(); + }, + icon: const Icon(Icons.more_horiz), + ), + ], + ), + body: Center( + child: Container( + width: Get.width - 32, + padding: const EdgeInsets.all(16), + decoration: BoxDecoration( + color: AppColors.white, + borderRadius: BorderRadius.circular(8), + ), + child: Column( + mainAxisSize: MainAxisSize.min, + children: [ + Row( + children: [ + CustomAvatar( + '', + size: 64, + radius: 6, + ), + const SizedBox(width: 8), + Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: const [ + Text( + 'Jason', + style: TextStyle( + fontSize: 20, + ), + ), + SizedBox(height: 8), + ], + ), + ], + ), + const SizedBox(height: 32), + QrImage( + data: 'BEFRIEND|5', + version: 3, + size: Get.width * 0.8, + ), + const SizedBox(height: 32), + const Text( + '扫一扫上面的二维码,加我共力好友', + style: TextStyle( + color: AppColors.unactive, + ), + ), + ], + ), + ), + ), + ); + } + + Future _showLongPressMenu() async { + showModalBottomSheet( + context: Get.context!, + isScrollControlled: true, + backgroundColor: AppColors.white, + shape: const RoundedRectangleBorder( + borderRadius: BorderRadius.vertical(top: Radius.circular(8)), + ), + builder: (context) { + return Column( + mainAxisSize: MainAxisSize.min, + children: [ + PopMenuItem( + '保存到手机', + onTap: () {}, + ), + const Divider(height: 0), + PopMenuItem( + '扫描二维码', + onTap: () { + Get.back(); + Permission.camera.request().isGranted.then((value) { + if (value) { + Get.to(const ScanPage()); + } + }); + }, + ), + const Divider(height: 0), + const Divider(height: 0.4), + Container( + color: AppColors.page, + height: 8, + ), + const Divider(height: 0.4), + PopMenuItem( + '取消', + onTap: () { + Get.back(); + }, + ), + ], + ); + }, + ); } } diff --git a/lib/widgets/custom_avatar.dart b/lib/widgets/custom_avatar.dart index 5ee2f41..d145dec 100644 --- a/lib/widgets/custom_avatar.dart +++ b/lib/widgets/custom_avatar.dart @@ -17,7 +17,7 @@ class CustomAvatar extends StatelessWidget { @override Widget build(BuildContext context) { if (avtarUrl == null || avtarUrl == '') { - avtarUrl = 'assets/chats/default_avatar.png'; + avtarUrl = 'assets/images/default_avatar.png'; } avtarUrl = avtarUrl!.trim(); diff --git a/pubspec.lock b/pubspec.lock index e054fae..b3e8c94 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -542,14 +542,14 @@ packages: name: permission_handler url: "https://pub.flutter-io.cn" source: hosted - version: "10.2.0" + version: "9.2.0" permission_handler_android: dependency: transitive description: name: permission_handler_android url: "https://pub.flutter-io.cn" source: hosted - version: "10.2.0" + version: "9.0.2+1" permission_handler_apple: dependency: transitive description: @@ -572,12 +572,12 @@ packages: source: hosted version: "0.1.2" photo_manager: - dependency: transitive + dependency: "direct main" description: name: photo_manager url: "https://pub.flutter-io.cn" source: hosted - version: "2.4.1" + version: "2.2.1" photo_view: dependency: "direct main" description: diff --git a/pubspec.yaml b/pubspec.yaml index 0169786..a918f2c 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -43,9 +43,10 @@ dependencies: video_player: ^2.4.7 scroll_to_index: ^2.1.1 dart_date: ^1.1.1 - permission_handler: ^10.2.0 + permission_handler: ^9.2.0 tuple: ^2.0.1 photo_view: ^0.14.0 + photo_manager: 2.2.1 chewie: ^1.3.5 dev_dependencies: @@ -56,4 +57,5 @@ flutter: uses-material-design: true assets: - assets/icons/ + - assets/images/ - assets/transits/