长按已添加的话题出现删除键

pull/1/head
戴余标 3 years ago
parent 289b78849c
commit bfc5e020d0

@ -14,7 +14,6 @@ import 'package:bot_toast/bot_toast.dart';
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:get/get.dart'; import 'package:get/get.dart';
import 'package:velocity_x/velocity_x.dart';
class AddNewEventPage extends StatefulWidget { class AddNewEventPage extends StatefulWidget {
final int? initTopic; final int? initTopic;
@ -229,20 +228,26 @@ class _AddNewEventPageState extends State<AddNewEventPage> {
} }
} }
class TopicWidgets extends StatelessWidget { class TopicWidgets extends StatefulWidget {
const TopicWidgets({
Key? key,
this.hotTopicModels,
this.topicTags,
}) : assert(hotTopicModels != null || topicTags != null),
super(key: key);
final List<TopicListModel>? hotTopicModels; final List<TopicListModel>? hotTopicModels;
final List<TopicTag>? topicTags; final List<TopicTag>? topicTags;
List<dynamic> get models => List<dynamic> get models =>
hotTopicModels == null ? topicTags! : hotTopicModels!; hotTopicModels == null ? topicTags! : hotTopicModels!;
const TopicWidgets({Key? key,this.hotTopicModels,
this.topicTags,}) : super(key: key);
@override
State<TopicWidgets> createState() => _TopicWidgetsState();
}
class _TopicWidgetsState extends State<TopicWidgets> {
bool _deleteTopic=false;
@override
void setState(VoidCallback fn) {
super.setState(fn);
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Wrap( return Wrap(
@ -251,8 +256,17 @@ class TopicWidgets extends StatelessWidget {
runSpacing: 12.w, runSpacing: 12.w,
crossAxisAlignment: WrapCrossAlignment.start, crossAxisAlignment: WrapCrossAlignment.start,
children: [ children: [
...models ...widget.models
.map((e) => Container( .map(
(e) => GestureDetector(
onLongPress: () {
_deleteTopic = !_deleteTopic;
setState(() { });
print(_deleteTopic);
},
child: Stack(
children: [
Container(
padding: padding:
EdgeInsets.symmetric(vertical: 8.w, horizontal: 16.w), EdgeInsets.symmetric(vertical: 8.w, horizontal: 16.w),
decoration: BoxDecoration( decoration: BoxDecoration(
@ -263,9 +277,32 @@ class TopicWidgets extends StatelessWidget {
.size(24.sp) .size(24.sp)
.color(Color(0xFF547FC0)) .color(Color(0xFF547FC0))
.make(), .make(),
)) ),
.toList(), if (_deleteTopic)
Positioned(
top: 10.w,
right: 10.w,
child: GestureDetector(
onTap: () {
widget.models.remove(e);
setState(() { });
},
child: Material(
child: Icon(
CupertinoIcons.xmark_circle_fill,
size: 30.w,
color: Colors.red.withOpacity(0.60),
),
),
),
),
],
),
),
).toList(),
], ],
); );
} }
} }

Loading…
Cancel
Save