更新时间:2022-12-31 09:34:07
您可以只使用StatefulWidget
,然后长按ListTile
并使用setState
重建小部件.
You can just use a StatefulWidget
and after you long press the ListTile
rebuild the widget using setState
.
检查此样本:
class MyApp extends StatefulWidget {
@override
MyAppState createState() => MyAppState();
}
class MyAppState extends State<MyApp> {
bool isVisible = false;
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: ListTile(
title: Text("Title"),
onLongPress: () {
setState(() {
isVisible = !isVisible;
});
},
subtitle: isVisible ? Text("Subtitle sample") : null,
)));
}
}