2023-09-25 13:35:01 +08:00
|
|
|
import 'dart:math';
|
|
|
|
|
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 = ''),
|
2024-03-28 11:38:11 +08:00
|
|
|
Expanded(
|
|
|
|
child: (isDesktop || isWebDesktop)
|
|
|
|
? _buildDesktop()
|
|
|
|
: _buildMobile())
|
2023-09-14 10:17:03 +08:00
|
|
|
],
|
|
|
|
);
|
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,
|
2024-03-20 15:05:54 +08:00
|
|
|
getInitPeers: () => 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,
|
2024-03-20 15:05:54 +08:00
|
|
|
getInitPeers: () => gFFI.groupModel.peers)),
|
2023-06-21 09:30:32 +08:00
|
|
|
)
|
|
|
|
],
|
2022-12-11 21:40:35 +08:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
Widget _buildLeftHeader() {
|
2023-09-23 10:03:09 +08:00
|
|
|
final fontSize = 14.0;
|
2022-12-11 21:40:35 +08:00
|
|
|
return Row(
|
|
|
|
children: [
|
|
|
|
Expanded(
|
|
|
|
child: TextField(
|
|
|
|
controller: searchUserController,
|
|
|
|
onChanged: (value) {
|
|
|
|
searchUserText.value = value;
|
|
|
|
},
|
2023-09-23 10:03:09 +08:00
|
|
|
textAlignVertical: TextAlignVertical.center,
|
|
|
|
style: TextStyle(fontSize: fontSize),
|
2022-12-11 21:40:35 +08:00
|
|
|
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,
|
2023-09-23 10:03:09 +08:00
|
|
|
).paddingOnly(top: 2),
|
2022-12-11 21:40:35 +08:00
|
|
|
hintText: translate("Search"),
|
2023-09-23 10:03:09 +08:00
|
|
|
hintStyle: TextStyle(fontSize: fontSize),
|
2022-12-11 21:40:35 +08:00
|
|
|
border: InputBorder.none,
|
|
|
|
isDense: true,
|
|
|
|
),
|
|
|
|
)),
|
|
|
|
],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
Widget _buildUserContacts() {
|
|
|
|
return Obx(() {
|
2023-09-20 17:47:33 +08:00
|
|
|
final items = gFFI.groupModel.users.where((p0) {
|
|
|
|
if (searchUserText.isNotEmpty) {
|
2023-09-23 10:03:09 +08:00
|
|
|
return p0.name
|
|
|
|
.toLowerCase()
|
|
|
|
.contains(searchUserText.value.toLowerCase());
|
2023-09-20 17:47:33 +08:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}).toList();
|
2023-09-25 13:35:01 +08:00
|
|
|
final listView = ListView.builder(
|
|
|
|
shrinkWrap: isMobile,
|
|
|
|
itemCount: items.length,
|
|
|
|
itemBuilder: (context, index) => _buildUserItem(items[index]));
|
|
|
|
var maxHeight = max(MediaQuery.of(context).size.height / 6, 100.0);
|
2024-03-28 11:38:11 +08:00
|
|
|
return (isDesktop || isWebDesktop)
|
2023-09-25 13:35:01 +08:00
|
|
|
? listView
|
|
|
|
: LimitedBox(maxHeight: maxHeight, child: listView);
|
2022-12-11 21:40:35 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
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;
|
2023-09-26 09:26:53 +08:00
|
|
|
final colorMe = MyTheme.color(context).me!;
|
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-09-26 09:26:53 +08:00
|
|
|
Container(
|
|
|
|
width: 20,
|
|
|
|
height: 20,
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
color: str2color(username, 0xAF),
|
|
|
|
shape: BoxShape.circle,
|
|
|
|
),
|
|
|
|
child: Align(
|
|
|
|
alignment: Alignment.center,
|
|
|
|
child: Center(
|
|
|
|
child: Text(
|
|
|
|
username.characters.first.toUpperCase(),
|
|
|
|
style: TextStyle(color: Colors.white),
|
|
|
|
textAlign: TextAlign.center,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
).marginOnly(right: 4),
|
|
|
|
if (isMe) Flexible(child: Text(username)),
|
|
|
|
if (isMe)
|
|
|
|
Flexible(
|
|
|
|
child: Container(
|
|
|
|
margin: EdgeInsets.only(left: 5),
|
|
|
|
padding: EdgeInsets.symmetric(horizontal: 3, vertical: 1),
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
color: colorMe.withAlpha(20),
|
|
|
|
borderRadius: BorderRadius.all(Radius.circular(2)),
|
|
|
|
border: Border.all(color: colorMe.withAlpha(100))),
|
|
|
|
child: Text(
|
|
|
|
translate('Me'),
|
|
|
|
style: TextStyle(
|
|
|
|
color: colorMe.withAlpha(200), fontSize: 12),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
if (!isMe) Expanded(child: Text(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
|
|
|
}
|
|
|
|
}
|