尝试在 Flutter 中设置行小部件的框约束



好的,所以我正在使用 Flutter,并尝试将整个行小部件的约束设置为 屏幕宽度,不设置行中每个单独部分的约束。 我搜索过 所有位置,并且行小部件没有要设置的宽度或最大宽度参数(它将其设置为 出于某种原因无穷大(并且行内的两件事之一必须是文本字段(我是 在iOS上开发,所以我使用的是CupertinoTextField,但这应该不会有什么不同。

脚手架小部件主体的一个例子是:

body: Container(
constraints: BoxConstraints.tight(new Size(MediaQuery.of(context).size.width, double.infinity)),
child: Row(
children: [
FloatingActionButton(
onPressed: _incrementCounter,
tooltip: 'Increment',
child: Icon(Icons.add),
),
CupertinoTextField(
textInputAction: TextInputAction.done,
keyboardType: TextInputType.text,
onSubmitted: (value) {
notes = value;
},
controller: textInput,
),
], 
)
)

可以想象,我收到无界渲染框错误,因为该行没有被限制 好吧,我不知道为什么 Flutter 不让我为整行设置计数框。 (或者如果确实如此,它不是按照我的方式做!

颤振医生的结果 -v

[✓] Flutter (Channel master, v1.14.2-pre.20, on Mac OS X 10.15.2 19C57, locale
en-CA)
• Flutter version 1.14.2-pre.20 at /Users/iosdev/Developer/flutter
• Framework revision 91f8d3da32 (2 hours ago), 2020-01-16 18:21:16 +0000
• Engine revision e0fe834288
• Dart version 2.8.0 (build 2.8.0-dev.2.0 009537bbf0)
[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
• Android SDK at /Users/iosdev/Library/Android/sdk
• Android NDK location not configured (optional; useful for native profiling
support)
• Platform android-29, build-tools 29.0.2
• Java binary at: /Applications/Android
Studio.app/Contents/jre/jdk/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build
1.8.0_202-release-1483-b49-5587405)
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS (Xcode 11.3.1)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Xcode 11.3.1, Build version 11C504
• CocoaPods version 1.8.4
[✓] Android Studio (version 3.5)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin version 42.1.1
• Dart plugin version 191.8593
• Java version OpenJDK Runtime Environment (build
1.8.0_202-release-1483-b49-5587405)
[✓] Connected device (1 available)
• Phillip’s iPhone • 52a4fba45a6767b88e4dddd881201205138cac0e • ios • iOS
13.3
• No issues found!

你只需要用一个扩展的小部件包装你的库比蒂诺文本字段:

Container(
child: Row(
children: [
FloatingActionButton(
onPressed: _incrementCounter,
tooltip: 'Increment',
child: Icon(Icons.add),
),
Expanded(
child: CupertinoTextField(
textInputAction: TextInputAction.done,
keyboardType: TextInputType.text,
onSubmitted: (value) {
notes = value;
},
controller: textInput,
),
),
],
)
)

最新更新