dart - 动画控制器 vsync 未将“this”识别为有效表达式
问题描述
尝试在 dart 中填写 TextFormField 时实现加载动画。声明 AnimationController 时,我的声明无法识别“this”。
我发现的每个文档都使用“this”作为 vsync,由于某种原因,我无法识别它。
class _SettingsScreenState extends State<SettingsScreen> with SingleTickerProviderStateMixin {
final _animationController = AnimationController(vsync: this, duration: Duration(seconds: 1));
...
ListTile(
title: new TextFormField(
controller: _serverController,
keyboardType: TextInputType.emailAddress,
style: TextStyle(
color: darkGray,
fontSize: 18,
fontWeight: FontWeight.w500,
fontFamily: mainFontFamily
),
onFieldSubmitted: _handleSubmitted,
autocorrect: false,
decoration: new InputDecoration(
icon: AnimatedIcon(icon: AnimatedIcons.search_ellipsis, progress: _animationController, color: darkGray,), /*TODO get this to actually show up and animate while checking server*/
contentPadding: EdgeInsets.symmetric(
vertical: 12, horizontal: 12),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(10.0),
),
),
),
),
颤振医生 -v 输出
[√] Flutter (Channel stable, v1.2.1, on Microsoft Windows [Version 10.0.17763.475], locale en-US)
• Flutter version 1.2.1 at C:\flutter
• Framework revision 8661d8aecd (3 months ago), 2019-02-14 19:19:53 -0800
• Engine revision 3757390fa4
• Dart version 2.1.2 (build 2.1.2-dev.0.0 0a7dcf17eb)
[!] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
• Android SDK at C:\Users\amehta\AppData\Local\Android\sdk
• Android NDK location not configured (optional; useful for native profiling support)
• Platform android-28, build-tools 28.0.3
• Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
• Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1343-b01)
! Some Android licenses not accepted. To resolve this, run: flutter doctor --android-licenses
[√] Android Studio (version 3.4)
• Android Studio at C:\Program Files\Android\Android Studio
• Flutter plugin version 35.3.1
• Dart plugin version 183.6270
• Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1343-b01)
[!] VS Code, 64-bit edition (version 1.21.0)
• VS Code at C:\Program Files\Microsoft VS Code
X Flutter extension not installed; install from
https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter
[√] Connected device (1 available)
• GT N7100 • 4d00db7fb27a90e9 • android-arm • Android 4.4.2 (API 19)
! Doctor found issues in 2 categories.
我希望图标显示出来,一旦我在 TextFormField 中提交,它将运行动画,直到服务器检查完成
解决方案
您必须将该行放在initState方法中,如下所示:
@override
void initState() {
super.initState();
_controller = AnimationController(duration: expandDuration, vsync: this);
}
希望这有帮助。
推荐阅读
- react-native - goBack 上的重新加载屏幕反应本机
- excel - COUNTIF 标题行单元格长度小于一个值
- java - java - 如何将多种数据类型分配给java中的单个变量?
- snowflake-cloud-data-platform - 雪花数据库和性能的约束
- javascript - 嵌入在电子邮件节点邮件程序中的图像
- arrays - 将 uiimage 附加到 uiimage 数组
- android - 解决 Android WiFi 限制限制?
- flutter - '在颤振中使用折叠方法时,'方法'_addFromInteger'在null'上被调用
- visual-studio - Visual Studio“在文件中查找”无法在解决方案中找到匹配项
- reactjs - 如何在子组件可以访问的上下文中创建方法?