opt: follow dialog

fix: add user tags
This commit is contained in:
bggRGjQaUbCoE
2024-10-08 10:35:55 +08:00
parent 5d0e4ed441
commit e6b71d375f
5 changed files with 313 additions and 109 deletions

View File

@@ -10,7 +10,14 @@ import '../../../../../utils/utils.dart';
class GroupPanel extends StatefulWidget {
final int? mid;
const GroupPanel({super.key, this.mid});
final List? tags;
final ScrollController? scrollController;
const GroupPanel({
super.key,
this.mid,
this.tags,
this.scrollController,
});
@override
State<GroupPanel> createState() => _GroupPanelState();
@@ -19,12 +26,25 @@ class GroupPanel extends StatefulWidget {
class _GroupPanelState extends State<GroupPanel> {
late Future _futureBuilderFuture;
late List<MemberTagItemModel> tagsList;
bool showDefault = true;
bool showDefaultBtn = true;
@override
void initState() {
super.initState();
_futureBuilderFuture = MemberHttp.followUpTags();
() async {
dynamic result = await _futureBuilderFuture;
if (result['status']) {
tagsList = result['data'];
tagsList.removeWhere((item) => item.tagid == 0);
tagsList = tagsList.map((item) {
return item..checked = widget.tags?.contains(item.tagid) == true;
}).toList();
setState(() {
showDefaultBtn = !tagsList.any((e) => e.checked == true);
});
}
}();
}
void onSave() async {
@@ -46,111 +66,133 @@ class _GroupPanelState extends State<GroupPanel> {
final res = await MemberHttp.addUsers(widget.mid, tagids);
SmartDialog.showToast(res['msg']);
if (res['status']) {
Get.back();
Get.back(result: true);
}
}
@override
Widget build(BuildContext context) {
return Container(
height: Utils.getSheetHeight(context),
color: Theme.of(context).colorScheme.background,
child: Column(
children: <Widget>[
AppBar(
centerTitle: false,
elevation: 0,
leading: IconButton(
tooltip: '关闭',
onPressed: () => Get.back(),
icon: const Icon(Icons.close_outlined)),
title:
Text('设置关注分组', style: Theme.of(context).textTheme.titleMedium),
),
Expanded(
child: Material(
child: FutureBuilder(
future: _futureBuilderFuture,
builder: (BuildContext context, AsyncSnapshot snapshot) {
if (snapshot.connectionState == ConnectionState.done) {
Map data = snapshot.data as Map;
if (data['status']) {
tagsList = data['data'];
return ListView.builder(
itemCount: data['data'].length,
itemBuilder: (context, index) {
return ListTile(
onTap: () {
data['data'][index].checked =
!data['data'][index].checked;
showDefault =
!data['data'].any((e) => e.checked == true);
setState(() {});
},
dense: true,
leading: const Icon(Icons.group_outlined),
minLeadingWidth: 0,
title: Text(data['data'][index].name),
subtitle: data['data'][index].tip != ''
? Text(data['data'][index].tip)
: null,
trailing: Transform.scale(
scale: 0.9,
child: Checkbox(
value: data['data'][index].checked,
onChanged: (bool? checkValue) {
data['data'][index].checked = checkValue;
showDefault = !data['data']
.any((e) => e.checked == true);
setState(() {});
},
return NotificationListener<DraggableScrollableNotification>(
onNotification: (notification) {
if (notification.extent <= 1e-5) {
Get.back();
}
return false;
},
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(18),
color: Theme.of(context).colorScheme.surface,
),
child: Column(
children: <Widget>[
AppBar(
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.vertical(
top: Radius.circular(18),
),
),
centerTitle: false,
elevation: 0,
leading: IconButton(
tooltip: '关闭',
onPressed: Get.back,
icon: const Icon(Icons.close_outlined)),
title: Text('设置关注分组',
style: Theme.of(context).textTheme.titleMedium),
),
Expanded(
child: Material(
child: FutureBuilder(
future: _futureBuilderFuture,
builder: (BuildContext context, AsyncSnapshot snapshot) {
if (snapshot.connectionState == ConnectionState.done) {
Map data = snapshot.data as Map;
if (data['status']) {
return ListView.builder(
controller: widget.scrollController,
itemCount: tagsList.length,
itemBuilder: (context, index) {
return ListTile(
onTap: () {
tagsList[index].checked =
!tagsList[index].checked!;
showDefaultBtn =
!tagsList.any((e) => e.checked == true);
setState(() {});
},
dense: true,
leading: const Icon(Icons.group_outlined),
minLeadingWidth: 0,
title: Text(tagsList[index].name ?? ''),
subtitle: tagsList[index].tip != ''
? Text(tagsList[index].tip ?? '')
: null,
trailing: Transform.scale(
scale: 0.9,
child: Checkbox(
value: tagsList[index].checked,
onChanged: (bool? checkValue) {
tagsList[index].checked = checkValue;
showDefaultBtn =
!tagsList.any((e) => e.checked == true);
setState(() {});
},
),
),
);
},
);
} else {
return CustomScrollView(
controller: widget.scrollController,
slivers: [
HttpError(
errMsg: data['msg'],
fn: () => setState(() {}),
),
);
},
);
],
);
}
} else {
return HttpError(
errMsg: data['msg'],
fn: () => setState(() {}),
// 骨架屏
return const Center(
child: CircularProgressIndicator(),
);
}
} else {
// 骨架屏
return const Text('请求中');
}
},
},
),
),
),
),
Divider(
height: 1,
color: Theme.of(context).disabledColor.withOpacity(0.08),
),
Padding(
padding: EdgeInsets.only(
left: 20,
right: 20,
top: 12,
bottom: MediaQuery.of(context).padding.bottom + 12,
Divider(
height: 1,
color: Theme.of(context).disabledColor.withOpacity(0.08),
),
child: Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
TextButton(
onPressed: () => onSave(),
style: TextButton.styleFrom(
padding: const EdgeInsets.only(left: 30, right: 30),
foregroundColor: Theme.of(context).colorScheme.onPrimary,
backgroundColor:
Theme.of(context).colorScheme.primary, // 设置按钮背景色
Padding(
padding: EdgeInsets.only(
left: 20,
right: 20,
top: 12,
bottom: MediaQuery.of(context).padding.bottom + 12,
),
child: Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
TextButton(
onPressed: () => onSave(),
style: TextButton.styleFrom(
padding: const EdgeInsets.only(left: 30, right: 30),
foregroundColor: Theme.of(context).colorScheme.onPrimary,
backgroundColor:
Theme.of(context).colorScheme.primary, // 设置按钮背景色
),
child: Text(showDefaultBtn ? '保存至默认分组' : '保存'),
),
child: Text(showDefault ? '保存至默认分组' : '保存'),
),
],
],
),
),
),
],
],
),
),
);
}