简体   繁体   English

Flutter 片段在 statefull 小部件 android studio 中不起作用

[英]Flutter snippet didn't work in statefull widget android studio

i dont know, after flutter 3.0.0 update, i can't use snippet in android studio.我不知道,flutter 3.0.0 更新后,我无法在 android studio 中使用片段。 maybe i can, but inside a function.也许我可以,但在一个函数内。 i cant easily import material.dart.我无法轻松导入 material.dart。 but i used snippet in it worked (i can use snippet without flutter snipet plugin in android studio before).但我在其中使用了片段(我之前可以在 android studio 中使用没有颤振片段插件的片段)。

this flutter snippet didn't work inside statefull widget,这个颤振片段在有状态的小部件中不起作用,

在此处输入图像描述

but it works inside function.但它在函数内部起作用。 在此处输入图像描述

i can use snippet before finally using flutter snippet plugin, but when i upgrade flutter to 3.0.0, i cant use it.我可以在最终使用颤振片段插件之前使用片段,但是当我将颤振升级到 3.0.0 时,我无法使用它。 and when i use flutter snippet plugin, i can't do like @override.当我使用颤振片段插件时,我不能像@override 那样做。 i've try updating all the plugin, reinstalling android studio, but it doesn't work.我尝试更新所有插件,重新安装android studio,但它不起作用。

any solution ?任何解决方案? i've already comfortable making flutter app with android studio, and i actually doesn't wanted to use vscode to make flutter app..我已经习惯了用 android studio 制作 Flutter 应用程序,实际上我并不想使用 vscode 来制作 Flutter 应用程序。

Me too, after I've updated flutter and android studio on my Ubuntu 22 I can't use initState and setState snippet even I've installed snippet plugin.我也是,在我的 Ubuntu 22 上更新了颤振和 android studio 之后,即使我安装了片段插件,我也无法使用initStatesetState片段。 Then I can use it again by changing Live Template setting, but not like before (works on StatefulWidget only).然后我可以通过更改 Live Template 设置再次使用它,但不像以前那样(仅适用于StatefulWidget )。 You can follow this steps:您可以按照以下步骤操作:

  1. Open File->Settings->Editor->Live Templates->Flutter then click initS打开File->Settings->Editor->Live Templates->Flutter然后点击initS 在此处输入图像描述

  2. Click Change button on the bottom and check mark Flutter then click Apply单击底部的更改按钮并选中Flutter ,然后单击应用在此处输入图像描述

  3. Finish, you can use initState snippet now.完成,您现在可以使用initState代码段了。

You can add setState or other template you want by clicking + button on top-right and fill all needed.您可以通过单击右上角+按钮添加所需的setState或其他模板并填写所有需要的内容。

Happy coding! :) :)

You need to write in Widget build function.您需要编写 Widget 构建函数。 Currently you are in the wrong scope目前你在错误的范围内

Same here.同样在这里。 So how i solved this issue!那么我是如何解决这个问题的! I just use Ctrl+O for overriding any method.我只是使用Ctrl+O来覆盖任何方法。 N:B sometimes hints don't work. N:B 有时提示不起作用。 so I have to press ESC a couple of times or navigate to another page and come back again.所以我必须按几次ESC或导航到另一个页面并再次返回。

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

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