【问题标题】:'package:flutter/src/animation/animation_controller.dart': Failed assertion: line 246 pos 15: 'vsync != null': is not true'package:flutter/src/animation/animation_controller.dart':断言失败:第 246 行 pos 15:'vsync != null':不正确
【发布时间】:2020-12-14 10:33:12
【问题描述】:

更新 Flutter 环境后,我遇到了这个问题。请帮我解决这个问题。

 @override
  Widget build(BuildContext context) {
    return DefaultTabController(
      length: 4,
      child: Scaffold(
          appBar: topBar(), 
          body: TabBarView( // problem indicates here
            children: _kTabPages,
            controller: _tabController,
          ),

          // Button Navigation
          bottomNavigationBar: Material(
            color: Colors.redAccent,
            child: TabBar(
              tabs: _kTabs,
              controller: _tabController,
            ),
          )),
    );
  }

请尽快帮助我。

【问题讨论】:

  • 看起来您在课堂上使用的是AnimationController,而没有使用SingleTickerProviderStateMixin
  • 我已经用过了。但也有问题class _DashboardPageState extends State<DashboardPage> with SingleTickerProviderStateMixin { AnimationController _controller;
  • 在创建AnimationController 的新实例时,您需要将this 作为vsync 传递。喜欢_controller = AnimationController(duration: Duration(seconds: 5), vsync: this);
  • _controller = AnimationController(vsync: this);此垂直同步属性在更新后不起作用。
  • not work after updation 是什么意思?

标签: flutter flutter-layout flutter-animation flutter-test


【解决方案1】:

关注这个 github 问题:AnimationController has lost it's vsync

您可以按照以下步骤解决问题:

1. Change minimum sdk to 2.8
2. Run flutter upgrade
3. Run flutter pub get
4. Run flutter clean
5. Restart IDE

【讨论】:

  • 感谢您的解决方案。
猜你喜欢
  • 2020-11-24
  • 2020-07-01
  • 1970-01-01
  • 2021-05-04
  • 2020-03-01
  • 2021-04-12
  • 2022-06-27
  • 2021-05-12
  • 1970-01-01
相关资源
最近更新 更多