Flutter 提取小部件需要返回小部件

标签 flutter flutter-layout

我在树中得到了很多小部件组,并想开始将它们提取到自己的小部件中。

我尝试使用 Ctrl-Alt-W,此命令不执行任何操作,并且在出现问题时不显示任何错误。

如果您转到顶部菜单并单击重构、提取、提取到小部件,则会出现以下错误:

Can only extract a widget expression or a method returning widget.

这是我试图提取的代码示例:
                     Expanded(
                          child: Container(
                            child: Padding(
                              padding: const EdgeInsets.only(
                                  left: 8.0,
                                  right: 8.0,
                                  top: 8.0,
                                  bottom: 4.0),
                              child: new TextField(
                                decoration: new InputDecoration(
                                    border: new OutlineInputBorder(
                                      borderRadius: const BorderRadius.all(
                                        const Radius.circular(10.0),
                                      ),
                                    ),
                                    filled: true,
                                    hintStyle: new TextStyle(
                                        color: Colors.grey[800]),
                                    hintText: "Supervisor",
                                    fillColor: Colors.white70),
                              ),
                            ),
                          ),
                        ),

我将如何修改小部件树中的此代码以返回以便可以轻松提取它。

谢谢

最佳答案

我不认为这是一个错误。每个人都说您必须突出显示所有代码才能提取它,并且它与他们一起工作,但对我来说,我已经这样做了。
首先,我将光标放在特定的小部件上。
enter image description here
enter image description here
enter image description here
enter image description here

关于Flutter 提取小部件需要返回小部件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56558409/

相关文章:

android-studio - 在Mac上使用Flutter设置Android Studio的问题

android - 在 flutter 中显示全屏加载小部件

android - 使用SingleChildScrollView时的堆栈小部件错误

flutter - 使用CustomPaint在 Canvas 上居中放置项目

dart - Flutter Blue 示例无法通过扫描我的蓝牙 PC、其他 Android 手机和 iOS 找到

firebase - 使用 Flutter 一次性读取 Firestore,我需要在控制台中打印文档数据,想要将其输出到 UI 中

dart - 有没有更好的方法来测试 Dart 构造函数中的 null

flutter - 如何使 FloatingActionButton 在 persistentFooterButtons 中居中

Flutter (Dart) : Split the screen into 6 sections, 每个在中心有一个角

flutter - 如何从同时悬停的多个小部件中获取信息?