| 
									
										
										
										
											2022-12-11 21:40:35 +08:00
										 |  |  | import 'package:flutter/material.dart'; | 
					
						
							| 
									
										
										
										
											2023-06-17 20:48:58 +08:00
										 |  |  | import 'package:flutter_hbb/common/hbbs/hbbs.dart'; | 
					
						
							| 
									
										
										
										
											2023-06-21 16:04:52 +08:00
										 |  |  | import 'package:flutter_hbb/common/widgets/login.dart'; | 
					
						
							| 
									
										
										
										
											2022-12-11 21:40:35 +08:00
										 |  |  | import 'package:flutter_hbb/common/widgets/peers_view.dart'; | 
					
						
							|  |  |  | import 'package:get/get.dart'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import '../../common.dart'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class MyGroup extends StatefulWidget { | 
					
						
							|  |  |  |   final EdgeInsets? menuPadding; | 
					
						
							|  |  |  |   const MyGroup({Key? key, this.menuPadding}) : super(key: key); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   @override | 
					
						
							|  |  |  |   State<StatefulWidget> createState() { | 
					
						
							|  |  |  |     return _MyGroupState(); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class _MyGroupState extends State<MyGroup> { | 
					
						
							| 
									
										
										
										
											2023-06-21 09:30:32 +08:00
										 |  |  |   RxString get selectedUser => gFFI.groupModel.selectedUser; | 
					
						
							|  |  |  |   RxString get searchUserText => gFFI.groupModel.searchUserText; | 
					
						
							| 
									
										
										
										
											2022-12-11 21:40:35 +08:00
										 |  |  |   static TextEditingController searchUserController = TextEditingController(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   @override | 
					
						
							|  |  |  |   void initState() { | 
					
						
							|  |  |  |     super.initState(); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   @override | 
					
						
							| 
									
										
										
										
											2023-06-21 16:08:45 +08:00
										 |  |  |   Widget build(BuildContext context) { | 
					
						
							| 
									
										
										
										
											2023-06-21 16:04:52 +08:00
										 |  |  |     return Obx(() { | 
					
						
							| 
									
										
										
										
											2023-09-14 10:17:03 +08:00
										 |  |  |       if (!gFFI.userModel.isLogin) { | 
					
						
							| 
									
										
										
										
											2023-06-21 16:04:52 +08:00
										 |  |  |         return Center( | 
					
						
							|  |  |  |             child: ElevatedButton( | 
					
						
							|  |  |  |                 onPressed: loginDialog, child: Text(translate("Login")))); | 
					
						
							| 
									
										
										
										
											2023-09-14 10:17:03 +08:00
										 |  |  |       } else if (gFFI.groupModel.groupLoading.value && gFFI.groupModel.emtpy) { | 
					
						
							| 
									
										
										
										
											2022-12-11 21:40:35 +08:00
										 |  |  |         return const Center( | 
					
						
							|  |  |  |           child: CircularProgressIndicator(), | 
					
						
							|  |  |  |         ); | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2023-09-14 10:17:03 +08:00
										 |  |  |       return Column( | 
					
						
							|  |  |  |         children: [ | 
					
						
							|  |  |  |           buildErrorBanner(context, | 
					
						
							|  |  |  |               loading: gFFI.groupModel.groupLoading, | 
					
						
							|  |  |  |               err: gFFI.groupModel.groupLoadError, | 
					
						
							|  |  |  |               retry: null, | 
					
						
							|  |  |  |               close: () => gFFI.groupModel.groupLoadError.value = ''), | 
					
						
							|  |  |  |           Expanded(child: isDesktop ? _buildDesktop() : _buildMobile()) | 
					
						
							|  |  |  |         ], | 
					
						
							|  |  |  |       ); | 
					
						
							| 
									
										
										
										
											2022-12-11 21:40:35 +08:00
										 |  |  |     }); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-12-14 12:47:08 +08:00
										 |  |  |   Widget _buildDesktop() { | 
					
						
							| 
									
										
										
										
											2023-06-21 09:30:32 +08:00
										 |  |  |     return Row( | 
					
						
							|  |  |  |       children: [ | 
					
						
							| 
									
										
										
										
											2023-06-23 00:32:43 +08:00
										 |  |  |         Container( | 
					
						
							|  |  |  |           decoration: BoxDecoration( | 
					
						
							| 
									
										
										
										
											2023-06-21 09:30:32 +08:00
										 |  |  |               borderRadius: BorderRadius.circular(12), | 
					
						
							| 
									
										
										
										
											2023-06-23 00:32:43 +08:00
										 |  |  |               border: | 
					
						
							|  |  |  |                   Border.all(color: Theme.of(context).colorScheme.background)), | 
					
						
							| 
									
										
										
										
											2023-06-21 09:30:32 +08:00
										 |  |  |           child: Container( | 
					
						
							| 
									
										
										
										
											2023-06-23 00:32:43 +08:00
										 |  |  |             width: 150, | 
					
						
							| 
									
										
										
										
											2023-06-21 09:30:32 +08:00
										 |  |  |             height: double.infinity, | 
					
						
							|  |  |  |             child: Column( | 
					
						
							|  |  |  |               children: [ | 
					
						
							|  |  |  |                 _buildLeftHeader(), | 
					
						
							|  |  |  |                 Expanded( | 
					
						
							|  |  |  |                   child: Container( | 
					
						
							|  |  |  |                     width: double.infinity, | 
					
						
							|  |  |  |                     height: double.infinity, | 
					
						
							|  |  |  |                     child: _buildUserContacts(), | 
					
						
							| 
									
										
										
										
											2023-06-23 00:32:43 +08:00
										 |  |  |                   ), | 
					
						
							| 
									
										
										
										
											2023-06-21 09:30:32 +08:00
										 |  |  |                 ) | 
					
						
							|  |  |  |               ], | 
					
						
							| 
									
										
										
										
											2022-12-14 12:47:08 +08:00
										 |  |  |             ), | 
					
						
							| 
									
										
										
										
											2023-06-21 09:30:32 +08:00
										 |  |  |           ), | 
					
						
							| 
									
										
										
										
											2023-06-23 00:32:43 +08:00
										 |  |  |         ).marginOnly(right: 12.0), | 
					
						
							| 
									
										
										
										
											2023-06-21 09:30:32 +08:00
										 |  |  |         Expanded( | 
					
						
							|  |  |  |           child: Align( | 
					
						
							|  |  |  |               alignment: Alignment.topLeft, | 
					
						
							| 
									
										
										
										
											2023-09-14 10:17:03 +08:00
										 |  |  |               child: MyGroupPeerView( | 
					
						
							| 
									
										
										
										
											2023-06-21 09:30:32 +08:00
										 |  |  |                   menuPadding: widget.menuPadding, | 
					
						
							| 
									
										
										
										
											2023-09-14 10:17:03 +08:00
										 |  |  |                   initPeers: gFFI.groupModel.peers)), | 
					
						
							| 
									
										
										
										
											2023-06-21 09:30:32 +08:00
										 |  |  |         ) | 
					
						
							|  |  |  |       ], | 
					
						
							| 
									
										
										
										
											2022-12-14 12:47:08 +08:00
										 |  |  |     ); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   Widget _buildMobile() { | 
					
						
							| 
									
										
										
										
											2023-06-21 09:30:32 +08:00
										 |  |  |     return Column( | 
					
						
							|  |  |  |       children: [ | 
					
						
							| 
									
										
										
										
											2023-06-23 00:32:43 +08:00
										 |  |  |         Container( | 
					
						
							|  |  |  |           decoration: BoxDecoration( | 
					
						
							|  |  |  |               borderRadius: BorderRadius.circular(6), | 
					
						
							|  |  |  |               border: | 
					
						
							|  |  |  |                   Border.all(color: Theme.of(context).colorScheme.background)), | 
					
						
							| 
									
										
										
										
											2023-06-21 09:30:32 +08:00
										 |  |  |           child: Container( | 
					
						
							|  |  |  |             child: Column( | 
					
						
							|  |  |  |               mainAxisSize: MainAxisSize.min, | 
					
						
							|  |  |  |               children: [ | 
					
						
							|  |  |  |                 _buildLeftHeader(), | 
					
						
							|  |  |  |                 Container( | 
					
						
							|  |  |  |                   width: double.infinity, | 
					
						
							|  |  |  |                   child: _buildUserContacts(), | 
					
						
							| 
									
										
										
										
											2023-06-23 00:32:43 +08:00
										 |  |  |                 ) | 
					
						
							| 
									
										
										
										
											2023-06-21 09:30:32 +08:00
										 |  |  |               ], | 
					
						
							| 
									
										
										
										
											2022-12-11 21:40:35 +08:00
										 |  |  |             ), | 
					
						
							|  |  |  |           ), | 
					
						
							| 
									
										
										
										
											2023-06-23 00:32:43 +08:00
										 |  |  |         ).marginOnly(bottom: 12.0), | 
					
						
							| 
									
										
										
										
											2023-06-21 09:30:32 +08:00
										 |  |  |         Expanded( | 
					
						
							|  |  |  |           child: Align( | 
					
						
							|  |  |  |               alignment: Alignment.topLeft, | 
					
						
							| 
									
										
										
										
											2023-09-14 10:17:03 +08:00
										 |  |  |               child: MyGroupPeerView( | 
					
						
							| 
									
										
										
										
											2023-06-21 09:30:32 +08:00
										 |  |  |                   menuPadding: widget.menuPadding, | 
					
						
							| 
									
										
										
										
											2023-09-14 10:17:03 +08:00
										 |  |  |                   initPeers: gFFI.groupModel.peers)), | 
					
						
							| 
									
										
										
										
											2023-06-21 09:30:32 +08:00
										 |  |  |         ) | 
					
						
							|  |  |  |       ], | 
					
						
							| 
									
										
										
										
											2022-12-11 21:40:35 +08:00
										 |  |  |     ); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   Widget _buildLeftHeader() { | 
					
						
							|  |  |  |     return Row( | 
					
						
							|  |  |  |       children: [ | 
					
						
							|  |  |  |         Expanded( | 
					
						
							|  |  |  |             child: TextField( | 
					
						
							|  |  |  |           controller: searchUserController, | 
					
						
							|  |  |  |           onChanged: (value) { | 
					
						
							|  |  |  |             searchUserText.value = value; | 
					
						
							|  |  |  |           }, | 
					
						
							|  |  |  |           decoration: InputDecoration( | 
					
						
							| 
									
										
										
										
											2023-06-23 00:32:43 +08:00
										 |  |  |             filled: false, | 
					
						
							| 
									
										
										
										
											2022-12-11 21:40:35 +08:00
										 |  |  |             prefixIcon: Icon( | 
					
						
							|  |  |  |               Icons.search_rounded, | 
					
						
							|  |  |  |               color: Theme.of(context).hintColor, | 
					
						
							|  |  |  |             ), | 
					
						
							|  |  |  |             contentPadding: const EdgeInsets.symmetric(vertical: 10), | 
					
						
							|  |  |  |             hintText: translate("Search"), | 
					
						
							|  |  |  |             hintStyle: | 
					
						
							|  |  |  |                 TextStyle(fontSize: 14, color: Theme.of(context).hintColor), | 
					
						
							|  |  |  |             border: InputBorder.none, | 
					
						
							|  |  |  |             isDense: true, | 
					
						
							|  |  |  |           ), | 
					
						
							|  |  |  |         )), | 
					
						
							|  |  |  |       ], | 
					
						
							|  |  |  |     ); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   Widget _buildUserContacts() { | 
					
						
							|  |  |  |     return Obx(() { | 
					
						
							|  |  |  |       return Column( | 
					
						
							|  |  |  |           children: gFFI.groupModel.users | 
					
						
							|  |  |  |               .where((p0) { | 
					
						
							|  |  |  |                 if (searchUserText.isNotEmpty) { | 
					
						
							|  |  |  |                   return p0.name.contains(searchUserText.value); | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |                 return true; | 
					
						
							|  |  |  |               }) | 
					
						
							| 
									
										
										
										
											2023-06-17 20:48:58 +08:00
										 |  |  |               .map((e) => _buildUserItem(e)) | 
					
						
							| 
									
										
										
										
											2022-12-11 21:40:35 +08:00
										 |  |  |               .toList()); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-17 20:48:58 +08:00
										 |  |  |   Widget _buildUserItem(UserPayload user) { | 
					
						
							|  |  |  |     final username = user.name; | 
					
						
							| 
									
										
										
										
											2022-12-11 21:40:35 +08:00
										 |  |  |     return InkWell(onTap: () { | 
					
						
							|  |  |  |       if (selectedUser.value != username) { | 
					
						
							|  |  |  |         selectedUser.value = username; | 
					
						
							| 
									
										
										
										
											2023-06-21 09:30:32 +08:00
										 |  |  |       } else { | 
					
						
							|  |  |  |         selectedUser.value = ''; | 
					
						
							| 
									
										
										
										
											2022-12-11 21:40:35 +08:00
										 |  |  |       } | 
					
						
							|  |  |  |     }, child: Obx( | 
					
						
							|  |  |  |       () { | 
					
						
							|  |  |  |         bool selected = selectedUser.value == username; | 
					
						
							| 
									
										
										
										
											2023-09-14 10:17:03 +08:00
										 |  |  |         final isMe = username == gFFI.userModel.userName.value; | 
					
						
							| 
									
										
										
										
											2022-12-11 21:40:35 +08:00
										 |  |  |         return Container( | 
					
						
							|  |  |  |           decoration: BoxDecoration( | 
					
						
							|  |  |  |             color: selected ? MyTheme.color(context).highlight : null, | 
					
						
							|  |  |  |             border: Border( | 
					
						
							|  |  |  |                 bottom: BorderSide( | 
					
						
							|  |  |  |                     width: 0.7, | 
					
						
							|  |  |  |                     color: Theme.of(context).dividerColor.withOpacity(0.1))), | 
					
						
							|  |  |  |           ), | 
					
						
							|  |  |  |           child: Container( | 
					
						
							|  |  |  |             child: Row( | 
					
						
							|  |  |  |               children: [ | 
					
						
							| 
									
										
										
										
											2023-06-23 00:32:43 +08:00
										 |  |  |                 Icon(Icons.person_rounded, color: Colors.grey, size: 16) | 
					
						
							| 
									
										
										
										
											2022-12-11 21:40:35 +08:00
										 |  |  |                     .marginOnly(right: 4), | 
					
						
							| 
									
										
										
										
											2023-09-14 10:17:03 +08:00
										 |  |  |                 Expanded(child: Text(isMe ? translate('Me') : username)), | 
					
						
							| 
									
										
										
										
											2022-12-11 21:40:35 +08:00
										 |  |  |               ], | 
					
						
							|  |  |  |             ).paddingSymmetric(vertical: 4), | 
					
						
							|  |  |  |           ), | 
					
						
							|  |  |  |         ); | 
					
						
							|  |  |  |       }, | 
					
						
							| 
									
										
										
										
											2023-06-23 00:32:43 +08:00
										 |  |  |     )).marginSymmetric(horizontal: 12).marginOnly(bottom: 6); | 
					
						
							| 
									
										
										
										
											2022-12-11 21:40:35 +08:00
										 |  |  |   } | 
					
						
							|  |  |  | } |