简体   繁体   English

如何在 flutter 中将一个小部件设为主控

[英]how to make one widget as master in flutter

I just made a flutter project.我刚刚做了一个 flutter 项目。 how to make one expandable as master then the content can change according to what we call如何使一个可扩展为主然后内容可以根据我们所说的改变

enter image description here在此处输入图像描述

what I mean is something like this:我的意思是这样的:

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

class myMasterExpand () {}

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

You can create a widget like this as your master:您可以创建一个像这样的小部件作为您的主人:

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],
    );
  }
}

This can be used like this:这可以像这样使用:

MyMasterExpandable(title: 'My Title', content: content1);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM