企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
[TOC] ## 概述 - Builder 用于获取父组件或者部分状态管理的方法 - 这个小部件是定义[StatelessWidget](https://api.flutter.dev/flutter/widgets/StatelessWidget-class.html)子类的简单内联替代方案 ``` class Foo extends StatelessWidget { @override Widget build(BuildContext context) => Text('foo'); } Center(child: Foo()) ``` 可用Builder替换 ``` Center( child: Builder( builder: (BuildContext context) => Text('foo'); ), ) ``` ``` child: Builder( builder: (context){ return TextButton( onPressed: (){ ScaffoldState _sate = context.findAncestorStateOfType<ScaffoldState>()!; _sate.closeDrawer(); }, child: Text("hello world"), ); }, ) ```