尝试在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),
),
),
),
),
flutter doctor -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中提交,它将运行动画,直到服务器检查完成
答案 0 :(得分:0)
您必须将该行放入 initState 方法内,如下所示:
@override
void initState() {
super.initState();
_controller = AnimationController(duration: expandDuration, vsync: this);
}
希望获得帮助。