mirror of
https://github.com/rustdesk/rustdesk.git
synced 2024-12-13 11:09:17 +08:00
10508a41b1
Signed-off-by: fufesou <shuanglongchen@yeah.net>
232 lines
6.7 KiB
Dart
232 lines
6.7 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_hbb/common/hbbs/hbbs.dart';
|
|
import 'package:flutter_hbb/common/widgets/peers_view.dart';
|
|
import 'package:flutter_hbb/models/state_model.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> {
|
|
RxString get selectedUser => gFFI.groupModel.selectedUser;
|
|
RxString get searchUserText => gFFI.groupModel.searchUserText;
|
|
static TextEditingController searchUserController = TextEditingController();
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Obx(() => Offstage(
|
|
offstage: stateGlobal.svcStatus.value != SvcStatus.ready,
|
|
child: FutureBuilder<Widget>(
|
|
future: buildBody(context),
|
|
builder: (context, snapshot) {
|
|
if (snapshot.hasData) {
|
|
return snapshot.data!;
|
|
} else {
|
|
return const Offstage();
|
|
}
|
|
}),
|
|
));
|
|
}
|
|
|
|
Future<Widget> buildBody(BuildContext context) async {
|
|
return Obx(() {
|
|
if (gFFI.groupModel.groupLoading.value ||
|
|
gFFI.groupModel.peerLoading.value) {
|
|
return const Center(
|
|
child: CircularProgressIndicator(),
|
|
);
|
|
}
|
|
if (gFFI.groupModel.groupLoadError.isNotEmpty) {
|
|
return _buildShowError(gFFI.groupModel.groupLoadError.value);
|
|
}
|
|
if (isDesktop) {
|
|
return _buildDesktop();
|
|
} else {
|
|
return _buildMobile();
|
|
}
|
|
});
|
|
}
|
|
|
|
Widget _buildShowError(String error) {
|
|
return Center(
|
|
child: Column(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
Text(translate(error)),
|
|
TextButton(
|
|
onPressed: () {
|
|
gFFI.groupModel.pull();
|
|
},
|
|
child: Text(translate("Retry")))
|
|
],
|
|
));
|
|
}
|
|
|
|
Widget _buildDesktop() {
|
|
return Row(
|
|
children: [
|
|
Card(
|
|
margin: EdgeInsets.symmetric(horizontal: 4.0),
|
|
shape: RoundedRectangleBorder(
|
|
borderRadius: BorderRadius.circular(12),
|
|
side:
|
|
BorderSide(color: Theme.of(context).scaffoldBackgroundColor)),
|
|
child: Container(
|
|
width: 200,
|
|
height: double.infinity,
|
|
padding:
|
|
const EdgeInsets.symmetric(horizontal: 12.0, vertical: 8.0),
|
|
child: Column(
|
|
children: [
|
|
_buildLeftHeader(),
|
|
Expanded(
|
|
child: Container(
|
|
width: double.infinity,
|
|
height: double.infinity,
|
|
decoration:
|
|
BoxDecoration(borderRadius: BorderRadius.circular(2)),
|
|
child: _buildUserContacts(),
|
|
).marginSymmetric(vertical: 8.0),
|
|
)
|
|
],
|
|
),
|
|
),
|
|
).marginOnly(right: 8.0),
|
|
Expanded(
|
|
child: Align(
|
|
alignment: Alignment.topLeft,
|
|
child: MyGroupPeerView(
|
|
menuPadding: widget.menuPadding,
|
|
initPeers: gFFI.groupModel.peersShow)),
|
|
)
|
|
],
|
|
);
|
|
}
|
|
|
|
Widget _buildMobile() {
|
|
return Column(
|
|
children: [
|
|
Card(
|
|
margin: EdgeInsets.symmetric(horizontal: 4.0),
|
|
shape: RoundedRectangleBorder(
|
|
borderRadius: BorderRadius.circular(12),
|
|
side:
|
|
BorderSide(color: Theme.of(context).scaffoldBackgroundColor)),
|
|
child: Container(
|
|
padding:
|
|
const EdgeInsets.symmetric(horizontal: 12.0, vertical: 8.0),
|
|
child: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
_buildLeftHeader(),
|
|
Container(
|
|
width: double.infinity,
|
|
decoration:
|
|
BoxDecoration(borderRadius: BorderRadius.circular(4)),
|
|
child: _buildUserContacts(),
|
|
).marginSymmetric(vertical: 8.0)
|
|
],
|
|
),
|
|
),
|
|
),
|
|
Divider(),
|
|
Expanded(
|
|
child: Align(
|
|
alignment: Alignment.topLeft,
|
|
child: MyGroupPeerView(
|
|
menuPadding: widget.menuPadding,
|
|
initPeers: gFFI.groupModel.peersShow)),
|
|
)
|
|
],
|
|
);
|
|
}
|
|
|
|
Widget _buildLeftHeader() {
|
|
return Row(
|
|
children: [
|
|
Expanded(
|
|
child: TextField(
|
|
controller: searchUserController,
|
|
onChanged: (value) {
|
|
searchUserText.value = value;
|
|
},
|
|
decoration: InputDecoration(
|
|
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;
|
|
})
|
|
.map((e) => _buildUserItem(e))
|
|
.toList());
|
|
});
|
|
}
|
|
|
|
Widget _buildUserItem(UserPayload user) {
|
|
final username = user.name;
|
|
return InkWell(onTap: () {
|
|
if (selectedUser.value != username) {
|
|
selectedUser.value = username;
|
|
} else {
|
|
selectedUser.value = '';
|
|
}
|
|
}, child: Obx(
|
|
() {
|
|
bool selected = selectedUser.value == username;
|
|
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: [
|
|
Icon(Icons.person_outline_rounded, color: Colors.grey, size: 16)
|
|
.marginOnly(right: 4),
|
|
Expanded(child: Text(username)),
|
|
],
|
|
).paddingSymmetric(vertical: 4),
|
|
),
|
|
);
|
|
},
|
|
)).marginSymmetric(horizontal: 12);
|
|
}
|
|
}
|