Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想创建statefulWidget并希望在这个小部件中获得父小部件高度。不想通过从父小部件发送高度数据来做到这一点。我怎样才能做到这一点?
statefulWidget
使用LayoutBuilder作为子小部件。
LayoutBuilder(builder: (ctx, constraints) { return Container( height: constraints.maxHeight * 0.5, width: constraints.maxWidth * 0.5, child: Text('Inside Layout Builder'), ); })
根据此代码Container将使用父小部件的一半高度和宽度。
Container