dart - TabController 构造函数中的 `vsync` 属性

据此:sample code

我创建了自己的 TabController 实现:

void main() {
  runApp(new MyApp());
}

class MyApp extends StatefulWidget {

  @override
  _MyAppState createState() => new _MyAppState();
}

class _MyAppState extends State<MyApp> {

  TabController _tabController;

  @override
  void initState() {
    super.initState();
    _tabController = new TabController(vsync: this, length: choices.length);
  }

  @override
  void dispose() {
    _tabController.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      home: new Scaffold(
        bottomNavigationBar: new Material(
          color: Colors.blue,
          child: new TabBar(
            controller: _tabController,
            isScrollable: false,
            tabs: choices.map((Choice choice) {
              return new Tab(
                text: null,
                icon: new Icon(choice.icon),
              );
            }).toList(),
          ),
        ),
        appBar: new AppBar(
          title: const Text('Swap'),
        ),
        body: new TabBarView(
          controller: _tabController,
          children: choices.map((Choice choice) {
            return new Padding(
              padding: const EdgeInsets.all(16.0),
              child: new ChoiceCard(choice: choice),
            );
          }).toList(),
        ),
      ),
    );
  }
}

行内:_tabController = new TabController(vsync: this, length:choices.length); 我收到错误消息:

error: The argument type '_MyAppState' can't be assigned to the parameter type 'TickerProvider'. (argument_type_not_assignable at [swap] lib/main.dart:24)

我的代码有什么问题?

最佳答案

with TickerProviderStateMixin 添加到 State 的类声明的末尾。

https://stackoverflow.com/questions/46851245/

相关文章:

android - 如何在 Flutter 中添加 Webview?

android - flutter : How to change Android minSdkVe

flutter - 使容器小部件垂直填充父级

dart - 在 Flutter 中将焦点滑动到 TextField

Flutter - 自定义字体不显示

flutter - 如何获取 Flutter 应用的构建和版本号

ios - 无法导入使用 Cocoapods 安装的依赖项

flutter - 导航后打开 flutter 对话框

flutter - Flutter AppBar 上的渐变背景

android - Flutter - 从现有的 android 项目导入