0

我刚刚做了一个颤振项目。如何使一个可扩展为主然后内容可以根据我们所说的改变

在此处输入图像描述

我的意思是这样的:

main () {
body: column [
myMasterExpand (mycontent1 ()),
myMasterExpand (mycontent2 ()),
];
}

class myMasterExpand () {}

class mycontent1 () {}
class mycontent2 () {}
4

1 回答 1

0

您可以创建一个像这样的小部件作为您的主人:

class MyMasterExpandable extends StatelessWidget {
  final String title;
  final Widget content;

  const MyMasterExpandable({Key key, @required this.title, @required this.content})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    return ExpansionTile(
      title: Text(title),
      children: [content],
    );
  }
}

这可以像这样使用:

MyMasterExpandable(title: 'My Title', content: content1);
于 2021-01-11T02:49:25.147 回答